std::set has no member emplace
Asked Answered
G

2

24

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.

Gilstrap answered 4/4, 2013 at 13:13 Comment(0)
I
26

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.

Immobile answered 4/4, 2013 at 13:55 Comment(0)
S
5

emplace() for associative containers was added in libstdc++ for gcc 4.8.0, under gcc 4.7.2 it won't work.

Selfcentered answered 4/4, 2013 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.