我有这个 MCVE:
#include <atomic>
#include <map>
#include <string>
struct foo
{
int intValue;
std::atomic_bool bar;
foo( int intValue ) : intValue( intValue ) {};
};
std::map<std::string, foo> myMap;
int main()
{
myMap.emplace( "0", 1234 );
}
它无法编译,因为 std::atomic
既不可复制也不可移动。
我的问题:
如何将包含不可复制/可移动对象的类添加到 std::map
容器?
最佳答案
怎么样
myMap.emplace(std::piecewise_construct,
std::forward_as_tuple("0"),
std::forward_as_tuple(1234));
?
关于c++ - 将包含不可复制/可移动对象的结构添加到 std::map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39312515/