Is it possible to use the unique_ptr with the map container? For example,
#include<iostream>
#include<string>
#include<map>
#include<memory>
using namespace std;
int main(){
unique_ptr<map<string, int>> person;
person = make_unique<map<string, int>>(make_pair("Tom", 34));
cout << (*person)["Tom"] << endl;
}
person = make_unique<map<string, int>>(map<string, int>{ { "Tom", 34 } });would work, and will use move semantics to make it relatively efficient.unique_ptr<map<string, int>>instead ofmap<string, int>? Moving astd::mapwon't be more expensive than moving aunique_ptr. There are only rare cases whereunique_ptr<map<string, int>>could be usefull.