3 ms·
Do what? This typestate pattern in C++? Of course you can. It's almost identical to the Rust code. The only downside is that C++'s moves leave the moved-from o
by IshKebab 4y ago
Do what? This typestate pattern in C++? Of course you can. It's almost identical to the Rust code.
The only downside is that C++'s moves leave the moved-from object accessible but invalid while the Rust compiler will not let you access them. Otherwise it's the same.
If you just Google "C++ typestate" the first result is an HTTP library that uses this technique (plus a load of complex template stuff, but that isn't required). But I guess you've seen that already so maybe that's not what you're asking for?
- morelisp 4y ago> The only downside is that C++'s moves leave the moved-from object accessible but invalid while the Rust compiler will not let you access them. "Except for the whole damn point, it's the same." Oh, ok.
- IshKebab 4y agoThat's not the whole damn point. It's arguable half of it - the creation of new states is identical. It's just the destruction that is relegated from compile time to run time.
- morelisp 4y agoYes in that context "whole damn point" means the key, salient aspect of the discussion being only allowing use of the thing once. In English it's normal to not speak 100% literally. I'm guessing you're not a native English speaker - surely it is the same in other languages?