Boost logo

Boost Users :

From: Fei Liu (fei.liu_at_[hidden])
Date: 2007-09-25 14:08:55


Nat Goodspeed wrote:
> Fei Liu wrote:
>
>
>> using namespace std;
>> using namespace boost::lambda;
>> using namespace boost;
>> using boost::any_cast;
>>
>> int main(){
>> vector<any> a;
>>
>> std::for_each(a.begin, a.end(), if_then(_1.type() == typeid(int))[cout
>> << _1 << ' ']);
>> }
>>
>
> Invoking a method on a placeholder is a documented limitation:
>
> http://boost.org/doc/html/lambda/le_in_details.html#id1244744
>
> The '.' operator cannot be overloaded. Therefore you must use bind().
> Because you're using boost::lambda::if_then, I'm sure you're better off
> using boost::lambda::bind than plain boost::bind, though the fact that
> both have been brought into the current namespace makes me think that an
> explicit reference might help -- something like:
>
> boost::lambda::bind(&any::type, _1)
>
> (Disclaimer: I haven't tried to compile your example, with or without my
> suggestion.)
> ______________________________________

Thank you, unfortunately I am getting even more cryptic error messages
now after I use explicit bind call:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#include <boost/any.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/if.hpp>

using namespace std;
using namespace boost::lambda;
using namespace boost;
using boost::any_cast;

int main(){
    vector<any> a;
    any val = 3;
    a.push_back(val);
    val = string("456");
    a.push_back(val);

    std::for_each(a.begin, a.end(),
if_then(boost::lambda::bind(&any::type, _1) == typeid(int))[cout << _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