@@ -204,14 +204,14 @@ using enable_if_t = typename std::enable_if<B, T>::type;
204204template <typename T>
205205using uncvref_t = typename std::remove_cv<typename std::remove_reference<T>::type>::type;
206206
207- // Taken from http://stackoverflow.com/questions/26936640/how-to-implement-is-enum-class-type-trait
207+ // taken from http://stackoverflow.com/a/26936864/266378
208208template <typename T>
209209using is_unscoped_enum =
210210 std::integral_constant<bool , std::is_convertible<T, int >::value and
211211 std::is_enum<T>::value>;
212212
213213/*
214- Implementation of 2 C++17 constructs: conjunction, negation. This is needed
214+ Implementation of two C++17 constructs: conjunction, negation. This is needed
215215to avoid evaluating all the traits in a condition
216216
217217For example: not std::is_same<void, T>::value and has_value_type<T>::value
@@ -393,6 +393,7 @@ NLOHMANN_JSON_HAS_HELPER(iterator);
393393
394394#undef NLOHMANN_JSON_HAS_HELPER
395395
396+
396397template <bool B, class RealType , class CompatibleObjectType >
397398struct is_compatible_object_type_impl : std::false_type {};
398399
@@ -468,7 +469,7 @@ struct is_compatible_integer_type
468469};
469470
470471
471- // This trait checks if JSONSerializer<T>::from_json(json const&, udt&) exists
472+ // trait checking if JSONSerializer<T>::from_json(json const&, udt&) exists
472473template <typename BasicJsonType, typename T>
473474struct has_from_json
474475{
@@ -530,8 +531,7 @@ void to_json(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept
530531
531532template <typename BasicJsonType, typename CompatibleString,
532533 enable_if_t <std::is_constructible<typename BasicJsonType::string_t ,
533- CompatibleString>::value,
534- int > = 0 >
534+ CompatibleString>::value, int > = 0 >
535535void to_json (BasicJsonType& j, const CompatibleString& s)
536536{
537537 external_constructor<value_t ::string>::construct (j, s);
@@ -547,8 +547,7 @@ void to_json(BasicJsonType& j, FloatType val) noexcept
547547template <
548548 typename BasicJsonType, typename CompatibleNumberUnsignedType,
549549 enable_if_t <is_compatible_integer_type<typename BasicJsonType::number_unsigned_t ,
550- CompatibleNumberUnsignedType>::value,
551- int > = 0 >
550+ CompatibleNumberUnsignedType>::value, int > = 0 >
552551void to_json (BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
553552{
554553 external_constructor<value_t ::number_unsigned>::construct (j, static_cast <typename BasicJsonType::number_unsigned_t >(val));
@@ -557,8 +556,7 @@ void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
557556template <
558557 typename BasicJsonType, typename CompatibleNumberIntegerType,
559558 enable_if_t <is_compatible_integer_type<typename BasicJsonType::number_integer_t ,
560- CompatibleNumberIntegerType>::value,
561- int > = 0 >
559+ CompatibleNumberIntegerType>::value, int > = 0 >
562560void to_json (BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
563561{
564562 external_constructor<value_t ::number_integer>::construct (j, static_cast <typename BasicJsonType::number_integer_t >(val));
@@ -690,7 +688,6 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::array_t& arr)
690688}
691689
692690// forward_list doesn't have an insert method
693- // TODO find a way to avoid including forward_list
694691template <typename BasicJsonType, typename T, typename Allocator>
695692void from_json (const BasicJsonType& j, std::forward_list<T, Allocator>& l)
696693{
@@ -781,14 +778,15 @@ void from_json(const BasicJsonType& j, CompatibleObjectType& obj)
781778 using std::begin;
782779 using std::end;
783780 // we could avoid the assignment, but this might require a for loop, which
784- // might be less efficient than the container constructor for some containers (would it?)
781+ // might be less efficient than the container constructor for some
782+ // containers (would it?)
785783 obj = CompatibleObjectType (begin (*inner_object), end (*inner_object));
786784}
787785
788- // overload for arithmetic types, not chosen for basic_json template arguments (BooleanType, etc..)
789- //
790- // note: Is it really necessary to provide explicit overloads for boolean_t etc..
791- // in case of a custom BooleanType which is not an arithmetic type?
786+ // overload for arithmetic types, not chosen for basic_json template arguments
787+ // (BooleanType, etc..); note: Is it really necessary to provide explicit
788+ // overloads for boolean_t etc. in case of a custom BooleanType which is not
789+ // an arithmetic type?
792790template <typename BasicJsonType, typename ArithmeticType,
793791 enable_if_t <
794792 std::is_arithmetic<ArithmeticType>::value and
@@ -802,19 +800,29 @@ void from_json(const BasicJsonType& j, ArithmeticType& val)
802800 switch (static_cast <value_t >(j))
803801 {
804802 case value_t ::number_unsigned:
803+ {
805804 val = static_cast <ArithmeticType>(*j.template get_ptr <const typename BasicJsonType::number_unsigned_t *>());
806805 break ;
806+ }
807807 case value_t ::number_integer:
808+ {
808809 val = static_cast <ArithmeticType>(*j.template get_ptr <const typename BasicJsonType::number_integer_t *>());
809810 break ;
811+ }
810812 case value_t ::number_float:
813+ {
811814 val = static_cast <ArithmeticType>(*j.template get_ptr <const typename BasicJsonType::number_float_t *>());
812815 break ;
816+ }
813817 case value_t ::boolean:
818+ {
814819 val = static_cast <ArithmeticType>(*j.template get_ptr <const typename BasicJsonType::boolean_t *>());
815820 break ;
821+ }
816822 default :
823+ {
817824 JSON_THROW (std::domain_error (" type must be number, but is " + j.type_name ()));
825+ }
818826 }
819827}
820828
@@ -3160,8 +3168,7 @@ class basic_json
31603168 detail::enable_if_t <
31613169 not std::is_same<basic_json_t , U>::value and
31623170 detail::has_from_json<basic_json_t , U>::value and
3163- not detail::has_non_default_from_json<basic_json_t ,
3164- U>::value,
3171+ not detail::has_non_default_from_json<basic_json_t , U>::value,
31653172 int > = 0 >
31663173 U get () const noexcept (noexcept (JSONSerializer<U>::from_json(
31673174 std::declval<const basic_json_t &>(), std::declval<U&>())))
@@ -3196,8 +3203,7 @@ class basic_json
31963203 typename U = detail::uncvref_t <T>,
31973204 detail::enable_if_t <not std::is_same<basic_json_t , U>::value and
31983205 detail::has_non_default_from_json<basic_json_t ,
3199- U>::value,
3200- int > = 0 >
3206+ U>::value, int > = 0 >
32013207 U get () const noexcept (noexcept (JSONSerializer<T>::from_json(std::declval<const basic_json_t &>())))
32023208 {
32033209 static_assert (not std::is_reference<T>::value, " get cannot be used with reference types, you might want to use get_ref" );
0 commit comments