so what exactly is const supposed to mean?
Hasan Aljudy
hasan.aljudy at gmail.com
Mon Jul 3 03:00:07 PDT 2006
Sean Kelly wrote:
> Hasan Aljudy wrote:
>
>> Ok, I know that the const issue has apparently been beaten to death on
>> the digitalmars.D NG, but ....
>>
>> Can someone please explain to me what does const mean?
>
>
> That depends. Typically it means that a reference won't be used to
> mutate referenced data, but that leaves a lot of room for
> interpretation. C++, for example, uses "logical const" for classes and
> 'mutable' qualified members can actually be altered by const member
> functions. The mutable qualifier is useful in instances where a class
> has members that are more of an implementation detail (a mutex or DB
> connection handle, for example) that may need to be mutated in the
> course of processing const-qualified methods.
hm, so basically making an object immutable?
Sorry, I didn't get the second part about C++. What do you mean by
"logical const"?
>> I think it's something from C++, no? what is it? what does it do? and
>> why do people think it's useful?
>
>
> Logical const (as in C++) provides a contract ensuring that the user of
> const-qualified data will not modify it in observable ways. This serves
> to catch accidental errors and to make programmers feel better about
> passing references into unknown code.
Is there anything preventing anyone from creating immutable classes?
>
>> While you're at it, would you mind explaining the implications of
>> implemeting the proposed "const by default" feature?
> [snip]
> The implication is that references through which mutating operations
> will occur would likely have to be qualified as 'mutable' or 'inout' or
> some such, and that mutating member functions of classes and structs
> would probably have to be labeled as 'mutable' as well. But I don't
> want to speculate beyond that as I haven't given the issue nearly as
> much thought as Walter has.
damn, this doesn't sound too good.
I for one don't give a damn about const, so why should I be bothered to
think about the constness of my code/classes and add "mutable"
qualifiers all over the place?
More information about the Digitalmars-d-learn
mailing list