3 ms·
I do not believe that the rust solution can be exactly encoded in C++ as the C++ type system itself can't statically guarantee linear typing. You have to use mo
by gpderetta 4y ago
I do not believe that the rust solution can be exactly encoded in C++ as the C++ type system itself can't statically guarantee linear typing. You have to use move semantics with a runtime guard...
... except that it might be possible to also "shift left" in C++, by running the pin-using code a compile-time (possibly instantiating it on mock objects) and validate the "runtime guard". This is a rough example https://gcc.godbolt.org/z/f5P3oaPME https://gcc.godbolt.org/z/f5P3oaPME .
Of course any kind of if consteval check can bypass the check, and things become very hairy if the pin is set to output mode conditionally.
I would like to see how the borrow checker would fare under runtime-conditional borrowing and what kind of syntatic limitations it uses to still guarantee its constraint statically.
- JonChesterfield 4y agoCan rust do linear types? I thought it was limited to affine by the exception machinery
- gpderetta 4y agoIt is probably close enough for this use.