samedi 3 septembre 2016

Adding struct containg not copyable/moveable object to std::map

I have this MCVE:

#include <atomic>
#include <map>

using foo = struct foo
{
    int intValue;
    std::atomic_bool bar;

    foo( int intValue ) : intValue( intValue ) {};
};

std::map<const char *, foo> myMap;

int main()
{
    myMap.emplace( "0",  1234 );
}

It does not compile because std::atomic is neither copyable nor movable.

My question:

How can I add a structure/class containing a not copyable/moveable object to a std::map container?

Aucun commentaire:

Enregistrer un commentaire