
On 11/20/07, Dean Michael Berris <mikhailberis@gmail.com> wrote:
On Nov 20, 2007 12:37 AM, Giovanni Piero Deretta <gpderetta@gmail.com>
[...] 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