std :: map emplace gcc 4.8.2 [英] std::map emplace gcc 4.8.2
本文介绍了std :: map emplace gcc 4.8.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用std :: map的emplace函数,但它似乎没有被实现(但是我读到它是在4.8中实现的)
I am trying to use the emplace function of std::map, but it seems it is not implemented (but I read it was implemented in 4.8)
以下代码:
std::map<std::string, double> maps;
maps.emplace("Test", 1.0);
导致:
class std::map<std::basic_string<char>, double>' has no member named 'emplace'
有人可以澄清哪个gcc版本的emplace函数被实现?
Can someone clarify in which gcc version the emplace functions are implemented?
推荐答案
代码:
#include <map>
#include <string>
int main()
{
std::map<std::string, double> maps;
maps.emplace("Test", 1.0);
}
让我们尝试编译它:
[9:34am][wlynch@apple /tmp] /opt/gcc/4.8.2/bin/g++ -std=c++98 foo.cc
foo.cc: In function ‘int main()’:
foo.cc:7:10: error: ‘class std::map<std::basic_string<char>, double>’ has no member named ‘emplace’
maps.emplace("Test", 1.0);
^
[9:34am][wlynch@apple /tmp] /opt/gcc/4.8.2/bin/g++ -std=c++11 foo.cc
[9:34am][wlynch@apple /tmp]
请注意,当我们使用 std = c ++ 11
它可以工作。这是因为 std :: map :: emplace()
是在2011 C ++标准中添加的功能。
Note that when we use -std=c++11
it works. This is because std::map::emplace()
is a feature that was added in the 2011 C++ Standard.
此外,我可以验证:
- g ++ 4.7.3不支持
std :: map :: emplace()
。 - g ++ 4.8.0支持
std :: map :: emplace()
。
- g++ 4.7.3 does not support
std::map::emplace()
. - g++ 4.8.0 does support
std::map::emplace()
.
这篇关于std :: map emplace gcc 4.8.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文