replaced vector by array #1323

This commit is contained in:
Niels Lohmann 2018-10-27 09:58:23 +02:00
parent ad639ad5e6
commit 9f48bb6937
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 12 additions and 12 deletions

View file

@ -97,25 +97,25 @@
inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
{ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
static const std::vector<std::pair<ENUM_TYPE, BasicJsonType>> m = __VA_ARGS__; \
auto it = std::find_if(m.cbegin(), m.cend(), \
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
auto it = std::find_if(std::begin(m), std::end(m), \
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
{ \
return ej_pair.first == e; \
}); \
j = ((it != m.cend()) ? it : m.cbegin())->second; \
j = ((it != std::end(m)) ? it : std::begin(m))->second; \
} \
template<typename BasicJsonType> \
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
{ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
static const std::vector<std::pair<ENUM_TYPE, BasicJsonType>> m = __VA_ARGS__; \
auto it = std::find_if(m.cbegin(), m.cend(), \
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
auto it = std::find_if(std::begin(m), std::end(m), \
[j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
{ \
return ej_pair.second == j; \
}); \
e = ((it != m.cend()) ? it : m.cbegin())->first; \
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
}
// Ugly macros to avoid uglier copy-paste when specializing basic_json. They

View file

@ -212,25 +212,25 @@ using json = basic_json<>;
inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
{ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
static const std::vector<std::pair<ENUM_TYPE, BasicJsonType>> m = __VA_ARGS__; \
auto it = std::find_if(m.cbegin(), m.cend(), \
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
auto it = std::find_if(std::begin(m), std::end(m), \
[e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
{ \
return ej_pair.first == e; \
}); \
j = ((it != m.cend()) ? it : m.cbegin())->second; \
j = ((it != std::end(m)) ? it : std::begin(m))->second; \
} \
template<typename BasicJsonType> \
inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
{ \
static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
static const std::vector<std::pair<ENUM_TYPE, BasicJsonType>> m = __VA_ARGS__; \
auto it = std::find_if(m.cbegin(), m.cend(), \
static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
auto it = std::find_if(std::begin(m), std::end(m), \
[j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
{ \
return ej_pair.second == j; \
}); \
e = ((it != m.cend()) ? it : m.cbegin())->first; \
e = ((it != std::end(m)) ? it : std::begin(m))->first; \
}
// Ugly macros to avoid uglier copy-paste when specializing basic_json. They