Do we really need const?

Steven Schveighoffer schveiguy at yahoo.com
Wed Sep 19 11:04:27 PDT 2007


"Janice Caron" wrote
> (If C++ had had intransitive const, the compiler would have prevented
> this, but it doesn't so he got away with it).

Something tells me that this friend of yours would have done the same thing 
in D.  Is there a warning if you cast away const?  If not, there should be.

Otherwise, D wouldn't have helped you in this case either...

> I don't have a problem with const being transitive by default. I think
> it's a good idea. I do, however, have a problem with there being *no
> way to specify* mutable pointer to const pointer to mutable data.
> We've listed enough use cases to know that sometimes that's exactly
> what you need. It shouldn't be the default, but it should be
> /possible/.
>
> But ... on the other hand ... we /can/ cast away const, and even
> though it's "undefined", there is some indication that you can get
> away with it if you know what you're doing (in terms of
> thread-safety), so maybe it's not as big a problem as some of us
> imagine.

Then why be SO adamant about const being transitive! (i.e. Walter's view, 
not yours).  If the 'accepted' practice is to cast away const if you want to 
have intransitive const, then transitive const is equally meaningless.

The more I think about this issue, the more I think that I can probably live 
with transitive only const.  I don't think it's such a bad thing as it 
simply makes you think differently when designing classes.  As I believe 
intransitive const is a subset of transitive const, it's almost 
implementable with transitive-only, but I think I'll probably stay away from 
it.

-Steve 





More information about the Digitalmars-d mailing list