isMutable!(T) - intended/overlooked behaviour?

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 11 07:00:30 PST 2016


On Monday, 11 January 2016 at 14:39:33 UTC, 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?

The question is what do you mean by enum ?

---
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;
     }

     assert(!(is(typeof(constant_0) == enum)));
     assert(!(is(typeof(constant_1) == enum)));
}
---


More information about the Digitalmars-d mailing list