-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Labels
confirmedsolution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)the issue will not be fixed (either it is impossible or deemed out of scope)state: help neededthe issue needs help to proceedthe issue needs help to proceed
Description
I tried to convert a json object to and from STL map<string, vector<int>>. The "from" direction works well:
map<string, vector<int> > c_map{ { "one", { 1, 2 } }, { "two", { 3, 4 } }, { "three", { 5, 6 } } };
json j_map(c_map);
cout << j_map.dump() << endl;
// Output: {"one":[1,2],"three":[5,6],"two":[3,4]}But the "to" direction gives the following error:
map<string, vector<int> > v2 = j_map;
or
map<string, vector<int> > v2 = j_map.get<map<string, vector<int>>>();
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5
.3.0/bits/stl_pair.h:125:22: error: call to constructor of 'std::vector<int, s
td::allocator<int> >' is ambiguousIs there a way to get around this error?
The library does conversions fine for map<string, int>
map<string, int> c_map{ { "one", 1 }, { "two", 4 }, { "three", 6 } };
json j_map(c_map);
cout << j_map.dump() << endl;
map<string, int > v2 = j_map;I also tried this but did not work either
map<string, vector<int> > v2;
v2["one"] = j_map["one"];
main.cpp:249:13: error: use of overloaded operator '=' is ambiguous (with oper
and types 'mapped_type' (aka 'std::vector<int, std::allocator<int> >') and 'va
lue_type' (aka 'nlohmann::basic_json<std::map, std::vector, std::__cxx11::basi
c_string<char>, bool, long, unsigned long, double, std::allocator>'))This final one works but looks ugly:
map<string, vector<int> > v2;
vector<int> one = j_map["one"];
v2["one"] = one;
vector<int> two = j_map["two"];
v2["two"] = two;Many thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
confirmedsolution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)the issue will not be fixed (either it is impossible or deemed out of scope)state: help neededthe issue needs help to proceedthe issue needs help to proceed