-1

This is a modification of my earlier question Explicit move constructor needed in container?.

I have a templated container 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;
 };

I want to do

void InPlace(Bag<Array>& Left){
  Bag<Array> temp;
  Transform(Left, temp); //fills temp with desirable output
  Left = std::move(temp);
}

Suppose Array has user-defined move semantics, but Bag does not. Would mData in this case be moved or copied?

AGML
  • 890
  • 6
  • 18
  • 2
    Are you planning to ask a question about every row in that grid? – T.C. Jun 15 '17 at 19:44
  • If `Bag` is not movable why would a move happen? – NathanOliver Jun 15 '17 at 19:45
  • [Similar question](https://stackoverflow.com/q/44573222/7359094) you asked 2 hours ago. – François Andrieux Jun 15 '17 at 19:46
  • Bag does not have a move constructor, so temp gets cast to an lvalue (by the assignment operator). If I had to guess I would think this means that the std::vector assignment (not move) operator gets called, since mData is also an lvalue, but I'm not totally sure, hence the question. Sorry? – AGML Jun 15 '17 at 19:48
  • 2
    If an object is not movable then move falls back to copy. That means `Left = std::move(temp);` is copy assignment. – NathanOliver Jun 15 '17 at 19:50

1 Answers1

1

If Bag supports no move semantics then there is no move operations applicable. Copy assignment/construction will take place accordingly.

Navie
  • 164
  • 1
  • 8