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)
The following code:
std::map<std::string, double> maps;
maps.emplace("Test", 1.0);
leads to:
class std::map<std::basic_string<char>, double>' has no member named 'emplace'
Can someone clarify in which gcc version the emplace functions are implemented?
Here's some source code:
#include <map>
#include <string>
int main()
{
std::map<std::string, double> maps;
maps.emplace("Test", 1.0);
}
Let's try to compile it:
[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]
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.
Additionally, I can verify that:
std::map::emplace()
.std::map::emplace()
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With