Re: Inserting into zero-length dynamic array

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 3:19 PM, Cecil Ward wrote: I have a dynamic array of strings of length zero. When i write to the first element the program crashes, not surprisingly, but what should I be doing?  dstring[] arr;  arr[0] = "my string"d; // BANG !! It depends on the semantic requirement. If the re

Re: Zapping a dynamic string

2023-07-04 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 4 July 2023 at 17:46:22 UTC, Steven Schveighoffer wrote: On 7/4/23 1:01 PM, Cecil Ward wrote: I have a mutable dynamic array of dchar, grown by successively appending more and more. When I wish to zap it and hand the contents to the GC to be cleaned up, what should I do? What happe

Inserting into zero-length dynamic array

2023-07-04 Thread Cecil Ward via Digitalmars-d-learn
I have a dynamic array of strings of length zero. When i write to the first element the program crashes, not surprisingly, but what should I be doing? dstring[] arr; arr[0] = "my string"d; // BANG !!

Re: Zapping a dynamic string

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 1:01 PM, Cecil Ward wrote: I have a mutable dynamic array of dchar, grown by successively appending more and more. When I wish to zap it and hand the contents to the GC to be cleaned up, what should I do? What happens if I set the .length to zero? If you want to forget it so the GC c

Re: Zapping a dynamic string

2023-07-04 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 4 July 2023 at 17:01:42 UTC, Cecil Ward wrote: I have a mutable dynamic array of dchar, grown by successively appending more and more. When I wish to zap it and hand the contents to the GC to be cleaned up, what should I do? What happens if I set the .length to zero? I do want to

Re: applay for template function with sumtypes result?

2023-07-04 Thread ryuukk_ via Digitalmars-d-learn
Hopefully we'll get tagged union in the future - no templates - proper support - proper error messages

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 11:15 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 14:42:31 UTC, Steven Schveighoffer wrote: On 7/4/23 10:19 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function ac

Re: applay for template function with sumtypes result?

2023-07-04 Thread kiriakov via Digitalmars-d-learn
On Tuesday, 4 July 2023 at 14:42:31 UTC, Steven Schveighoffer wrote: On 7/4/23 10:19 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function accepted should return `Result` but it

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 10:19 AM, kiriakov wrote: On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function accepted should return `Result` but it's returning `ParsResult`. That's the problem Result(T) = SumType!

Re: applay for template function with sumtypes result?

2023-07-04 Thread kiriakov via Digitalmars-d-learn
On Tuesday, 4 July 2023 at 12:43:19 UTC, Steven Schveighoffer wrote: On 7/4/23 12:58 AM, kiriakov wrote: It looks like a type mismatch. The function accepted should return `Result` but it's returning `ParsResult`. -Steve That's the problem Result(T) = SumType!(ParsResult!T, Err!T)

Re: applay for template function with sumtypes result?

2023-07-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/4/23 12:58 AM, kiriakov wrote: Hi. I can't handle template. It all looks sad, build ok, test error. ``` struct ParsResult(T) { T[] _in; T[] _out; } struct Err(T) { T[] x; } struct Result(T) {     SumType!(ParsResult!T, Err!T) data;     alias data this;     this(Value)(Value value) { dat