diff --git a/include/json.hpp b/include/json.hpp index bed68c3..09ed07b 100644 --- a/include/json.hpp +++ b/include/json.hpp @@ -96,10 +96,15 @@ class basic_value template basic_value(value_type type, args_t&&... args); - // Prohibit conversion of other types to basic_value - template + template >>> basic_value(value_t) = delete; + // I don't know if you want to convert char to string or number, so I delete these constructors. + basic_value(char) = delete; + basic_value(wchar_t) = delete; + basic_value(char16_t) = delete; + basic_value(char32_t) = delete; + ~basic_value(); bool valid() const noexcept { return _type != value_type::invalid; } @@ -261,19 +266,18 @@ class basic_array basic_array() = default; basic_array(const basic_array& rhs) = default; basic_array(basic_array&& rhs) noexcept = default; - basic_array(const raw_array& arr); - basic_array(raw_array&& arr) noexcept; basic_array(std::initializer_list init_list); basic_array(typename raw_array::size_type size); explicit basic_array(const basic_value& val); explicit basic_array(basic_value&& val); - template ::value_type>>> - basic_array(array_t arr) - { - _array_data.assign(std::make_move_iterator(arr.begin()), std::make_move_iterator(arr.end())); - } + + template ::value_type>>> + basic_array(collection_t arr) + : _array_data(std::make_move_iterator(arr.begin()), std::make_move_iterator(arr.end())) + {} ~basic_array() noexcept = default; @@ -377,17 +381,13 @@ class basic_object basic_object() = default; basic_object(const basic_object& rhs) = default; basic_object(basic_object&& rhs) noexcept = default; - basic_object(const raw_object& raw_obj); - basic_object(raw_object&& raw_obj); basic_object(std::initializer_list init_list); explicit basic_object(const basic_value& val); explicit basic_object(basic_value&& val); - template ::value_type>>> - basic_object(map_t map) - { - _object_data.insert(std::make_move_iterator(map.begin()), std::make_move_iterator(map.end())); - } + template ::value_type>>> + basic_object(map_t map) : _object_data(std::make_move_iterator(map.begin()), std::make_move_iterator(map.end())) + {} ~basic_object() = default; @@ -1332,18 +1332,6 @@ MEOJSON_INLINE typename basic_value::var_t basic_value::deep // * basic_array impl * // ****************************** -template -MEOJSON_INLINE basic_array::basic_array(const raw_array& arr) : _array_data(arr) -{ - ; -} - -template -MEOJSON_INLINE basic_array::basic_array(raw_array&& arr) noexcept : _array_data(std::move(arr)) -{ - ; -} - template MEOJSON_INLINE basic_array::basic_array(std::initializer_list init_list) : _array_data(init_list) { @@ -1653,24 +1641,11 @@ MEOJSON_INLINE bool basic_array::operator==(const basic_array -MEOJSON_INLINE basic_object::basic_object(const raw_object& raw_obj) : _object_data(raw_obj) -{ - ; -} - -template -MEOJSON_INLINE basic_object::basic_object(raw_object&& raw_obj) : _object_data(std::move(raw_obj)) -{ - ; -} - template MEOJSON_INLINE basic_object::basic_object(std::initializer_list init_list) + : _object_data(std::make_move_iterator(init_list.begin()), std::make_move_iterator(init_list.end())) { - for (const auto& [key, val] : init_list) { - emplace(key, val); - } + ; } template @@ -2565,21 +2540,19 @@ namespace _serialization_helper template constexpr bool is_container = false; template - constexpr bool is_container< - T, void_t().begin()), decltype(std::declval().end())>> = - true; + constexpr bool is_container::value_type>> = + std::is_same_v::value_type>; - // something like a map template - constexpr bool is_associative_container = false; + constexpr bool is_map = false; template - constexpr bool is_associative_container> = is_container; + constexpr bool is_map> = is_container; - // something like a vector template - constexpr bool is_sequence_container = false; + constexpr bool is_collection = false; template - constexpr bool is_sequence_container = is_container && !is_associative_container; + constexpr bool is_collection = is_container && !is_map; template struct string_converter @@ -2615,12 +2588,14 @@ namespace _serialization_helper void unable_to_serialize() { static_assert(!sizeof(T), "Unable to serialize T. " - "You can define the conversion of T to json, or overload operator<< for it."); + "You can define the conversion of T to json, or overload operator<< for it. " #ifdef _MSC_VER - static_assert(!sizeof(T), "See T below: " __FUNCSIG__); + "See T below: " __FUNCSIG__ #else - // static_assert(!sizeof(T), "See T below: " __PRETTY_FUNCTION__); + //"See T below: " __PRETTY_FUNCTION__ + #endif + ); } } // namespace _serialization_helper @@ -2641,7 +2616,7 @@ MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& else if constexpr (std::decay_t::template is_convertible) { return string_converter(std::forward(arg)); } - else if constexpr (is_sequence_container>) { + else if constexpr (is_collection>) { basic_value result; for (auto&& val : arg) { using value_t = decltype(val); @@ -2651,7 +2626,7 @@ MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& } return result; } - else if constexpr (is_associative_container>) { + else if constexpr (is_map>) { basic_value result; for (auto&& [key, val] : arg) { using key_t = decltype(key);