Boost logo

Boost Users :

Subject: Re: [Boost-users] Lambda issue.
From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2009-03-01 07:36:42


On Sun, Mar 1, 2009 at 11:17 AM, Surya Kiran Gullapalli
<suryakiran.gullapalli_at_[hidden]> wrote:
> Hello all,
> I've a class with boost::variant as its member ;
> class A
> {
> public:
> A() { }
>
> boost::variant<int, string, double, date>& getValue (const string& key)
> {
> ...
> }
> private:
> map<string, boost::variant<int, string, double, date> >m_member ;
> }
> I've list of A's like this
> list<A> myList.
> when trying to find a particular element with integer value (1 say) which is
> stored in m_member,
> I'm doing this..
> find_if (myList.begin(), myList.end(),
> (boost::lambda::bind(&A::getValue, boost::lambda::_1, "SomeKey") == 1));
> This is giving lot of errors. I've tried casting the result of bind to
> Variant, and then converting the variant to int using boost::get<int>()..
> but no help.
> Any ideas how to do this ?
> Surya

How about comparing variants rather than try to extract a value that
may not be an int anyway?

   boost::variant<int, string, double, date> lookFor(1);

   using namespace boost::lambda;
   find_if(myList.begin(), myList.end(), constant(lookFor) ==
bind(&A::getValue, _1, "SomeKey") == 1));

Stuart Dootson


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