Siemel Naran wrote in

news:u9ysd.1033433$(E-Mail Removed) in

comp.lang.c++:

>

> The standard typedef names are result_type
Thanks I always get this wrong.

> and argument_type.
AIUI (I haven't researched this myself, just going on snippets

from usenet) argument_type isn't needed (used).

> These

> allow compatibility with other standard binders in STL and boost like

> std::bind2nd.

>

> template < typename T > struct my_abs

> {

> typedef T argument_type;

> typedef T result_type;

> T operator () ( T const &arg ) const

> {

> using std::abs;

> return abs( arg );

> }

> };

>

> My preferred way is to derive from std::unary_function<argument_type,

> result_type>.
Yep, but that does add an extra byte to the function object in some

cases:

struct my_functor : std::binary_function< int, int, bool >

{

std::less< int > m_less;

// operator here ...

};

The above has 2 subobjects of type std::binary_function< int, int, bool >

so EBO (Empty Base (class) Optimization) can't happen.

I am perhapse being needlessly pedantic (and possibly I'm premeturly

optimizing), OTOH typing "typedef T result_type;" is shorter (and IMO

less cryptic) than writing " : std::unary_function< T, T > ".

If only I could remember result_type not return_type all would be

well

.

Either way I have to lookup result_type or binary_function /

unary_function as I'm actualy not sure the bool return type above

shouldn't be the first argument.

Rob.

--

http://www.victim-prime.dsl.pipex.com/