From f5cb089f8927167ae934d510c752bce581e8f62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Wed, 7 Dec 2016 23:21:10 +0100 Subject: [PATCH] add an enum constructor (quickfix) --- src/json.hpp | 52 +++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 310779ea..35d3d0a6 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -265,27 +265,6 @@ struct is_compatible_integer_type CompatibleNumberIntegerType>::value; }; -// quickfix, just trying to make things compile before refactoring -template -struct is_compatible_enum_type_impl : std::false_type {}; - -template -struct is_compatible_enum_type_impl -{ - using Underlying = typename std::underlying_type::type; - static constexpr auto value = - is_compatible_integer_type::value; -}; - -template -struct is_compatible_enum_type -{ - static constexpr auto value = - is_compatible_enum_type_impl::value, - RealIntegerType, - CompatibleEnumType>::value; -}; - template struct is_compatible_float_type { @@ -302,8 +281,6 @@ struct is_compatible_basic_json_type std::is_constructible::value or std::is_same::value or is_compatible_array_type::value or - is_compatible_enum_type::value or - is_compatible_enum_type::value or is_compatible_object_type::value or is_compatible_float_type::value or is_compatible_integer_type, basic_json_t>::value and not detail::is_basic_json_nested_class, basic_json_t, primitive_iterator_t>::value and + not std::is_enum>::value and not std::is_same, typename basic_json_t::array_t::iterator>::value and - not detail::is_compatible_enum_type>::value and - not detail::is_compatible_enum_type>::value and not std::is_same, typename basic_json_t::object_t::iterator>::value and detail::has_to_json>::value, @@ -1797,7 +1773,10 @@ class basic_json @since version 1.0.0 */ - basic_json(const int val) noexcept + + // Quickfix, accept every enum type, without looking if a to_json method is provided... + template ::value, int> = 0> + basic_json(T val) noexcept : m_type(value_t::number_integer), m_value(static_cast(val)) { @@ -1829,13 +1808,11 @@ class basic_json @since version 1.0.0 */ - template ::value or - detail::is_compatible_enum_type< - number_integer_t, CompatibleNumberIntegerType>::value, - int> = 0> + template < + typename CompatibleNumberIntegerType, + enable_if_t::value, + int> = 0> basic_json(const CompatibleNumberIntegerType val) noexcept : m_type(value_t::number_integer), m_value(static_cast(val)) { @@ -1890,12 +1867,9 @@ class basic_json */ template < typename CompatibleNumberUnsignedType, - enable_if_t< - detail::is_compatible_integer_type< - number_unsigned_t, CompatibleNumberUnsignedType>::value or - detail::is_compatible_enum_type< - number_integer_t, CompatibleNumberUnsignedType>::value, - int> = 0> + enable_if_t::value, + int> = 0> basic_json(const CompatibleNumberUnsignedType val) noexcept : m_type(value_t::number_unsigned), m_value(static_cast(val)) {