isocpp.org指出:
move-based std::sort() and std::set::insert() have been measured to be 15 times faster than copy based versions[…] if your type has a move operation,you gain the performance benefits automatically from the standard algorithms.
这是否意味着如果在没有移动构造函数或移动赋值运算符的用户定义类型上调用sort(),那么是否使用了移动语义?换句话说,要获得C 11性能改进的诸多好处,您应该编辑现有代码以明确添加移动操作吗?
此外,如果要进行排序,是容器还是容器内的类型,或两者都必须定义移动操作?
解决方法
Does this mean that if you call sort() on a user-defined type that has no move constructor or move assignment operator,then there are no move semantics used?
正确.如果班级不可移动,那么它将回归复制
In other words,to get the many benefits of C++11 performance improvements,you should edit existing code to add move operations explicitly?
如果你可以肯定,谁不喜欢更多的表现.请注意,根据课程,你可能会获得automatically generated move operations.
Further,if you are sorting,is it the container or the type inside the container,or both,that must have move operations defined?
容器本身不需要是可移动的. std :: sort要求传递给它的迭代器应满足ValueSwappable(17.6.3.2)的要求.并且取消引用迭代器返回的类型应满足MoveConstructible(表20)和MoveAssignable的要求(表22).
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|