473,804 Members | 3,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the advantage of inherit from unary_function template

I would like to know what is the advantage of inherit from
unary_function template?

For example, I have this in my code:

What is the advantage of doing this:

class Same : std::unary_func tion<A*, bool>
{
public:
Same(A* a) : _a(a){};

bool operator()(A*a1 );
private:
A* _a;
};
instead of this:

class Same
{
public:
Same(A* a) : _a(a){};

bool operator()(A*a1 );
private:
A* _a;
};

typedef list<A*> AList
bool MyAList::contai ns(A* a) {
AList::iterator iter;

iter = find_if ( _aList.begin(), _aList.end(), Same(a));

if (iter == _aList.end())

return false;
else
return true;

}

Jan 26 '06 #1
3 2218

Al************@ gmail.com wrote:
I would like to know what is the advantage of inherit from
unary_function template?

For example, I have this in my code:

What is the advantage of doing this:

class Same : std::unary_func tion<A*, bool>
{
public:
Same(A* a) : _a(a){};

bool operator()(A*a1 );
private:
A* _a;
};


This allows you to use things like bind2nd and such. There are certain
requirements for "unary functions" and subclassing unary_function sets
all that up.

Jan 26 '06 #2
Al************@ gmail.com wrote:
I would like to know what is the advantage of inherit from
unary_function template?
[..]


At this point inheriting is done to get the typedefs 'unary_function '
declares (and 'binary_functio n' does that too).

V
Jan 26 '06 #3
ro**********@gm ail.com wrote:
Al************@ gmail.com wrote:
I would like to know what is the advantage of inherit from
unary_functio n template?

For example, I have this in my code:

What is the advantage of doing this:

class Same : std::unary_func tion<A*, bool>
{
public:
Same(A* a) : _a(a){};

bool operator()(A*a1 );
private:
A* _a;
};

This allows you to use things like bind2nd and such. There are certain
requirements for "unary functions" and subclassing unary_function sets
all that up.


Do you think you can show an example where _not_ inheriting would make
it impossible to use 'bind2nd'? Especially in the case of an _unary_
function. Thanks!

V
Jan 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1813
by: kyo | last post by:
class A { public: int a; }; struct testfun1 : public unary_function<const A&, bool> { bool operator()(const A &) const {
0
1361
by: Jill Graham | last post by:
Hi folks, The pages of my website are built dynamically and are based on templates. A template can look like this : <table> <tr><td>This is the page header</td></tr> <tr><td>This is the page content</td></tr> <tr><td>This is the page footer</td></tr>
6
2255
by: blah | last post by:
Hi, Is it possible to force the typename of a template to inherit from a particular class? For example, something like this (conceptual; this doesn't compile): class Parent { public: virtual void vfn() = 0;
2
6967
by: Samuel R. Neff | last post by:
What's the advantage of inheriting from CollectionBase as opposed to just implementing IList? It seems that it saves you from having to implement a few properties (Clear, CopyTo, Count, GetEnumerator, and RemoveAt) but the way it implements all the other things you need to override seems overkill and counters the advantage of having an extensible base class. For example, the documentation example implementation of Remove: Public...
4
4913
by: yuyang08 | last post by:
Hello, everyone, I am wondering what is the hash function that is used in hash_map/hash_set. Can I replace it with my own hash function? Any comments on this? Thanks! -Andy
8
20614
by: weird0 | last post by:
Can anyone explain briefly what is the difference between inheritance and polymorphism? i read and seem to forget it again and again... Can anyone along with good examples of c# explain the fundanmental concept so i can remember it forever as it is a common interview question.... Thanks in advance
7
3024
by: curious2007 | last post by:
Hello, I have the following code, but does not compile: #include <iostream> using namespace std; template<class Arg, class Result> struct unary_function {
32
2747
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
6
3932
by: jabbah | last post by:
Hi, im failing with my first try to use unary_function, i got something (which i partly borrowed from another forum): #include <algorithm> #include <functional> #include <iostream> using namespace std; template <typename T> class is_good : public std::unary_function<T, bool> { public:
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.