On 4/25/22 21:32, Salih Dincer wrote:
> So the problem is that the structure is not in the inter-module space
Nested structs carry an additional pointer to their containing context.
When they don't need the context, we define them with 'static':
void foo() {
static struct Bar { }
}
> If ``
😀
So the problem is that the structure is not in the inter-module
space
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
This works:
```d
import std;
void main() {
struct Foo { string s; }
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
arr.writeln; // => [Foo("abc"), F
On 4/25/22 19:37, Salih Dincer wrote:
> a lot of errors 😀
Hm. I can't reproduce any of that. I did two things:
1) Added necessary import directives
2) Moved all expressions into the main() function
I did not change anything else. The program below compiles and works
with all these compilers:
On Tuesday, 26 April 2022 at 00:57:54 UTC, Ali Çehreli wrote:
On 4/25/22 16:59, Salih Dincer wrote:
> Because it cannot be used with other possibilities such as
> ```chunks()``` and ```take()```.
There must be something wrong. map is commonly used with
chunks(), take(), etc.
> Also it cannot
On 4/25/22 16:59, Salih Dincer wrote:
> Because it cannot be used with other possibilities such as
> ```chunks()``` and ```take()```.
There must be something wrong. map is commonly used with chunks(),
take(), etc.
> Also it cannot be customized with
> ```toString()```.
Can you show examples
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
```d
import std;
void main() {
struct Foo { string s; }
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
arr.writeln; // => [Foo("abc"), Foo("def"), Foo("ghi")]
}
```
Thank you...
Very very nice and simple but not extensible
On Monday, 25 April 2022 at 15:23:12 UTC, Ali Çehreli wrote:
auto arr = iota(10).map!(i => Foo(i.text)).array;
On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote:
Foo[] arr = ["abc", "def", "ghi"].map!Foo.array;
Ahh that'll do it alright, thanks
On 4/25/22 16:36, cc via Digitalmars-d-learn wrote:
```d
struct Foo {
string s;
this(string s) { this.s = s; }
}
Foo foo = "a";
Foo[] foos = ["a"]; // Error: cannot implicitly convert expression `["a"]` of type `string[]` to
`Foo[]`
Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir: cann
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
> `["
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.len
On Monday, 25 April 2022 at 14:36:25 UTC, cc wrote:
```d
struct Foo {
string s;
this(string s) { this.s = s; }
}
Foo foo = "a";
Foo[] foos = ["a"]; // Error: cannot implicitly convert
expression `["a"]` of type `string[]` to `Foo[]`
Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir:
On Monday, 25 April 2022 at 15:00:13 UTC, Alain De Vos wrote:
Not really an answer but this works,
```
void main(){
Foo foo = "a";
Foo[] foos;
foos ~=foo;
}%
```
Right, I can append individual elements, but can't assign or
append a slice of a type that can be individually cast to the
struct.
Not really an answer but this works,
```
struct Foo {
string s;
this(string s) { this.s = s; }
}
void main(){
Foo foo = "a";
Foo[] foos;
foos ~=foo;
}%
```
13 matches
Mail list logo