|
Boost : |
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-11-21 11:35:05
On 11/20/07, Dean Michael Berris <mikhailberis_at_[hidden]> wrote:
> On Nov 20, 2007 12:37 AM, Giovanni Piero Deretta <gpderetta_at_[hidden]>
> > [...]
> > This doesn't return the right thing with non const parameters. A very
> > simple result_of compatible wrapper around fusion::at_c will do. In fact
> > I think that fusion should provide function objects for every one of its
> > algorithm.
> >
>
> You mean:
>
> std::pair<int, int> pair(1, 2);
> std::cout << boost::select<1>()(pair) << std::endl; // should output 2
>
> ?
>
> I think I'm missing something here... Can you elaborate?
>
In fact I was wrong. Now I do not think it return the right thing even
with const parameters :). The problem is that you always return a
copy of the Nth element (as a temporary). This work fine if you only
need read access *and* the object is small. In this example 'select'
copy the vector at every extraction!
std::map<int, std::vector<int> > map = ....;
void foo(std::vector<int> const&);
std::for_each(map.begin(), map.end(), bind(foo,
bind(boost::select<1>(), _1)));
If you remove the const from the signature of foo, the example won't
compile at all. It is a bit elaborate to deduce the return value of a
generic tuple accessor in the most general case possible, but it can
be done. Anyways, fusion at_c already takes care of all the work.
HTH,
gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk