On Saturday, 14 November 2015 at 12:55:52 UTC, BBaz wrote:
On Saturday, 14 November 2015 at 12:46:21 UTC, Relja wrote:
I've got this strange compile error using std.conv.to!string(double[3]) - or any static array type. It's called in toString override function of a template matrix class, I'm building as a D learning project.

[...]

Maybe try to use a full slice after a 'static if' in case the template type is static array:

--
{
    ElementType!T[] something;
    static if (isStaticArray!T)
        something = value[]; // slice to get a dyn array
    else
        something = value; // already a dyn array
}
--

and you work on something when it only works on dyn array. You can also slice the whole static array each time the problem occurrs

I'm not sure if I understand you fully, but I think you misunderstood me - std.conv.to!string() works on a static array, when called directly on the array object, but gives the compile error when called on the returning object from a function.

Here is simpler example, which shows the same compile error:

import std.conv;

float[3] getFloat3() {
    return [1, 2, 3];
}

void main() {
    getFloat3().to!string; // does not compile
    (new float[3]).to!string; // compiles
}

On this example, compiler error message is the same as above:
source/app.d(10,12): Error: template std.conv.to cannot deduce function from argument types !(string)(float[3]), candidates are:
/usr/include/dlang/dmd/std/conv.d(293,1):        std.conv.to(T)
dmd failed with exit code 1.

But then again, your suggestion got me to try this:
getFloat3()[].to!string;

This does compile! Can somebody elaborate, and tell us whats going on here? I feel that this does not solve my issue, but only makes me stay away from calling std.conv.to in this way.

Thanks,
Relja

Reply via email to