【发布时间】:2016-04-05 17:44:11
【问题描述】:
我正在尝试对包含不可复制构造或默认构造(但可移动构造)的对象的向量进行排序,但我收到有关编译器无法为 swap 找到有效函数的错误。我认为拥有一个移动构造函数就足够了。我在这里错过了什么?
class MyType {
public:
MyType(bool a) {}
MyType(const MyType& that) = delete;
MyType(MyType&& that) = default;
};
int main(void) {
vector<MyType> v;
v.emplace_back(true);
sort(v.begin(), v.end(), [](MyType const& l, MyType const& r) {
return true;
});
}
【问题讨论】:
标签: c++ sorting c++11 move-semantics