Here is an example code:
struct T
{
T(int x) : x_(x)
{}
T(T&&) = delete;
T(const T&) = delete;
int x_;
};
int main()
{
std::unordered_map<int, T> m;
m.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2));
m.emplace(std::piecewise_construct, std::forward_as_tuple(1), std::forward_as_tuple(2));
return 0;
}
Second emplace fails but T constructor is called twice. I have though that emplace will construct an object only when insertion is possible. Could you explain it ?
Edit: I use Visual Studio 2017 compiler.