13

I try to use emplace() function for an unordered_map and compiler says that no such function exists.

I put -std=c+11 and it says cc1plus.exe: error: unrecognized command line option '-std=c+11'

Can i somehow use C++11 functionality with mingw?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
pdrak
  • 404
  • 1
  • 4
  • 12

1 Answers1

14

From the GCC documentation

C++0x was the working name of a new ISO C++ standard, which was then released in 2011 as C++11 and introduces a host of new features into the standard C++ language and library. This project seeks to implement new C++11 features in GCC and to make it one of the first compilers to bring C++11 to C++ programmers.

C++11 features are available as part of the "mainline" GCC compiler in the trunk of GCC's Subversion repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.

So, for gcc 4.3 through 4.6 use -std=c++0x, for later version use -std=c++11. Library support for map::emplace was added in gcc 4.8

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
  • same error: 'class std::unordered_map, dictionaryWord>' has no member named 'emplace' – pdrak Apr 22 '13 at 13:40
  • I have come to believe that i can not use c++ 11, or at least all of it, with 4.6. – pdrak Apr 22 '13 at 13:47
  • 1
    You will need gcc 4.8 to use `map::emplace`, see e.g. [this question](http://stackoverflow.com/questions/14075128/mapemplace-with-a-custom-value-type) – TemplateRex Apr 22 '13 at 14:45
  • The project i try to compile for windows, was made in Linux Gcc 4.7.2 a month ago. There is emplace() in linux gcc 4.7.2 – pdrak Apr 22 '13 at 18:19
  • @PetrosDrakoulis That's surprising because the [gcc 4.7.2 docs](http://gcc.gnu.org/onlinedocs/gcc-4.7.2/libstdc++/manual/manual/status.html#status.iso.2011) says that `emplace` is missing for `map`. See also http://ideone.com/dqScM9 Safe bet is to install MinGW 4.8, e.g. from http://nuwen.net/mingw.html – TemplateRex Apr 22 '13 at 18:57
  • Thank you. I will try to do so. But i guarantee you that in Linux gcc 4.7.2 with flag -std=c+11 there is emplace() for unordered_map. I participated in a contest 2 weeks ago and with the compiler being 4.7.2 i used it. It's the very program i try to recompile for windows... – pdrak Apr 22 '13 at 19:28