Boost logo

Boost :

From: Fredrik Blomqvist (fredrik_blomqvist_at_[hidden])
Date: 2003-02-13 10:32:20


Hi
Consider this case of boost::mem_fn applied to data members and in
association with boost::iterator_adaptors.

#include <boost/iterator_adaptors.hpp>
#include <boost/mem_fn.hpp>

struct foo {
    int m_data;
    // ..
};

std::vector<foo> data;
...
boost::make_projection_iterator(data.begin(), boost::mem_fn(&foo::m_data))

The line above "should" IMHO work, but with the current impl (VC7, latest
CVS) it ends up as a reference-to-reference problem. I believe this is a
very important and common(?) use-case.

What's the rationale for mem_fn to (in the case of data members) make it's
return_type a reference? Should mem_fn change to use a "plain" typedef (like
std::unary_function) or could iterator_adaptor perhaps mangle the input type
to avoid the reference-to-reference problem?
(I haven't tested with the sandbox iterator_adaptor v2 though)

Regards
/Fredrik Blomqvist


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk