Boost logo

Boost :

From: Dan W. (danw_at_[hidden])
Date: 2004-01-05 15:35:45

David B. Held wrote:
> I guess I'm still not seeing how this works. Let's look at smart_ptr
> and review what Thorsten wants. I believe he wants this:
> void foo(smart_ptr<T> deep_const& p)
> {
> p->nonConst(); // Boom!
> }
> Now, note that I've put the deep_const on the p, and not the T.
> That's because he wants the effect that declaring a pointer
> deep_const causes the pointee to be const (isn't that the point
> of deep const?). Now, obviously, I don't want to declare the
> pointee const or deep_const, like so:

No, hold on, I was the one who brought deep_const and added a truckfull
of mud to the mud-wresling arena; --don't blame him. He only used
const. So let me rephrase your question:

  void foo(smart_ptr<T> const p)
      p->nonConst(); // Boom!

Actually, you verbalized a question that was in my mind. I'm not
exactly sure whether he meant that he wanted that in general, or only in
the context of p being a member of a class and receiving
address-constness indirectly, by virtue of a const function of the class
of which it is a member, being called. I also think that he wants the
compiler to forbid,

int foo(smart_ptr<T> p) const;

and mandate

int foo(smart_ptr<T const> p) const;

or else make the former mean the latter implicitly.

Both above rules I apply in my coding, by discipline, by the way; so,
it's not that I disagree with him on aesthetical grounds... Just that I
would rather not have the language mandate it.

Now, if you're asking me whether I'd have that be the meaning of
deep_const, at first look I'd say I'd rather see T deepconst * as the
correct syntax, even though technically T * deepconst "should" mean the
same, strictly speaking; I'd rather keep the ability to specify whether
I can re-point my deepconstness in some other direction or not by writing,

T deepconst * p;
T deepconst * const cp;

which ability does not propagate, I realize... (I smell a rat)

> smart_ptr
> {
> T deep_const* p_;
> };
> Because how do you return a non-const pointer without a cast?

Just use deep_ptr<> :)

Sorry, where do we have to return a non-const pointer?
Or, are you talking about the address-constness of the pointer?

Oh!, I get it! If the pointer, the address, is const, it cannot be
assigned! And if I make the root-pointer's address non-const, then my
definition of deep-constness is not recursively defined!

A rat indeed it was. Thank you!

( God there's smart people in this place! ;-) )

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