Bug 12181 – std.conv.to should support static array manifest constants

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-16T05:11:38Z
Last change time
2020-03-21T03:56:41Z
Keywords
pull
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2014-02-16T05:11:38Z
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 by turkeyman — 2014-02-16T05:12:44Z
Actually, int[] works, but int[4] doesn't work. So it seems arrays of floats fail, also, fixed length arrays fail.
Comment #2 by andrej.mitrovich — 2014-02-16T05:18:25Z
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 by andrej.mitrovich — 2014-04-21T16:36:08Z
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 by andrej.mitrovich — 2014-04-24T13:01:36Z
Blocked by 'auto ref' implementation issues.
Comment #5 by b2.temp — 2017-09-13T18:19:53Z
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 ***