3 ms·
As someone with twenty years of C++ experience, I will say I don't see why that would be difficult to implement in C++... it doesn't even seem hard... it is the
by saurik 11y ago
As someone with twenty years of C++ experience, I will say I don't see why that would be difficult to implement in C++... it doesn't even seem hard... it is the kind of thing I would have been writing over ten years ago, actually: you just have a partial template specialization of a private base class that takes a boolean predicate as a template parameter to check for "one of these types has a sentinel value and the other type can be represented as a sentinal value" (you could even keep a count of sentinal as you lay out multiple types: count up the number that can be represented as sentinels and then verify all types have at least that many available sentinels; some types could seriously be friendly and provide a near infinite number of sentinels do to having otherwise invalid states, and this would be quite trivially handled in a generic way any type could slot into), and then you can use the null-or-not to collapse the storage of Some(T) and None.