SList of chars not possible?

Ali Çehreli acehreli at yahoo.com
Thu Nov 1 15:46:21 PDT 2012


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


More information about the Digitalmars-d-learn mailing list