#include <unordered_map>
#include <type_traits>
int main()
{
std::unordered_multimap<int, string> m{ { 1, "hello" } };
auto b = std::is_move_assignable_v<decltype(*m.begin())>;
// b is true
auto v = *m4.begin(); // ok
v = std::move(*m4.begin()); // compile-time error
}
Issue:
If
b
is true, thenv = *m4.begin();
should be ok.
Question:
Why does
std::is_move_assignable
not behave as expected?
Error messages: (Clang 3.8 + Visual Studio 2015 Update 3)
error : cannot assign to non-static data member 'first' with const-qualified type 'const int' first = _Right.first; ~~~~~ ^ main.cpp(119,5) : note: in instantiation of member function 'std::pair<const int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator=' requested here v = *m4.begin(); // error
Dereferencing
.begin()
iterator of empty container is undefined behaviour.