D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 12181 - std.conv.to should support static array manifest constants
Summary: std.conv.to should support static array manifest constants
Status: RESOLVED DUPLICATE of issue 8424
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL: https://github.com/D-Programming-Lang...
Keywords: pull
Depends on:
Blocks:
 
Reported: 2014-02-16 05:11 UTC by Manu
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Manu 2014-02-16 05:11:38 UTC
Should this work?

 enum float[4] x = [0,1,2,3]; // fixed array
 pragma(msg, to!string(x));

1>src\db\performance.d(159): Error: template std.conv.to does not match any function template declaration. Candidates are:
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(276):        std.conv.to(T)
1>src\db\performance.d(159): Error: template std.conv.to(T) cannot deduce template function from argument types !(string)(float[4])
1>src\db\performance.d(160):        while evaluating pragma(msg, s)


Another:

 enum float[] x = [0,1,2,3]; // dynamic array
 pragma(msg, to!string(x));

1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\math.d(3892): Error: Cannot convert &real to ushort* at compile time
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1568):        called from here: isNaN(cast(real)val)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2373):        called from here: formatValue(w, val, f)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(2185):        called from here: formatElement(w, front(val), f)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\format.d(1904):        called from here: formatRange(w, obj, f)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(107):        called from here: formatValue(w, src, f)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(866):        called from here: toStr(value)
1>C:\dev\D\dmd2\windows\bin\..\..\src\phobos\std\conv.d(281):        called from here: toImpl(_param_0)
1>src\db\performance.d(159):        called from here: to([0.000000F, 1.00000F, 2.00000F, 3.00000F])
1>src\db\performance.d(160):        while evaluating pragma(msg, s)


It does seem to work with arrays of int's.
Comment 1 Manu 2014-02-16 05:12:44 UTC
Actually, int[] works, but int[4] doesn't work.
So it seems arrays of floats fail, also, fixed length arrays fail.
Comment 2 Andrej Mitrovic 2014-02-16 05:18:25 UTC
Typical workaround would be:

pragma(msg, to!string(x[]));

But this only works at runtime, at CT it's an error:

C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\format.d(1623): Error: _snprintf cannot be interpreted at compile time, because it has no available source code
Comment 3 Andrej Mitrovic 2014-04-21 16:36:08 UTC
This is an issue with the 'to' template which takes a 'ref', and you can't pass manifest constants by reference. I'll try and use 'auto ref'.
Comment 4 Andrej Mitrovic 2014-04-24 13:01:36 UTC
Blocked by 'auto ref' implementation issues.
Comment 5 basile-z 2017-09-13 18:19:53 UTC
Now blocked by the format sub-routine not available at CTFE b/c of the dependecy to the standard C library, which is another issue.

*** This issue has been marked as a duplicate of issue 8424 ***