D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4971 - to!() fails with static arrays
Summary: to!() fails with static arrays
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Linux
: P2 enhancement
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-01 22:54 UTC by Jonathan M Davis
Modified: 2015-06-09 05:14 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 Jonathan M Davis 2010-10-01 22:54:00 UTC
This code fails to compile

import std.conv;
import std.stdio;

void main()
{
    dchar[7] numStr = "1234567";

    writeln(to!long(numStr));
}


with this error

/home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(95): Error: template std.conv.toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) toImpl(T,S) if (!implicitlyConverts!(S,T) && isSomeString!(T) && isInputRange!(Unqual!(S)) && isSomeChar!(ElementType!(S))) matches more than one template declaration, /home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(217):toImpl(T,S) if (isStaticArray!(S)) and /home/jmdavis/Downloaded_Files/dmd/dmd2/linux/bin/../../src/phobos/std/conv.d(588):toImpl(T,S) if ((is(S : const(wchar)[]) || is(S : const(dchar)[])) && !isSomeString!(T))


If you use numStr[] instead of numStr, it works. But I see no reason why to!() can't be made to work with a static array. Ideally, it would either turn it into a const ref or a dynamic slice itself, thus avoiding creating a copy, but right now it just fails. Maybe that's just how things go with static arrays, but it seems overly restrictive in this case. to!() shouldn't _need_ a dynamically allocated array.
Comment 1 Jonathan M Davis 2011-06-11 20:06:18 UTC
Related: http://d.puremagic.com/issues/show_bug.cgi?id=6148
Comment 2 Kenji Hara 2011-08-31 21:36:54 UTC
std.conv.to now support static array conversion, it is treated as dynamic array.