
#include <iostream>
#include <cassert>
#include <vector>

class MyClass
{
public:
    explicit MyClass(
        int theA, 
        int theB
    ) : myA(theA), 
        myB(theB)
    {
        return;
    };
    
    MyClass(
        MyClass && theOther
    ) : myA(std::move(theOther.myA)), 
        myB(std::move(theOther.myB))
    {
        return;
    }
    
    MyClass & operator=(
        MyClass && theOther
    ) {
        assert(this != &theOther);
        
        myA = std::move(theOther.myA);
        myB = std::move(theOther.myB);
    }
    
private:
    // Not default-constructible. 
    explicit MyClass();

    // Enforce move-semantics. 
    MyClass(const MyClass & theOther);
    MyClass & operator=(const MyClass & theOther);

public:
    int myA;
    int myB;
};

int main(int argc, char * argv[])
{
    std::vector<MyClass> v1;
    std::vector<MyClass> v2;
    
    v1.push_back(MyClass(1, 2));
    v1.push_back(MyClass(2, 3));
    v1.push_back(MyClass(2, 4));
    
    // Works.
    for(auto i = 0u; i < v1.size(); i++)
        if(v1[i].myA == 2)
            v2.push_back(std::move(v1[i]));


    // Does not work: Calls copy-constructor.
    for(auto i = v1.begin(); i != v1.end(); i++)
        if(i->myA == 2)
            v2.push_back(std::move(*i));


    // list1 may not be used any longer!
    
    return 0;
}
