www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Algebraic replacement

reply "Freddy" <Hexagonalstar64 gmail.com> writes:
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 ?
Jul 08 2015
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
Jul 08 2015
parent reply "Freddy" <Hexagonalstar64 gmail.com> writes:
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); }
Jul 08 2015
parent reply "Freddy" <Hexagonalstar64 gmail.com> writes:
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
Jul 08 2015
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
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
Jul 08 2015