I want to be able to express the operator *() as a function (or function object), like in the following trivial example.

template<class Iterator>
typename std::iterator_traits<Iterator>::reference deref(Iterator i)
{
    return *i;
}

std::vector<int *> vp;
std::vector<int> v;
std::transform(vp.begin(), vp.end(), std::back_inserter(v), deref<int*>);



This is, I think, somewhat related to

template<class T, class X> inline
T implicit_cast(X x)
{
     return x;
}

std::vector<boost::reference_wrapper<int> > vp;
std::vector<int> v;
std::transform(vp.begin (), vp.end(), std::back_inserter(v), implicit_cast<int, int&>);
(well, this would compile with std::copy instead of std::transform..but this is just for illustration).


I'm looking for something like 'Given any 'dereferencable object T' return the object it has a reference to'.





On 16/04/07, Paul Giaccone <paulg@cinesite.co.uk> wrote:
Christian Holmquist wrote:

>
> Sorry for beeing off-topic, but is there a utility in boost for
> dereferencing an iterator, such as the below (but that also works for
> boost::reference_wrapper)
>
> template<class Iterator>
> typename std::iterator_traits<Iterator>::reference deref(Iterator i)
> {
>     return *i;
> }
>
> Thanks,
> Christian

Apart from it looking a little tidier and so perhaps more readable, why
would you need this when it works in exactly the same way as unary
operator* (and so means more typing)? It might be useful if it had some
checks for zero or bad pointers before it did the dereferencing, of
course, but can that happen with Boost iterators (I'm not familiar
enough with them to know)?

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users