Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-07-24 13:16:00


Peter Dimov wrote:
> Eric Niebler wrote:
>> General design question here. This came up on the user's list, and it
>> made me question something I believed to be true. When writing a proxy
>> for, e.g., a std container, I see two options for handling const.
>>
>> 0) Const-ness depends on the const-ness of the object being proxied:
>>
>> 1) Const-ness depends on the proxy object itself:

<snip>

> If the vector_proxy has an ordinary copy constructor, (0) is usually correct
> because (1) cannot be enforced.
>
> vector_proxy const a = ...;
> vector_proxy b = a;

That's a good point, and very relevant to the BOOST_FOREACH discussion
because BOOST_FOREACH must make a copy of the proxy.

> (1) typically only makes sense for types that are intended to be class
> members and propagate the constness of the member function to the proxied
> (referred to) object for some reason.

Right, that would seem to be a legitimate use.

> (1) can work for move-only types. I don't have experience with such proxies,
> so I can't tell. :-)

You mean when the proxy is move only? How does that solve the problem above?

vector_proxy const a = ...;
vector_proxy b = std::move(a);

I've probably misunderstood.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com

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