v2.029: "Type const(int) does not have an Unsigned counterpart"?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Apr 25 04:15:51 PDT 2009


%u wrote:
> Is there anyway to work around this compiler problem temporarily?  Thanks.
> 
> /dmd/linux/bin/../bin/../../src/phobos/std/traits.d(1011): Error: static
> assert  "Type const(int) does not have an Unsigned counterpart"
> /dmd/linux/bin/../bin/../../src/phobos/std/traits.d(2454): Error: template
> instance std.traits.Unsigned!(const(int)) error instantiating
> /dmd/linux/bin/../bin/../../src/phobos/std/conv.d(2454): Error:
> Unsigned!(const(int)) is used as a type
> 

Either get traits.d from svn, or paste this code into it:

template Unsigned(T) {
     static if (is(T == byte)) alias ubyte Unsigned;
     else static if (is(T == short)) alias ushort Unsigned;
     else static if (is(T == int)) alias uint Unsigned;
     else static if (is(T == long)) alias ulong Unsigned;
     else static if (is(T == ubyte)) alias ubyte Unsigned;
     else static if (is(T == ushort)) alias ushort Unsigned;
     else static if (is(T == uint)) alias uint Unsigned;
     else static if (is(T == ulong)) alias ulong Unsigned;
     else static if (is(T == char)) alias char Unsigned;
     else static if (is(T == wchar)) alias wchar Unsigned;
     else static if (is(T == dchar)) alias dchar Unsigned;
     else static if(is(T == enum))
     {
         static if (T.sizeof == 1) alias ubyte Unsigned;
         else static if (T.sizeof == 2) alias ushort Unsigned;
         else static if (T.sizeof == 4) alias uint Unsigned;
         else static if (T.sizeof == 8) alias ulong Unsigned;
         else static assert(false, "Type " ~ T.stringof
                            ~ " does not have an Unsigned counterpart");
     }
     else static if (is(T == immutable))
     {
         alias immutable(Unsigned!(Unqual!T)) Unsigned;
     }
     else static if (is(T == const))
     {
         alias const(Unsigned!(Unqual!T)) Unsigned;
     }
     else static assert(false, "Type " ~ T.stringof
                        ~ " does not have an Unsigned counterpart");
}


Andrei



More information about the Digitalmars-d mailing list