www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - to!(ubyte[])("")

reply simendsjo <simendsjo gmail.com> writes:
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)
----------------
to(_d_assert_msg+0x45) [0x43700d]
to( property dchar  
std.array.front!(immutable(char)[]).front(immutable(char)[])+0x4c)  
[0x42f2b8]
to(ubyte[] std.conv.parse!(ubyte[], immutable(char)[]).parse(ref  
immutable(char)[], dchar, dchar, dchar).void  
parseCheck!(_D3std4conv17__T5parseTAhTAyaZ5parseFKAyawwwZAh1sAy
).parseCheck(dchar,  
immutable(char)[], ulong)+0x2f) [0x43482b]
to(ubyte[] std.conv.parse!(ubyte[], immutable(char)[]).parse(ref  
immutable(char)[], dchar, dchar, dchar)+0x49) [0x42f50d]
to(ubyte[] std.conv.toImpl!(ubyte[],  
immutable(char)[]).toImpl(immutable(char)[])+0x31) [0x42f619]
to(ubyte[]  
std.conv.to!(ubyte[]).to!(immutable(char)[]).to(immutable(char)[])+0x20)  
[0x42f268]
to(_Dmain+0x1a) [0x42f242]
Jun 22 2012
parent "Kenji Hara" <k.hara.pg gmail.com> writes:
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
Jun 22 2012