4 ms·
And of course his "simple" example of an `Either` class leaks and doesn't call destructors, because C++ unions do not cleanly support types with nontrivial dest
by workincog 9y ago
And of course his "simple" example of an `Either` class leaks and doesn't call destructors, because C++ unions do not cleanly support types with nontrivial destructors.
Meanwhile the open source project he links to has an implementation that is hundreds of lines of template magic that I gave up on interpreting.
I've dealt with codebases like this and I strongly recommend against using this kind of arcane template incantations in production. It becomes an impenetrable fog for newbies, and a morass for veterans with something to prove.
- fnl 9y agoCan you please point out what about Buckaroo's (i.e., the author's) solution is wrong? I take it, his version of Either is copied from the neither project [1], so the destructor of the union is: ~Either() { if(isLeft) { leftValue.~L(); } else { rightValue.~R(); } } Which does explicitly call the destructors. (Obviously, if you only were referring to his eight-line toy version of Either for the blog, please forget my comment.) [EDIT: re-reading your comment once more, I see you did indeed mean the blog implementation; please ignore this comment.] [EDIT2: BTW, it seems the author is "affiliated" with that LoopPerfect/neither implementation.] [1] https://github.com/LoopPerfect/neither/blob/master/neither/include/either.hpp https://github.com/LoopPerfect/neither/blob/master/neither/i...