Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-05 04:37:22

David B. Held wrote:

> "Dan W." <danw_at_[hidden]> wrote in message
> news:btb4ff$gmk$
>>class x
>> y deep_const *a;
>> y* get_a(); //boom!
>> y const * get_a() const; //boom!
>> y deep_const * get_a() deep_const; //ok
>> y const * get_get_a() const
>> {
>> get_a(); //boom!
>> }
>> y deep_const * get_get_a() deep_const
>> {
>> get_a(); //ok
>> }
> Ok, so how would this apply to our smart_ptr<> example? Maybe:
> smart_ptr<T> deep_const p;

smart_ptr<T deep_const> p;

>>From what I can tell, this would require us to define deep_const
> accessors inside smart_ptr<> and/or do a deep_const_cast<>
> of the raw pointer. But then, that doesn't seem to be any
> different from implementing deep const manually. Are you
> suggesting that the language *enforce* deep const, but not
> actually *help* you implement it? At least const propagates
> to aggregated members, so it is both enforcing a property and
> helping you out at the language level. But from what I can see
> above, you're just asking for enforcement, with a parallel
> const concept. What I was thinking is that if you declare an
> object deep_const, it will make all pointers inside that object
> const/deep_const as well, without you ever having to declare
> deep const versions of anything; just like declaring an object
> const makes the members effectively const. So it's not y or
> y* that we want to make deep_const. It's an instance of x.
> What we really should be asking ourselves is how

"If I have a deep_const object I can only access its deep_const accessors."
...with a bitter rule...
"deep_const accessors in a class can only access deep_const accessors on
its members."
...and a bit of sweetner...
" basic_type const * " == " basic_type deep_const * "
" basic_type const & " == " basic_type deep_const & "
...and a bit more sweetener...
"class x
    (only basic_type members)
    ... f() const == ... f() deep_const


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