4 ms·
This isn't true in general, it's only true when T is a pointer type, in which case C++ would just use a pointer.
by detrino 11y ago
This isn't true in general, it's only true when T is a pointer type, in which case C++ would just use a pointer.
- pcwalton 11y agoOr if T is NonZero. More importantly, dereferencing a None is not undefined behavior in Rust.
- vvanders 11y agoIt seems like that wasn't the case for the proposed C++ variant. It seems like you would have to use some sort of sentinel value to discriminate between None and Some(or virtual which is even worse). Rust explicitly omits the sentinel value and leaves it to the compiler so that it can decide how to optimize best.
- detrino 11y agoI'm just saying you wouldn't use std::variant<T star>, you'd just use T star. Also C++ has the meta-programming capabilities to special variant for pointers. edit: replaced * with star to defeat italicizer.