add an enum constructor (quickfix)

This commit is contained in:
Théo DELRIEU 2016-12-07 23:21:10 +01:00 committed by Théo DELRIEU
parent 1eafac7220
commit f5cb089f89

View file

@ -265,27 +265,6 @@ struct is_compatible_integer_type
CompatibleNumberIntegerType>::value; CompatibleNumberIntegerType>::value;
}; };
// quickfix, just trying to make things compile before refactoring
template <bool B, typename RealIntegerType, typename CompatibleEnumType>
struct is_compatible_enum_type_impl : std::false_type {};
template <typename RealIntegerType, typename CompatibleEnumType>
struct is_compatible_enum_type_impl<true, RealIntegerType, CompatibleEnumType>
{
using Underlying = typename std::underlying_type<CompatibleEnumType>::type;
static constexpr auto value =
is_compatible_integer_type<RealIntegerType, Underlying>::value;
};
template <typename RealIntegerType, typename CompatibleEnumType>
struct is_compatible_enum_type
{
static constexpr auto value =
is_compatible_enum_type_impl<std::is_enum<CompatibleEnumType>::value,
RealIntegerType,
CompatibleEnumType>::value;
};
template <typename RealFloat, typename CompatibleFloat> template <typename RealFloat, typename CompatibleFloat>
struct is_compatible_float_type struct is_compatible_float_type
{ {
@ -302,8 +281,6 @@ struct is_compatible_basic_json_type
std::is_constructible<typename BasicJson::string_t, T>::value or std::is_constructible<typename BasicJson::string_t, T>::value or
std::is_same<typename BasicJson::boolean_t, T>::value or std::is_same<typename BasicJson::boolean_t, T>::value or
is_compatible_array_type<BasicJson, T>::value or is_compatible_array_type<BasicJson, T>::value or
is_compatible_enum_type<T, typename BasicJson::number_integer_t>::value or
is_compatible_enum_type<T, typename BasicJson::number_unsigned_t>::value or
is_compatible_object_type<typename BasicJson::object_t, T>::value or is_compatible_object_type<typename BasicJson::object_t, T>::value or
is_compatible_float_type<typename BasicJson::number_float_t, T>::value or is_compatible_float_type<typename BasicJson::number_float_t, T>::value or
is_compatible_integer_type<typename BasicJson::number_integer_t, is_compatible_integer_type<typename BasicJson::number_integer_t,
@ -1624,9 +1601,8 @@ class basic_json
not detail::is_compatible_basic_json_type< not detail::is_compatible_basic_json_type<
uncvref_t<T>, basic_json_t>::value and uncvref_t<T>, basic_json_t>::value and
not detail::is_basic_json_nested_class<uncvref_t<T>, basic_json_t, primitive_iterator_t>::value and not detail::is_basic_json_nested_class<uncvref_t<T>, basic_json_t, primitive_iterator_t>::value and
not std::is_enum<uncvref_t<T>>::value and
not std::is_same<uncvref_t<T>, typename basic_json_t::array_t::iterator>::value and not std::is_same<uncvref_t<T>, typename basic_json_t::array_t::iterator>::value and
not detail::is_compatible_enum_type<number_integer_t, uncvref_t<T>>::value and
not detail::is_compatible_enum_type<number_unsigned_t, uncvref_t<T>>::value and
not std::is_same<uncvref_t<T>, typename basic_json_t::object_t::iterator>::value and not std::is_same<uncvref_t<T>, typename basic_json_t::object_t::iterator>::value and
detail::has_to_json<JSONSerializer, basic_json, detail::has_to_json<JSONSerializer, basic_json,
uncvref_t<T>>::value, uncvref_t<T>>::value,
@ -1797,7 +1773,10 @@ class basic_json
@since version 1.0.0 @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 <typename T, enable_if_t<std::is_enum<T>::value, int> = 0>
basic_json(T val) noexcept
: m_type(value_t::number_integer), : m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(val)) m_value(static_cast<number_integer_t>(val))
{ {
@ -1829,13 +1808,11 @@ class basic_json
@since version 1.0.0 @since version 1.0.0
*/ */
template <typename CompatibleNumberIntegerType, template <
enable_if_t< typename CompatibleNumberIntegerType,
detail::is_compatible_integer_type< enable_if_t<detail::is_compatible_integer_type<
number_integer_t, CompatibleNumberIntegerType>::value or number_integer_t, CompatibleNumberIntegerType>::value,
detail::is_compatible_enum_type< int> = 0>
number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
basic_json(const CompatibleNumberIntegerType val) noexcept basic_json(const CompatibleNumberIntegerType val) noexcept
: m_type(value_t::number_integer), : m_type(value_t::number_integer),
m_value(static_cast<number_integer_t>(val)) { m_value(static_cast<number_integer_t>(val)) {
@ -1890,12 +1867,9 @@ class basic_json
*/ */
template < template <
typename CompatibleNumberUnsignedType, typename CompatibleNumberUnsignedType,
enable_if_t< enable_if_t<detail::is_compatible_integer_type<
detail::is_compatible_integer_type< number_unsigned_t, CompatibleNumberUnsignedType>::value,
number_unsigned_t, CompatibleNumberUnsignedType>::value or int> = 0>
detail::is_compatible_enum_type<
number_integer_t, CompatibleNumberUnsignedType>::value,
int> = 0>
basic_json(const CompatibleNumberUnsignedType val) noexcept basic_json(const CompatibleNumberUnsignedType val) noexcept
: m_type(value_t::number_unsigned), : m_type(value_t::number_unsigned),
m_value(static_cast<number_unsigned_t>(val)) { m_value(static_cast<number_unsigned_t>(val)) {