r/cpp • Meson dev • May 13 '17

Emulating the Rust borrow checker with C++ move-only types

http://nibblestew.blogspot.com/2017/05/emulating-rust-borrow-checker-with-c.html
0 Upvotes

7 comments sorted by

24

u/samkellett May 13 '17

this isn't even close to what the borrow checker brings to the table

9

u/caramba2654 Intermediate C++ Student May 14 '17

Agreed. This whole article says that the borrow checker does that, when in fact it does something else completely different. What the article really explained is how to mimic Rust's move-by-default behavior and how to make types not Clone and Copy by deleting the copy constructors.

Still pretty useful article, and very practical too. It's just not what the borrow checker does.

1

u/jpakkane Meson dev May 15 '17

5

u/caramba2654 Intermediate C++ Student May 15 '17

The original post didn't even hint that there would be a part 2. 😐

8

u/bhuztez May 14 '17

take a look at mine ( https://github.com/bhuztez/borrow )

1

u/[deleted] May 15 '17 edited May 15 '17

This feature does not seem to be useful at first glance. Thanks to the brilliant friend injection techique discovered by Filip Roséen , stateful metaprogramming has become feasible in C++.

I wouldn't rely on this.

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2118

1

u/millenix May 16 '17

Useful tidbit on how to define move-only types. Any reason not to define it as the template moveOnly<T, Release>?