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

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 13 14:50:42 PDT 2015


On Tuesday, October 13, 2015 21:07:07 Nordlöw via Digitalmars-d-learn 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.

Just glancing at your code, you've marked toString with @property, which is
kind of a weird thing to do, nd if we ever make @property enforce that it's
not called with parens, then that code won't work. So, you might try moving
that @property: to after toString and see if that fixes your problem. But
given the error, my guess is that the problem relates to the fact that you
templatized the constructor, which is often problematic, and whatever type
introspection std.conv.to is doing could be choking on that. So, you should
probably try making it so that the constructor isn't templatized and see if
that fixes the problem.

- Jonathan M Davis




More information about the Digitalmars-d-learn mailing list