Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::map emplace gcc 4.8.2

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?

like image 934
Thorsten Avatar asked Mar 19 '23 05:03

Thorsten


1 Answers

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:

  • g++ 4.7.3 does not support std::map::emplace().
  • g++ 4.8.0 does support std::map::emplace().
like image 182
Bill Lynch Avatar answered Apr 25 '23 10:04

Bill Lynch