Struct toString works but not std.conv.to!string

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 13 15:21:42 PDT 2015


On 10/13/2015 02:07 PM, Nordlöw wrote:
> I have defined a struct UTCOffset in
>
> https://github.com/nordlow/justd/blob/master/datetime_ex.d
>
> Everything works as desired except for
>
>      import std.conv : to;
>      assert(UTCOffset(+14, 0).to!string == "UTC+14:00");
>
> which fails as
>
> /usr/include/dmd/phobos/std/conv.d(293,14): Error: template instance
> isRawStaticArray!() does not match template declaration
> isRawStaticArray(T, A...)
> datetime_ex.d(129,29): Error: cannot resolve type for
> UTCOffset(cast(ubyte)0u).this(cast(byte)14, cast(ubyte)0u).to!string
>
> I don't understand what's wrong.

Reduced with a workaround:

struct UTCOffset
{
     import std.conv : to;    // Move to module scope to compile

     string toString() const
     {
         return "hello";
     }
}

void main() {
     import std.conv : to;
     UTCOffset().to!string;
}

This is an issue that I know to be known. :) I think it is about private 
definitions (isRawStaticArray) of modules not working outside? or when 
in inner scopes? Something like that...

Ali



More information about the Digitalmars-d-learn mailing list