3 #define WMTK_NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
4 void to_json(nlohmann::json& j, const ENUM_TYPE& e) \
6 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
7 static const std::pair<ENUM_TYPE, nlohmann::json> m[] = __VA_ARGS__; \
8 auto it = std::find_if(std::begin(m), std::end(m), \
9 [e](const std::pair<ENUM_TYPE, nlohmann::json>& ej_pair) -> bool \
11 return ej_pair.first == e; \
13 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
15 void from_json(const nlohmann::json& j, ENUM_TYPE& e) \
17 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
18 static const std::pair<ENUM_TYPE, nlohmann::json> m[] = __VA_ARGS__; \
19 auto it = std::find_if(std::begin(m), std::end(m), \
20 [&j](const std::pair<ENUM_TYPE, nlohmann::json>& ej_pair) -> bool \
22 return ej_pair.second == j; \
24 e = ((it != std::end(m)) ? it : std::begin(m))->first; \