PhobosWatch: manifest => enum
Walter Bright
newshound1 at digitalmars.com
Fri Dec 28 12:38:28 PST 2007
Janice Caron wrote:
> On 12/28/07, Walter Bright <newshound1 at digitalmars.com> wrote:
>> Janice Caron wrote:
>>> y is a /copy/ of x, and clearly it should be possible to make a copy
>>> of a const thing and have the copy be mutable.
>> That doesn't work for structs or classes.
>
> It doesn't? For structs
>
> struct S {}
> const S x;
> auto y = x;
Imagine you have:
struct S { int* p; }
Because const is transitive, const(S) implies that now p points to
const. But if you strip off the const in the assignment, you've lost the
const-ness of p, and now you have a gaping hole in the const-correctness.
> Isn't
>
> class C {}
> enum { C x; }
> auto y = x;
>
> exactly the same problem?
No, because y will be of type C and will have the value null.
>> Just for fun, how would we define a tail const member function?
>
> Yeah, I agreed, it wouldn't work for classes. Still don't see any
> problem for structs though.
You'd need tail const member functions for structs, too.
More information about the Digitalmars-d
mailing list