You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently writing an app, which uses nlohmann::json and xtensor together. xtensor provides a serializer and deserializer functions xt::to_json and xt::from_json, with following prototypes:
The nlohmann::json is basically synonym for nlohmann::basic_json<>, i.e. the basic type with all the specializations set to default. In my app however I need to use the non-default specialization with custom map, which preserves ordering (nlohmann::fifo_map), while the default uses std::map which does not preserve the insertion order.
So what I do in my code is something along this line:
using json = nlohmann::basic_json<nlohmann::fifo_map>
The code is more complex in the reality because of some bugs (nlohmann/json#485), but this is basically the idea. The problem is that this specialization does not compile with xt::to_json and xt::from_json default specialization.
It seems that an easy (and naive) fix could be rewriting the code in xjson.hpp to something along this line:
I tested it on my code and this works fine. What I did not like, was that type J gives no information about its features - it is completely abstract.
So my second attempt was trying to define the type "un-specialized" enough, while still not losing everything, but the nlohmann::basic_json is quite a heavy weight:
I am currently writing an app, which uses
nlohmann::json
andxtensor
together.xtensor
provides a serializer and deserializer functionsxt::to_json
andxt::from_json
, with following prototypes:The
nlohmann::json
is basically synonym fornlohmann::basic_json<>
, i.e. the basic type with all the specializations set to default. In my app however I need to use the non-default specialization with custom map, which preserves ordering (nlohmann::fifo_map
), while the default usesstd::map
which does not preserve the insertion order.So what I do in my code is something along this line:
using json = nlohmann::basic_json<nlohmann::fifo_map>
The code is more complex in the reality because of some bugs (nlohmann/json#485), but this is basically the idea. The problem is that this specialization does not compile with
xt::to_json
andxt::from_json
default specialization.It seems that an easy (and naive) fix could be rewriting the code in
xjson.hpp
to something along this line:I tested it on my code and this works fine. What I did not like, was that type
J
gives no information about its features - it is completely abstract.So my second attempt was trying to define the type "un-specialized" enough, while still not losing everything, but the
nlohmann::basic_json
is quite a heavy weight:and the best thing I could come up with was this:
which still loses all the other (default) template types in the specialization. It does however work with the custom map too.
Now I wonder if anyone knows a better way to tackle it or if some of the aforementioned changes will be acceptable into the library.
The text was updated successfully, but these errors were encountered: