www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SList of chars not possible?

reply "They call me Mr. D" <kheaser eapl.org> writes:
auto i = SList!int(1, 2, 3, 4, 5, 6, 7);

auto f = SList!float(1.1, 2.234, 3.21, 4.3, 5.001, 6.2, 7.0);

auto s = SList!string(["I", "Hello", "World"]);

auto c = SList!char('a', 'b' ,'c');  // doesn't compile, get the 
following

C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(905): 
Error: template std.container.SList!(char).SList.insertFront does 
not match any function template
eclaration
C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(1096): 
Error: template std.container.SList!(char).SList.insertFront 
cannot deduce template function from
argument types !()(char[])
Container.d(19): Error: template instance 
std.container.SList!(char).SList.__ctor!(char) error instantiating

auto c = SList!char(['a', 'b' ,'c']); // doesn't compile either.


Seems to me a Slist of char nodes should be pretty innocuous.
Nov 01 2012
next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 11/01/2012 03:18 PM, They call me Mr. D wrote:
 auto i = SList!int(1, 2, 3, 4, 5, 6, 7);

 auto f = SList!float(1.1, 2.234, 3.21, 4.3, 5.001, 6.2, 7.0);

 auto s = SList!string(["I", "Hello", "World"]);

 auto c = SList!char('a', 'b' ,'c'); // doesn't compile, get the following

 C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(905): Error:
 template std.container.SList!(char).SList.insertFront does not match any
 function template
 eclaration
 C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(1096): Error:
 template std.container.SList!(char).SList.insertFront cannot deduce
 template function from
 argument types !()(char[])
 Container.d(19): Error: template instance
 std.container.SList!(char).SList.__ctor!(char) error instantiating

 auto c = SList!char(['a', 'b' ,'c']); // doesn't compile either.


 Seems to me a Slist of char nodes should be pretty innocuous.

Looks related to the fact that the element type of a char[] range is dchar, not char. So, SList!dchar works: auto c = SList!dchar('a', 'b' ,'c'); SList!ubyte may make sense too but it requires a cast: auto u = SList!ubyte(cast(ubyte[])[ 'a', 'b' ,'c' ]); Ali
Nov 01 2012
prev sibling next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On 2012-18-01 23:11, They call me Mr. D <kheaser eapl.org> wrote:

 auto i = SList!int(1, 2, 3, 4, 5, 6, 7);

 auto f = SList!float(1.1, 2.234, 3.21, 4.3, 5.001, 6.2, 7.0);

 auto s = SList!string(["I", "Hello", "World"]);

 auto c = SList!char('a', 'b' ,'c');  // doesn't compile, get the  
 following

 C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(905): Error:  
 template std.container.SList!(char).SList.insertFront does not match any  
 function template
 eclaration
 C:\D\dmd2\windows\bin\..\..\src\phobos\std\container.d(1096): Error:  
 template std.container.SList!(char).SList.insertFront cannot deduce  
 template function from
 argument types !()(char[])
 Container.d(19): Error: template instance  
 std.container.SList!(char).SList.__ctor!(char) error instantiating

 auto c = SList!char(['a', 'b' ,'c']); // doesn't compile either.


 Seems to me a Slist of char nodes should be pretty innocuous.

Not sure of the exact reasons, but I think Ali is probably right. A char cannot hold all possible values for a unicode character, so having a range with that element type is not really a good idea. -- Simen
Nov 02 2012
prev sibling parent "Tobias Pankrath" <tobias pankrath.net> writes:
The error is: the constructor of SList!T takes a U[] if U is 
implicitly convertible to T, but forwards to insertFront which 
requires a range of T. But inside phobos char[] is a range of 
dchar, so if fails. Imo a clear bug.

 Not sure of the exact reasons, but I think Ali is probably 
 right.

 A char cannot hold all possible values for a unicode character, 
 so
 having a range with that element type is not really a good idea.

Still, if you want to have a container of char for whatever reasons it shouldn't fail so miserably. The special treatment of char[] as range of dchar everywhere in phobos just produces bugs and confusion.
Nov 02 2012