Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-01-12 20:43:20


Dave Abrahams wrote on 1/12/2000 8:27 PM
>> Also note it is
>> permissable for the reference type to be the value type itself. It
>> would not be appropriate to use the reference type for a function
>> argument with the intent that the argument will be pass-by-reference.
>
>Hmm. There may be some subtle issues here, which I'd rather not discuss.
>Against my better judgement:

Is this not precisely the context with swap I was talking about earlier?

Algorithm calls:

void swap(T& x, T& y);

with a statement like:

swap(*i, *j);

But algorithm is given a proxy reference so the above call fails because
*i generates a temporary object which won't bind to a non-const
reference. To solve, proxy container supplies:

void swap(reference x, reference y);

so swap(*i, *j) happily and ignorantly does the right thing.

Or perhaps I misunderstood the context... I usually understand C++ code
better than I understand English.

-Howard


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