From 9f48bb69372d59614327e485960fc0d30edf39cb Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 27 Oct 2018 09:58:23 +0200 Subject: [PATCH] :zap: replaced vector by array #1323 --- include/nlohmann/detail/macro_scope.hpp | 12 ++++++------ single_include/nlohmann/json.hpp | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index 1f0f9bd5..5e42a0e8 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -97,25 +97,25 @@ inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::vector> m = __VA_ARGS__; \ - auto it = std::find_if(m.cbegin(), m.cend(), \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ [e](const std::pair& 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 \ inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::vector> m = __VA_ARGS__; \ - auto it = std::find_if(m.cbegin(), m.cend(), \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ [j](const std::pair& 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 diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 77f9e072..1268ca1d 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -212,25 +212,25 @@ using json = basic_json<>; inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::vector> m = __VA_ARGS__; \ - auto it = std::find_if(m.cbegin(), m.cend(), \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ [e](const std::pair& 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 \ inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ - static const std::vector> m = __VA_ARGS__; \ - auto it = std::find_if(m.cbegin(), m.cend(), \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ [j](const std::pair& 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