▲ | tialaramex 5 days ago | ||||||||||||||||
This means C++ is riddled with types that have unrelated "I'm empty" state inside them rather than this being relegated to a separate wrapper type. It's Tony's Billion Dollar Mistake but smeared across an entire ecosystem. The smart pointer std::unique_ptr<T> is an example of this, sometimes people will say it's basically a boxed T, so analogous to Rust's Box<T> but it isn't quite, it's actually equivalent to Option<Box<T>>. And if we don't want to allow None? Too bad, you can't express that in C++ But you're right that C++ people soldier on, there aren't many C++ types where this nonsense unavoidably gets in your face. std::variant's magic valueless_by_exception is such an example and it's not at all uncommon for C++ people to just pretend it can't happen rather than take it square on. | |||||||||||||||||
▲ | spacechild1 5 days ago | parent | next [-] | ||||||||||||||||
> This means C++ is riddled with types that have unrelated "I'm empty" state Again, these cases are still rare. Most classes either don't require user-defined move operations, or they have some notion of emptiness or default state. > And if we don't want to allow None? Too bad, you can't express that in C++ That's actually a good example! Nitpick: you can express it in C++, just not without additional logic and some overhead :) | |||||||||||||||||
| |||||||||||||||||
▲ | steveklabnik 5 days ago | parent | prev [-] | ||||||||||||||||
(And that difference leads to an ABI difference that makes it not a zero overhead abstraction in the way that Box is…) | |||||||||||||||||
|