Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2006-05-30 14:49:01

Thorsten Ottosen wrote:
> Eric Niebler wrote:
>> Thorsten Ottosen wrote:
>>> Eric Niebler wrote:
>>>> If make_iterator_range() returned a const-qualified iterator_range<>,
>>>> this would work. Thorsten?
>>> Isn't the problem thet out is a reference?
>> out is a reference, which means that non-const rvalues will not bind to
>> it. But const rvalues will because out_t will be deduced to be
>> "iterator_range<> const". Try it and see.
> I see. I certainly didn't know that. I could get it to work on
> gcc, but not vc8.
> On what compilers does it actually work?

All of them, as far as I know. I just tried on VC8 and it worked:

template<typename T> void foo(T &) {}
struct empty {};
empty const bar() { empty e; return e; }

int main()
   return 0;

Without thinking about this deeply, it seems that lightweight proxy
objects such as iterator_range<> should always be returned as a
const-qualified rvalues for precisely this reason.

(Note that cv-qualifications on intrinsic return types are ignored, so
"int foo()" and "int const foo()" are the same. Perhaps that's the
problem you were seeing?)

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at