to!(ubyte[])("")

Kenji Hara k.hara.pg at gmail.com
Fri Jun 22 03:31:18 PDT 2012


On Friday, 22 June 2012 at 09:18:38 UTC, simendsjo wrote:
> Bug or by design? (using dmd head)
>
> import std.conv;
> void main() {
>     to!(ubyte[])("");
> }
>
>
> std/array.d(493): Attempting to fetch the front of an empty 
> array of immutable(char)
[snip]

It is design. With the conversion from string to non-string type, 
std.conv.to runs parsing.

import std.conv;
void main()
{
     auto arr = to!(ubyte[])("[1,2,3]");
     // parse given string as a representation of ubyte[] value.
     assert(arr == [1,2,3]);
}

And, the representation string of a value should have one or more 
characters.
So empty string always throws exception.

Kenji Hara


More information about the Digitalmars-d-learn mailing list