container vs standard array

JG jg at jg.com
Tue Sep 19 06:35:01 UTC 2023


On Tuesday, 19 September 2023 at 00:34:01 UTC, vino wrote:
> Hi All,
>
>  I am trying to understand as to why the below code is throwing 
> error
>
> Code
> ```
> import std.stdio: writeln;
> import std.container.array;
>
> void main () {
>  //auto a = Array!string("Aname");           // throws error
>  auto b = Array!char("Bname");             	// works
>  auto c = Array!string("Aname", "Bname");  	// works
>
>  //writeln(a);
>  writeln("Container Array :", b);
>  writeln("Container Array :", c);
>
>  writeln();
>
>  string[] d = ["Dname"];			       // works
>  string[] e = ["Dname", "Ename"];              // works
>  writeln("Standard Array :", d);
>  writeln("Standard Array :", e);
>
> }
> ```
> From,
> Vino
Looks to me like when it receives a single range it expects the 
elements of that range to match the type. If I am correct in the 
first one if you replace the "Aname" by ["Aname"] it should work



More information about the Digitalmars-d-learn mailing list