Re:Emulating the Rust borrow checker with C++ move-only types
by kibwen on Saturday May 13, 2017 @05:53PM
(#14333220)
That's actually even way too much code for the Rust version. A wrapper type declaration is as simple as `struct MoveOnlyInt(i32);`, and construction is then just `let foo = MoveOnlyInt(42);`. (And of course, the wrapper type is only necessary because integers in Rust implement `Copy`, opting out of move semantics.)
Re:Emulating the Rust borrow checker with C++ move-only types
by steveklabnik on Saturday May 13, 2017 @05:55PM
(#14333224)
(and "operator int" would be foo.0 in this case)
Re:Emulating the Rust borrow checker with C++ move-only types
by heinrich5991 on Sunday May 14, 2017 @07:36AM
(#14335197)
Don't use `isize`, `isize` is not equivalent to C's `int`, but `intptr_t`. Specific sizes would be best, but if you need to copy C's `int`, there's `libc::c_int`.
And of course since it's the language's default you don't have to write a dozen lines of boilerplate either, this is the C++ code stripped of the interspersed text:
This seems like a fair Rust version, with as you noted the "move source" becoming inaccessible rather than just being in an invalid state: