有什么地方可以确认吗?我不确定是 GCC 的问题还是我的代码的问题。例如,以下代码无法编译:
#include <unordered_set>
#include <memory>
using namespace std;
int main() {
unordered_set<unique_ptr<int> > s;
unique_ptr<int> p(new int(0));
s.insert(move(p));
return 0;
}
错误信息太大,我不想放在这里。 GCC 版本为 4.5.3,编译标志为 -std=gnu++0x。也在 4.4.5 上测试过。
最佳答案
GCC 4.6.1 按原样接受您的代码,我认为它没有任何问题(即关联容器的 value_type 必须是 EmplaceInsertable 并且 std::unique_ptr
不会阻止这种情况)。大概这是 GCC 4.5 中的一个缺陷。
关于c++ - GCC 4.4/4.5 unique_ptr 不适用于 unordered_set/unordered_map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7342703/