该锈语言网站索赔移动语义的语言的特征之一.但我无法看到Rust中如何实现移动语义.
Rust box是唯一使用移动语义的地方.
let x = Box::new(5);
let y: Box<i32> = x; // x is 'moved'
Run Code Online (Sandbox Code Playgroud)
上面的Rust代码可以用C++编写
auto x = std::make_unique<int>();
auto y = std::move(x); // Note the explicit move
Run Code Online (Sandbox Code Playgroud)
据我所知(如果我错了,请纠正我),
Rust如何提供移动语义?
我在 C++ 中使用 Boehm 垃圾收集。使用GC_malloc分配后如何调用构造函数?
SomeClass *i = new SomeClass(); // Here the constructor is called.
SomeClass *j = (SomeClass *)GC_malloc(sizeof(SomeClass)); // How to call the constructor here?
Run Code Online (Sandbox Code Playgroud)