Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant] apply templated visitor
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-20 18:31:00


AMDG

Dmitry Vinogradov wrote:
> Imagine the following:
>
> struct foo
> {
> bar& operator[](int);
> bar& operator[](std::string);
> } Foo;
>
> boost::variant<int, std::string> Idx;
>
>
> Is some simple way exist to apply foo::operator[](T) for Foo and Idx?
>
> Something like
> boost::apply_visitor(boost::bind(&foo::operator[], boost::ref(Foo),
> _1), Idx); // does not compile

You can either use a combination of bind and lambda: (untested)
  
boost::bind<bar&>(boost::lambda::ret<bar&>(boost::lambda::var(Foo)[boost::lambda::_1]),
_1);
or you can write your own function object

In Christ,
Steven Watanabe


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