没有编译器定义的移动构造函数的容器中需要显式移动构造函数吗?
Explicit move constructor needed in container with no compiler-defined move constructor?
这是我之前问题的修改 。
我有一个模板容器class:
template<class Stuff>
class Bag{
public:
~Bag() {//Do some stuff here so that the compiler doesn't implement move semantics}
private:
std::vector<Stuff> mData;
};
我想做
void InPlace(Bag<Array>& Left){
Bag<Array> temp;
Transform(Left, temp); //fills temp with desirable output
Left = std::move(temp);
}
假设 Array 具有用户定义的移动语义,但 Bag 没有。在这种情况下,mData 会被移动或复制吗?
如果 Bag 不支持移动语义,则没有适用的移动操作。复制assignment/construction将相应发生。
这是我之前问题的修改
我有一个模板容器class:
template<class Stuff>
class Bag{
public:
~Bag() {//Do some stuff here so that the compiler doesn't implement move semantics}
private:
std::vector<Stuff> mData;
};
我想做
void InPlace(Bag<Array>& Left){
Bag<Array> temp;
Transform(Left, temp); //fills temp with desirable output
Left = std::move(temp);
}
假设 Array 具有用户定义的移动语义,但 Bag 没有。在这种情况下,mData 会被移动或复制吗?
如果 Bag 不支持移动语义,则没有适用的移动操作。复制assignment/construction将相应发生。