Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::set has no member emplace

Tags:

Does g++ 4.7.2 implement std::set::emplace, as defined by the C++11 Standard and documented here?

I have written the following little test case:

#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")); } 

Under G++ 4.7.2, this fails to compile:

[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’ 

Also fails to compile under IDEOne, however it does compile under MSVC 2012 Update 1.

like image 212
John Dibling Avatar asked Apr 04 '13 13:04

John Dibling


1 Answers

It is not implemented in gcc 4.7.2.

There is some explanation:

Just to clarify a bit: this wasn't an oversight. We had the nasty problem in the Draft C++0x Standard with std::pair, which essentially made impossible adding the emplace_* members to std::map, std::multimap, etc, without breaking existing user code. Thus we waited on that, until things got clarified in this whole area. Now it's actually possible to work on those facilities.

Your code compiles nicely with gcc 4.8.0, see LWS.

like image 133
Ali Avatar answered Dec 21 '22 03:12

Ali