nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
43.26k stars 6.74k forks source link

Add more flexibility to basic_json's ObjectType (and ArrayType) #2013

Closed 1410rlH closed 4 years ago

1410rlH commented 4 years ago

Custom ObjectTypes are in hard limits:

basic_json<> // ok
basic_json<std::map> // ok (the same)
template<class Key, class Value, class Comp, class Alloc> 
my_stl_like_map {};
basic_json<my_stl_like_map> // ok (the same)

basic_json<std::unordered_map> // Won't compile (hash != comparator)

template<class Key, class Value> 
MyMap {};
basic_json<MyMap> // Won't compile (too few templates)

I suggest changing the following line with some metaprogramming or using only Key and Value:

    using object_t = ObjectType<StringType,
          basic_json,
/* Maybe leave those below as default (won't allow custom allocators :( ) */
          object_comparator_t,
          AllocatorType<std::pair<const StringType,
          basic_json>>>;
nlohmann commented 4 years ago

Though this adds flexibility, it would also remove flexibility for custom allocators and custom comparators, right?

1410rlH commented 4 years ago

Yea, kinda. But otherwise those templates are useless.

On Tue, Mar 31, 2020, 13:53 Niels Lohmann notifications@github.com wrote:

Though this adds flexibility, it would also remove flexibility for custom allocators and custom comparators, right?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nlohmann/json/issues/2013#issuecomment-606551502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOOWHVQ2OEFT2NYXRTJLN6DRKHDULANCNFSM4LUJ342A .

nlohmann commented 4 years ago

As this would break the API, I cannot introduce the change without more benefits. Sorry.