On 1/11/16 9:39 AM, Liam McSherry wrote:
Are the results produced by the following program intended behaviour for
isMutable!(T)?

---
void main()
{
     import std.stdio  : writeln;
     import std.traits : isMutable;

     struct S
     {
         enum size_t constant_0        = 0;
         enum const(size_t) constant_1 = 0;
     }

     __traits(compiles, { S s; s.constant_0 = 1; }).writeln; // false

     isMutable!(typeof(S.constant_0)).writeln; // true
     isMutable!(typeof(S.constant_1)).writeln; // false
}
---

I know the documentation for isMutable!(T) says "Returns true if T is
not const or immutable," but it would make sense to me if it returned
false when given an enum. Is this maybe something to be corrected?

You are confusing type with storage class.

isMutable tells you that some variable declared with the given type would be mutable. In other words, it's not the type that makes constant_0 immutable, it's the location where it's stored.

This should work fine:

typeof(S.constant_0) foo;
foo = 5;

-Steve

Reply via email to