Boost logo

Boost :

From: Martin Bosticky (mbosticky_at_[hidden])
Date: 2002-11-22 09:28:28


I have I not a template boost guru but i have developed a 'functor adapter'
that I think could be usefull. To best of my knowledge the following is
currently not provided by boost library yet. Please let me know otherwise.

Functor adapter: adaptor2ndArgument and other appropriate variants can take
a functor, and create a new functor with a new argument type such that it
takes an object but uses that objects member. This would be usefull when you
want to search a container of some object type based on one of its member
data/functions. Normally the same affect can be achieved by writing custom
functors but that can get very tedious.


adapt2ndArgument<object_type>(equal_to<string>(), &object_type::m_Name)

would convert the equal_to<string> binary_function with argumenst of type
(string, string)
into a new functor with arguments of type (string, object_type) such that
equal_to<string> gets called with arguments (what_ever_string,


struct Option
    string m_Name;
    string m_OptionParameters;

vector<Option> AVector_vec;

 // Find the preffered option
 vector<Option>::iterator AVector_it =
      // Identify when Option.vm_Member == "c"
      bind1st(adapt2ndArgument<Option>(equal_to<string>(), &Option::m_Name),

By the way, i have attempted to find a solution that does not require the
template argument <Option> at all. However that does not copile on VC7. My
example compiles on VC6 and VC7.

It might be that there are other solutions available on boost already and
please let me know. However I suspect that those would not compile on lesser
compilers such as VC6.

Cheers, Martin

Boost list run by bdawes at, gregod at, cpdaniel at, john at