以下代码不会在gcc 4.8.2上编译.问题是此代码将尝试复制构造,std::pair<int, A>这是由于struct A缺少复制和移动构造函数而无法发生的.
gcc在这里失败了还是我错过了什么?
#include <map>
struct A
{
int bla;
A(int blub):bla(blub){}
A(A&&) = delete;
A(const A&) = delete;
A& operator=(A&&) = delete;
A& operator=(const A&) = delete;
};
int main()
{
std::map<int, A> map;
map.emplace(1, 2); // doesn't work
map.emplace(std::piecewise_construct,
std::forward_as_tuple(1),
std::forward_as_tuple(2)
); // works like a charm
return 0;
}
Run Code Online (Sandbox Code Playgroud)