Getting the const-correctness of Object sorted once and for all
Era Scarecrow
rtcvb32 at yahoo.com
Sun May 13 20:09:28 PDT 2012
On Monday, 14 May 2012 at 02:57:57 UTC, Mehrdad wrote:
> On Monday, 14 May 2012 at 02:48:20 UTC, Jonathan M Davis wrote:
>> But that's just one of the costs of const in D.
>
> The problem is that it's unavoidable.
>
> I.e. you can't say "don't Mark it as const if it isn't const",
> because, practically speaking, it's being forced onto the
> programmers by the language.
With const and immutable being transitive, there are cases when
there's things you want to do with an object after you've made it
and it's in a const structure. I know I've made a struct that was
intended to hold immutable data, however it refused to allow
methods to until const was appended to the signatures of the
functions. At first it was annoying; But when I see bigger
picture of why it makes much more sense.
Nothing we make 'has' to have const on it but inevitably they
may be used in a read-only way. I'm trying to think of it as my
structs and classes being as const-friendly as possible in those
cases.
More information about the Digitalmars-d
mailing list