You forget that the map key is constant (to prevent intentional or accidental messing with the internal ordering of the associative container):
ntohl_map.insert( std::pair<uint32_t const, std::unique_ptr<uint32_t>>(
To avoid the error, you could do:
ntohl_map.insert(ntohl_map_type::value_type(key, std::move(u32_uptr2)));
The reason the original insert() call from your question text does not compile is because the type of the pair you provide is different from the type of the pair that insert() accepts (due to this const ), it should happen conversion, which will lead to an attempt to copy-create a temporary pair from the one you provide.
Copy-pairing means copying your elements, and since std::unique_ptr not constructive for copying, your program will not compile.
The reason that compiling a function using map<uint32_t, uint32_t> is because uint32_t (obviously) possible to copy.
Also note that since C ++ 11 std::map has a member function emplace() (which some implementations do not yet provide, so this may be your case), which allows you to create your own elements in place:
ntohl_map.emplace(key, std::move(u32_uptr2));
source share