From 9b401972a0d5324789e25be2ba6854273d378afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Delrieu?= Date: Thu, 17 Nov 2016 18:15:40 +0100 Subject: [PATCH] add a macro for has_xxx types --- src/json.hpp | 72 +++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 54 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 2265457f..bd91a615 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -140,6 +140,7 @@ template struct conjunction : B1 {}; template struct conjunction : conditional_t, B1> {}; + template struct negation : std::integral_constant {}; template struct disjunction : std::false_type {}; template struct disjunction : B1 {}; @@ -149,68 +150,31 @@ struct disjunction /*! @brief Helper to determine whether there's a key_type for T. - Thus helper is used to tell associative containers apart from other containers such as sequence containers. For instance, `std::map` passes the test as it contains a `mapped_type`, whereas `std::vector` fails the test. - @sa http://stackoverflow.com/a/7728728/266378 @since version 1.0.0, overworked in version 2.0.6 */ -template -struct has_mapped_type -{ - private: - template - static int detect(U&&); +#define NLOHMANN_JSON_HAS_HELPER(type) \ + template struct has_##type { \ + private: \ + template \ + static int detect(U &&); \ + \ + static void detect(...); \ + \ + public: \ + static constexpr bool value = \ + std::is_integral()))>::value; \ + }; - static void detect(...); - public: - static constexpr bool value = - std::is_integral()))>::value; -}; +NLOHMANN_JSON_HAS_HELPER(mapped_type) +NLOHMANN_JSON_HAS_HELPER(key_type) +NLOHMANN_JSON_HAS_HELPER(value_type) +NLOHMANN_JSON_HAS_HELPER(iterator) -template