Replies: 1 comment 5 replies
-
What do you mean by "X-macros"? |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The documentation gives this example of how to serialize an enum with the library.
Unfortunately this macro does not work with X-macros, because you cannot
#include
within a macro argument list. It would be great to have three additional macros that can be used like this:The intent is that I can then write this code:
This does not work with the existing macro because you cannot
#include
within a macro argument list.I looked at the implementation of
NLOHMANN_JSON_SERIALIZE_ENUM
and it does not seem trivial to add the proposed macros, because the argument list__VA_ARGS__
is used twice, once into_json()
and once infrom_json()
. However in both functions it is used identically to create a static array that maps the enum values to JSON objects.Perhaps one way one implement the macros could be to add a class template
enum_serializer
to thenlohmann
namespace that stores the static mapping array. The macros then specialize this template and thefrom_json
andto_json
functions could be generic templates that SFINAE out ifenum_serializer<enum-type>
is not defined. This also would mean that the static array would only be stored once.What do you think of this idea? If it seems worthwhile I could get around to implement it the next days.
Beta Was this translation helpful? Give feedback.
All reactions