-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Labels
kind: bugsolution: 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: please discussplease discuss the issue or vote for your favorite optionplease discuss the issue or vote for your favorite option
Description
Even if #161 isn't fixed, the dump() method still assumes the default allocator is used. Consider the following code:
nlohmann::basic_json<std::map, std::vector, StringWithMyAllocator, bool, int64_t, uint64_t, double, MyAllocator> j;
// add a string that is stored as std::string
j["name"] = "Niels";
// explicit conversion to string
StringWithMyAllocator s = j.dump(); // {\"happy\":true,\"pi\":3.141}This results in a compiler error:
'return': cannot convert from 'std::basic_string<char,std::char_traits,std::allocator>' to 'std::basic_string<char,std::char_traits,MyAllocator>'
The issue is due to the stringstream that is used without specifying the allocator for the stream. As a result, dump fails to compile due to the call to ss.str().
string_t dump(const int indent = -1) const
{
std::stringstream ss;
if (indent >= 0)
{
dump(ss, true, static_cast<unsigned int>(indent));
}
else
{
dump(ss, false, 0);
}
return ss.str();
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind: bugsolution: 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: please discussplease discuss the issue or vote for your favorite optionplease discuss the issue or vote for your favorite option