Thread overview
[Issue 4971] New: to!() fails with static arrays
Oct 02, 2010
Jonathan M Davis
Jun 12, 2011
Jonathan M Davis
Sep 01, 2011
Kenji Hara
October 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4971

           Summary: to!() fails with static arrays
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: jmdavisProg@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg@gmx.com> 2010-10-01 22:54:00 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4971


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 12, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4971



--- Comment #1 from Jonathan M Davis <jmdavisProg@gmx.com> 2011-06-11 20:06:18 PDT ---
Related: http://d.puremagic.com/issues/show_bug.cgi?id=6148

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 01, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4971


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2011-08-31 21:36:54 PDT ---
std.conv.to now support static array conversion, it is treated as dynamic array.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------