g++ 4.7.2是否实现了C++11标准和文档here所定义的std::set::emplace
我写了下面的小测试用例:
#include <set>
#include <string>
struct Foo
{
std::string mBar;
bool operator<(const Foo& rhs) const
{
return mBar < rhs.mBar;
}
Foo(const std::string bar) : mBar(bar) {};
};
typedef std::set<Foo> Foos;
int main()
{
Foos foos;
foos.emplace(std::string("Hello"));
}在G++ 4.7.2下,这无法编译:
[john.dibling@somewhere hacks]$ g++ -o main.o -std=c++0x -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:19:10: error: ‘Foos’ has no member named ‘emplace’也无法在IDEOne下编译,但在MSVC2012更新1下编译。
发布于 2013-04-04 21:55:32
It is not implemented in gcc 4.7.2.
这里有一些解释:
只是想澄清一下:这不是一个疏忽。我们在使用std::pair的C++0x标准草案中遇到了令人讨厌的问题,这使得在不破坏现有用户代码的情况下,不可能将emplace_*成员添加到std::map、std::multimap等。因此,我们一直在等待,直到这整个领域的事情得到澄清。现在,实际上可以在这些设施上工作了。
你的代码可以用gcc 4.8.0很好地编译,请参阅LWS。
发布于 2013-04-04 21:36:10
用于关联容器的emplace()是在libstdc++中为gcc 4.8.0添加的,在gcc 4.7.2下将不起作用。
https://stackoverflow.com/questions/15812276
复制相似问题