MSVC compiler tries to call a deleted copy constructor instead of moving for a map elements

Viewed 89

Why does MSVC compiler complains about this simple code, when I emplace back into a vector an object containing an std::map or std::unordered_map, but not when it contains an std::vector? Even if some growing happens, it still should just move elements into a new location whenever it's possible, right?

Actually I just checked the code with GCC and Clang compilers, they built it without problems. Is this just an MSVC issue?

#include <vector>
#include <map>
#include <unordered_map>

struct NonCopyable
{
    NonCopyable() = default;

    NonCopyable(const NonCopyable& o) = delete;
    NonCopyable& operator=(const NonCopyable& o) = delete;

    NonCopyable(NonCopyable&& o) noexcept = default;
    NonCopyable& operator=(NonCopyable&& o) noexcept = default;

    std::unordered_map<int, int> map; // MSVC tries to call a deleted copy constructor
    // std::map<int, int> map; // MSVC tries to call a deleted copy constructor
    // std::vector<int> map; // OK
};

int main()
{
    std::vector<NonCopyable> collection;
    collection.emplace_back();
}
0 Answers
Related