C++ 在没有编译器定义的移动构造函数的容器中需要显式移动构造函数?

C++ 在没有编译器定义的移动构造函数的容器中需要显式移动构造函数?,c++,c++11,move-semantics,C++,C++11,Move Semantics,这是对我先前问题的修改 我有一个模板化容器类: 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; }; 模板 书包{ 公众: ~Bag(){//在这

这是对我先前问题的修改

我有一个模板化容器类:

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;
 };
模板
书包{
公众:
~Bag(){//在这里做一些事情,这样编译器就不会实现移动语义了}
私人:
std::向量mData;
};
我想做什么

void InPlace(Bag<Array>& Left){
  Bag<Array> temp;
  Transform(Left, temp); //fills temp with desirable output
  Left = std::move(temp);
}
void-in-place(袋子和左侧){
袋温;
Transform(左,temp);//用所需的输出填充temp
左=标准::移动(温度);
}

假设数组具有用户定义的移动语义,但Bag没有。在这种情况下,是否移动或复制mData?

如果Bag支持无移动语义,则不适用移动操作。复制分配/构造将相应地进行。

您是否计划对该网格中的每一行提出问题?如果
包不可移动,为什么会发生移动?您在2小时前询问过。Bag没有移动构造函数,因此temp被转换为左值(由赋值运算符)。如果我不得不猜测的话,我会认为这意味着调用了std::vector赋值(not move)操作符,因为mData也是一个左值,但我不能完全确定,因此产生了这个问题。对不起?如果对象不可移动,则“移动”将返回到“复制”。这意味着
Left=std::move(temp)是copy assignment.Btw。temp是一个左值,所以它不会导致移动到这里。