Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2004-12-01 23:40:21


David Abrahams wrote:
> Eric Niebler wrote:
>
>> If anyone knows of a foolproof way to distinguish lvalues from
>> rvalues, I'm all ears.
>
>
> See the contents of boost/iterator/is_lvalue_iterator.hpp
>
>

Sorry to break this to you Dave, but is_lvalue_iterator suffers from the
same problem as BOOST_FOREACH. Consider:

struct rvalue_iterator
     : std::iterator<
         std::forward_iterator_tag
       , std::list<int>
       , ptrdiff_t
       , std::list<int> const *
       , std::list<int> const &
>
{
     std::list<int> const operator*() const;
};

BOOST_STATIC_ASSERT( ! boost::is_lvalue_iterator<rvalue_iterator>::value );

The static assert fails. Since operator* returns a /const/ UDT, it binds
to T&, which fools your lvalue detection scheme. I don't know enough
about iterator requirements to say whether operator* is permitted to
return a const-qualified object of value_type, but regardless, it's
still a problem for BOOST_FOREACH.

Any other thoughts?

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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