On 4/25/22 07:36, cc wrote:
> ```d
> struct Foo {
>      string s;
>      this(string s) { this.s = s; }
> }
> Foo foo = "a";

I don't understand why that syntax exists. I always write it like this:

  auto foo = Foo("a");

> Foo[] foos = ["a"]; // Error: cannot implicitly convert expression
> `["a"]` of type `string[]` to `Foo[]`

This is a way:

  Foo[] foos = [Foo("a")];

Or:

  import std.stdio;
  import std.algorithm;
  import std.range;
  import std.conv;
  auto arr = iota(10).map!(i => Foo(i.text)).array;
  writeln(arr);

Ali

Reply via email to