Re: about unary_function
"George" <George@discussions.microsoft.com> wrote in message
news:844BB035-EE8A-424D-A10F-F05D13E14C71@microsoft.com
I am wondering what is the practical usage of unary_function?
unary_function just defines a few typedefs. These may be used by
adapters. See e.g. unary_negate, note how it takes Predicate as a
template parameter and expects Predicate::argument_type to be defined.
When you write your own predicate, you can introduce this typedef by
hand, or you can inherit from unary_function that does it for you.
My question is, a class like
class Foo : public std::unary_function<class A, class B>
is always the same (could use similar implementation) to
template <class A, class B> class Foo
Yes. The second class just won't work with STL adapters.
So we could always use the alternative approach to replace
unary_function.
unary_function is trivial: it just defines two typedefs, it doesn't
introduce any behavior. Yes, you can define those typedefs yourself.
unary_function is just for convenience.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925