If I create a struct with an explicit constructor
struct A { int x; explicit A(int x):x(x){}; }; And then use it as the mapped_type in a std::map, I am able to emplace with the piecewise constructor:
#include <map> std::map<int, A> foo; foo.emplace( std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(10) ); But I when I try to use the move or template constructors, I get errors and can't compile:
foo.emplace(std::make_pair(2, 20)); // <-- doesn't work foo.emplace(3, 30); // <-- doesn't work What's going on here? Until now, I hadn't appreciated that there was much of a difference between these different usages. I guess, with the pair move constructor, it could make sense that there's an implicit conversion from std::pair<int, A>... but why does that have to happen in the template constructor? And then why not with the piecewise constructor??
I've poked around a bit, but the docs for std::map::emplace and for explicit don't really clarify this for me.