简体   繁体   English

boost :: move和stl算法

[英]boost::move and stl algorithms

Rvalue reference is one of the best feature in c++11, but our old compilers do not support this beautiful creature. Rvalue引用是c ++ 11中最好的功能之一,但我们的旧编译器不支持这个美丽的生物。 After some study, creating a moveable "unique_ptr" is not too hard with the help of boost::move, the better news is that boost::container can work with boost::move too. 经过一些研究,在boost :: move的帮助下创建一个可移动的“unique_ptr”并不太难,更好的消息是boost :: container也可以与boost :: move一起使用。

My question is, is it possible to make the algorithms like std::swap_range or std::sort benefit from boost::move? 我的问题是,是否有可能使像std :: swap_range或std :: sort这样的算法受益于boost :: move? Or do I have to write one for my self? 或者我必须为自己写一个?

in pre-C++11 std::sort uses swap internally, so as long as you define swap appropriately for your class (don't forget ADL), it should use that instead of copying each object. 在pre-C ++ 11中, std::sort内部使用swap ,因此只要你为你的类适当地定义swap (不要忘记ADL),就应该使用它而不是复制每个对象。
Move semantics wouldn't do anything significant here. 移动语义在这里不会有任何重要意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM