digitalmars.D - Algebraic replacement
- Freddy (5/5) Jul 08 2015 std.variant's Algebraic
- Andrei Alexandrescu (4/11) Jul 08 2015 No. The code is incorrect in several places.
- Freddy (12/13) Jul 08 2015 peek returns a pointer to a stack variable
- Freddy (2/5) Jul 08 2015 + I meant that it can't be used in @safe code
- Andrei Alexandrescu (3/7) Jul 08 2015 I see. Indeed that method can't be used in safe code - the others
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
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
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
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:+ I meant that it can't be used in safe codeWhat's unsafe about it?
Jul 08 2015
On 7/8/15 6:27 PM, Freddy wrote:On Wednesday, 8 July 2015 at 22:19:52 UTC, Freddy wrote:I see. Indeed that method can't be used in safe code - the others should. -- AndreiOn Wednesday, 8 July 2015 at 21:34:01 UTC, Andrei Alexandrescu wrote:+ I meant that it can't be used in safe codeWhat's unsafe about it?
Jul 08 2015