Assigning to array of structs with custom constructor

cc cc at nevernet.com
Mon Apr 25 15:20:38 UTC 2022


On Monday, 25 April 2022 at 15:13:51 UTC, Stanislav Blinov wrote:
> Make it explicit:
>
> ```d
> Foo[] foos = [Foo("a")];
> ```

There's that too, but I still have to iterate manually. e.g.:

```d
string[] ss = loadABunchOfStringsFromSomewhere();
//Foo[] foos = ss; //error
Foo[] foos;
foos.reserve(ss.length);
foreach (s; ss)
	foos ~= Foo(s);
```

Was just hoping there was a way to streamline it within the 
struct definition.


More information about the Digitalmars-d-learn mailing list