1

I'm having these two simple codes :

void f(){
    std::map<int,std::unique_ptr<int>> map_;
    std::unique_ptr<int> p;
    map_[42] = std::move(p);
}

does build

struct test_s{
    int toto;
    std::unique_ptr<int> tata;
};
void f(){
    std::map<int,test_s> map_;
    test_s p;
    map_[42] = std::move(p);
}

does not build because copy is forbidden on visual ctp120 It does build on MAC with Clang 4.2

Anyone has an idea about what I should change to make this work ?

dzada
  • 5,344
  • 5
  • 29
  • 37

1 Answers1

1

Explicitly defining move constructor and move assignment operator is a workaround (tested with VS2010):

struct test_s{
    int toto;
    std::unique_ptr<int> tata;
    test_s() : toto(0) {}
    test_s& operator=(test_s&& o)
    {
        toto = o.toto;
        tata = std::move(o.tata);
        return *this;
    }
    test_s(test_s&& o) : toto(o.toto), tata(std::move(o.tata)) {}
};

As a guess, MSVC is not auto generating the move operations.

hmjd
  • 120,187
  • 20
  • 207
  • 252