Boost logo

Boost Users :

From: Haroon Khan (haroon.khan_at_[hidden])
Date: 2006-12-09 03:26:44


On 12/8/06, Santosh Joseph <santoshjoseph73_at_[hidden]> wrote:
>
> using namespace boost::lambda;
> boost::lambda::placeholder1_type Arg;
>
> typedef
> pair<set<string>::iterator,bool>(set<string>::*INSERT)(const
> string&);
> std::vector<string> v;
> set<string> str_con;
> INSERT insert_func = &set<string>::insert;
> for_each( v.begin(), v.end(), bind( insert_func,
> str_con, Arg));
>

All the arguments to the bind function need to be a lambda
expressions, except for the pointer to a member function. You will
have to wrap str_con in var function for it to compile, like in the
code as follows. Its not very clear in the docs that needs to be done.

    using namespace boost::lambda;
    typedef std::set<std::string> set_of_strings;

    typedef std::pair<set_of_strings::iterator, bool>
(set_of_strings::*INSERT_FUNC_TYPE1) (const std::string&) ;
    INSERT_FUNC_TYPE1 insert_func = &set_of_strings::insert

    std::vector<std::string> v;
    set_of_strings str_con;

    std::for_each(v.begin(), v.end(), (bind(insert_func, var(str_con),
boost::lambda::_1)));


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net