| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
July 08, 2015 Algebraic replacement | ||||
|---|---|---|---|---|
| ||||
std.variant's Algebraic (https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d) seems very complex for what it's trying to do and is also unsafe. Is it worth writing a simpler replacement? Something like this https://github.com/Superstar64/tagged_union/blob/master/source/tagged_union.d ? | ||||
July 08, 2015 Re: Algebraic replacement | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Freddy | On 7/8/15 4:31 PM, Freddy wrote: > std.variant's Algebraic > (https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d) > seems very complex for what it's trying to do and is also unsafe. What's unsafe about it? > Is it worth writing a simpler replacement? > > Something like this > https://github.com/Superstar64/tagged_union/blob/master/source/tagged_union.d > ? No. The code is incorrect in several places. Andrei | |||
July 08, 2015 Re: Algebraic replacement | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, 8 July 2015 at 21:34:01 UTC, Andrei Alexandrescu wrote:
> What's unsafe about it?
peek returns a pointer to a stack variable
import std.variant;
import std.stdio;
void main()
{
Algebraic!(int,string) a = "a";
string* b = a.peek!string;
a = 0;
writeln(b.length);
}
| |||
July 08, 2015 Re: Algebraic replacement | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Freddy | On Wednesday, 8 July 2015 at 22:19:52 UTC, Freddy wrote:
> On Wednesday, 8 July 2015 at 21:34:01 UTC, Andrei Alexandrescu wrote:
>> What's unsafe about it?
+ I meant that it can't be used in @safe code
| |||
July 09, 2015 Re: Algebraic replacement | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Freddy | On 7/8/15 6:27 PM, Freddy wrote:
> On Wednesday, 8 July 2015 at 22:19:52 UTC, Freddy wrote:
>> On Wednesday, 8 July 2015 at 21:34:01 UTC, Andrei Alexandrescu wrote:
>>> What's unsafe about it?
> + I meant that it can't be used in @safe code
I see. Indeed that method can't be used in safe code - the others should. -- Andrei
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply