diff --git a/include/json.hpp b/include/json.hpp index 25172ae..f146457 100644 --- a/include/json.hpp +++ b/include/json.hpp @@ -14,21 +14,8 @@ #include "packed_bytes.hpp" -#define MEOJSON_INLINE inline - namespace json { -namespace utils -{ - template - using iterator_t = decltype(std::declval().begin()); - template - using remove_cvref_t = std::remove_cv_t>; - template - using iter_value_t = typename std::iterator_traits>::value_type; - template - using range_value_t = iter_value_t>; -} template class basic_value; template @@ -46,6 +33,18 @@ using wvalue = basic_value; using warray = basic_array; using wobject = basic_object; +namespace utils +{ + template + using iterator_t = decltype(std::declval().begin()); + template + using remove_cvref_t = std::remove_cv_t>; + template + using iter_value_t = typename std::iterator_traits>::value_type; + template + using range_value_t = iter_value_t>; +} + // ********************************* // * basic_value declare * // ********************************* @@ -615,7 +614,7 @@ static constexpr string_t null_string() } template -inline string_t to_template_string(any_t&& arg) +string_t to_basic_string(any_t&& arg) { if constexpr (std::is_same_v) { return std::to_string(std::forward(arg)); @@ -632,98 +631,96 @@ template static constexpr string_t unescape_string(const string_t& str); template -MEOJSON_INLINE basic_value::basic_value() = default; +inline basic_value::basic_value() = default; template -MEOJSON_INLINE basic_value::basic_value(const basic_value& rhs) +inline basic_value::basic_value(const basic_value& rhs) : _type(rhs._type), _raw_data(deep_copy(rhs._raw_data)) {} template -MEOJSON_INLINE basic_value::basic_value(basic_value&& rhs) noexcept = default; +inline basic_value::basic_value(basic_value&& rhs) noexcept = default; template -MEOJSON_INLINE basic_value::basic_value(bool b) +inline basic_value::basic_value(bool b) : _type(value_type::boolean), _raw_data(string_t(b ? true_string() : false_string())) {} template -MEOJSON_INLINE basic_value::basic_value(int num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(int num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(unsigned num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(unsigned num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(long num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(long num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(unsigned long num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(unsigned long num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(long long num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(long long num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(unsigned long long num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(unsigned long long num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(float num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(float num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(double num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(double num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(long double num) - : _type(value_type::number), _raw_data(to_template_string(num)) +inline basic_value::basic_value(long double num) + : _type(value_type::number), _raw_data(to_basic_string(num)) {} template -MEOJSON_INLINE basic_value::basic_value(const char_t* str) - : _type(value_type::string), _raw_data(string_t(str)) +inline basic_value::basic_value(const char_t* str) : _type(value_type::string), _raw_data(string_t(str)) {} template -MEOJSON_INLINE basic_value::basic_value(string_t str) : _type(value_type::string), _raw_data(std::move(str)) +inline basic_value::basic_value(string_t str) : _type(value_type::string), _raw_data(std::move(str)) {} template -MEOJSON_INLINE basic_value::basic_value(basic_array arr) +inline basic_value::basic_value(basic_array arr) : _type(value_type::array), _raw_data(std::make_unique>(std::move(arr))) {} template -MEOJSON_INLINE basic_value::basic_value(basic_object obj) +inline basic_value::basic_value(basic_object obj) : _type(value_type::object), _raw_data(std::make_unique>(std::move(obj))) {} template -MEOJSON_INLINE basic_value::basic_value( - std::initializer_list::value_type> init_list) +inline basic_value::basic_value(std::initializer_list::value_type> init_list) : _type(value_type::object), _raw_data(std::make_unique>(init_list)) {} // for Pimpl template -MEOJSON_INLINE basic_value::~basic_value() = default; +inline basic_value::~basic_value() = default; template template -MEOJSON_INLINE bool basic_value::is() const noexcept +inline bool basic_value::is() const noexcept { if constexpr (std::is_same_v, value_t>) { return true; @@ -749,44 +746,44 @@ MEOJSON_INLINE bool basic_value::is() const noexcept } template -MEOJSON_INLINE bool basic_value::contains(const string_t& key) const +inline bool basic_value::contains(const string_t& key) const { return is_object() && as_object().contains(key); } template -MEOJSON_INLINE bool basic_value::contains(size_t pos) const +inline bool basic_value::contains(size_t pos) const { return is_array() && as_array().contains(pos); } template -MEOJSON_INLINE const basic_value& basic_value::at(size_t pos) const +inline const basic_value& basic_value::at(size_t pos) const { return as_array().at(pos); } template -MEOJSON_INLINE const basic_value& basic_value::at(const string_t& key) const +inline const basic_value& basic_value::at(const string_t& key) const { return as_object().at(key); } template -MEOJSON_INLINE bool basic_value::erase(size_t pos) +inline bool basic_value::erase(size_t pos) { return as_array().erase(pos); } template -MEOJSON_INLINE bool basic_value::erase(const string_t& key) +inline bool basic_value::erase(const string_t& key) { return as_object().erase(key); } template template -MEOJSON_INLINE auto basic_value::get(key_then_default_value_t&&... keys_then_default_value) const +inline auto basic_value::get(key_then_default_value_t&&... keys_then_default_value) const { return get(std::forward_as_tuple(keys_then_default_value...), std::make_index_sequence {}); @@ -794,8 +791,8 @@ MEOJSON_INLINE auto basic_value::get(key_then_default_value_t&&... key template template -MEOJSON_INLINE auto basic_value::get(std::tuple keys_then_default_value, - std::index_sequence) const +inline auto basic_value::get(std::tuple keys_then_default_value, + std::index_sequence) const { constexpr unsigned long default_value_index = sizeof...(key_then_default_value_t) - 1; return get_helper(std::get(keys_then_default_value), @@ -804,8 +801,8 @@ MEOJSON_INLINE auto basic_value::get(std::tuple template -MEOJSON_INLINE auto basic_value::get_helper(const value_t& default_value, first_key_t&& first, - rest_keys_t&&... rest) const +inline auto basic_value::get_helper(const value_t& default_value, first_key_t&& first, + rest_keys_t&&... rest) const { if constexpr (std::is_constructible_v) { return is_object() ? as_object().get_helper(default_value, std::forward(first), @@ -824,7 +821,7 @@ MEOJSON_INLINE auto basic_value::get_helper(const value_t& default_val template template -MEOJSON_INLINE auto basic_value::get_helper(const value_t& default_value, unique_key_t&& first) const +inline auto basic_value::get_helper(const value_t& default_value, unique_key_t&& first) const { if constexpr (std::is_constructible_v) { return is_object() ? as_object().get_helper(default_value, std::forward(first)) : default_value; @@ -839,7 +836,7 @@ MEOJSON_INLINE auto basic_value::get_helper(const value_t& default_val template template -MEOJSON_INLINE auto basic_array::get(key_then_default_value_t&&... keys_then_default_value) const +inline auto basic_array::get(key_then_default_value_t&&... keys_then_default_value) const { return get(std::forward_as_tuple(keys_then_default_value...), std::make_index_sequence {}); @@ -847,8 +844,8 @@ MEOJSON_INLINE auto basic_array::get(key_then_default_value_t&&... key template template -MEOJSON_INLINE auto basic_array::get(std::tuple keys_then_default_value, - std::index_sequence) const +inline auto basic_array::get(std::tuple keys_then_default_value, + std::index_sequence) const { constexpr unsigned long default_value_index = sizeof...(key_then_default_value_t) - 1; return get_helper(std::get(keys_then_default_value), @@ -857,7 +854,7 @@ MEOJSON_INLINE auto basic_array::get(std::tuple template -MEOJSON_INLINE auto basic_object::get(key_then_default_value_t&&... keys_then_default_value) const +inline auto basic_object::get(key_then_default_value_t&&... keys_then_default_value) const { return get(std::forward_as_tuple(keys_then_default_value...), std::make_index_sequence {}); @@ -865,8 +862,8 @@ MEOJSON_INLINE auto basic_object::get(key_then_default_value_t&&... ke template template -MEOJSON_INLINE auto basic_object::get(std::tuple keys_then_default_value, - std::index_sequence) const +inline auto basic_object::get(std::tuple keys_then_default_value, + std::index_sequence) const { constexpr unsigned long default_value_index = sizeof...(key_then_default_value_t) - 1; return get_helper(std::get(keys_then_default_value), @@ -875,20 +872,20 @@ MEOJSON_INLINE auto basic_object::get(std::tuple template -MEOJSON_INLINE std::optional basic_value::find(size_t pos) const +inline std::optional basic_value::find(size_t pos) const { return is_array() ? as_array().template find(pos) : std::nullopt; } template template -MEOJSON_INLINE std::optional basic_value::find(const string_t& key) const +inline std::optional basic_value::find(const string_t& key) const { return is_object() ? as_object().template find(key) : std::nullopt; } template -MEOJSON_INLINE bool basic_value::as_boolean() const +inline bool basic_value::as_boolean() const { if (is_boolean()) { if (const string_t& b_str = as_basic_type_str(); b_str == true_string()) { @@ -907,7 +904,7 @@ MEOJSON_INLINE bool basic_value::as_boolean() const } template -MEOJSON_INLINE int basic_value::as_integer() const +inline int basic_value::as_integer() const { if (is_number()) { return std::stoi(as_basic_type_str()); @@ -918,14 +915,14 @@ MEOJSON_INLINE int basic_value::as_integer() const } template -MEOJSON_INLINE unsigned basic_value::as_unsigned() const +inline unsigned basic_value::as_unsigned() const { // I don't know why there is no std::stou. return static_cast(as_unsigned_long()); } template -MEOJSON_INLINE long basic_value::as_long() const +inline long basic_value::as_long() const { if (is_number()) { return std::stol(as_basic_type_str()); @@ -936,7 +933,7 @@ MEOJSON_INLINE long basic_value::as_long() const } template -MEOJSON_INLINE unsigned long basic_value::as_unsigned_long() const +inline unsigned long basic_value::as_unsigned_long() const { if (is_number()) { return std::stoul(as_basic_type_str()); @@ -947,7 +944,7 @@ MEOJSON_INLINE unsigned long basic_value::as_unsigned_long() const } template -MEOJSON_INLINE long long basic_value::as_long_long() const +inline long long basic_value::as_long_long() const { if (is_number()) { return std::stoll(as_basic_type_str()); @@ -958,7 +955,7 @@ MEOJSON_INLINE long long basic_value::as_long_long() const } template -MEOJSON_INLINE unsigned long long basic_value::as_unsigned_long_long() const +inline unsigned long long basic_value::as_unsigned_long_long() const { if (is_number()) { return std::stoull(as_basic_type_str()); @@ -969,7 +966,7 @@ MEOJSON_INLINE unsigned long long basic_value::as_unsigned_long_long() } template -MEOJSON_INLINE float basic_value::as_float() const +inline float basic_value::as_float() const { if (is_number()) { return std::stof(as_basic_type_str()); @@ -980,7 +977,7 @@ MEOJSON_INLINE float basic_value::as_float() const } template -MEOJSON_INLINE double basic_value::as_double() const +inline double basic_value::as_double() const { if (is_number()) { return std::stod(as_basic_type_str()); @@ -991,7 +988,7 @@ MEOJSON_INLINE double basic_value::as_double() const } template -MEOJSON_INLINE long double basic_value::as_long_double() const +inline long double basic_value::as_long_double() const { if (is_number()) { return std::stold(as_basic_type_str()); @@ -1002,7 +999,7 @@ MEOJSON_INLINE long double basic_value::as_long_double() const } template -MEOJSON_INLINE string_t basic_value::as_string() const +inline string_t basic_value::as_string() const { if (is_string()) { return as_basic_type_str(); @@ -1013,7 +1010,7 @@ MEOJSON_INLINE string_t basic_value::as_string() const } template -MEOJSON_INLINE const basic_array& basic_value::as_array() const +inline const basic_array& basic_value::as_array() const { if (is_array()) { return *std::get(_raw_data); @@ -1023,7 +1020,7 @@ MEOJSON_INLINE const basic_array& basic_value::as_array() co } template -MEOJSON_INLINE const basic_object& basic_value::as_object() const +inline const basic_object& basic_value::as_object() const { if (is_object()) { return *std::get(_raw_data); @@ -1033,7 +1030,7 @@ MEOJSON_INLINE const basic_object& basic_value::as_object() } template -MEOJSON_INLINE basic_array& basic_value::as_array() +inline basic_array& basic_value::as_array() { if (empty()) { *this = basic_array(); @@ -1047,7 +1044,7 @@ MEOJSON_INLINE basic_array& basic_value::as_array() } template -MEOJSON_INLINE basic_object& basic_value::as_object() +inline basic_object& basic_value::as_object() { if (empty()) { *this = basic_object(); @@ -1062,26 +1059,26 @@ MEOJSON_INLINE basic_object& basic_value::as_object() template template -MEOJSON_INLINE value_t basic_value::as() const +inline value_t basic_value::as() const { return static_cast(*this); } template -MEOJSON_INLINE const string_t& basic_value::as_basic_type_str() const +inline const string_t& basic_value::as_basic_type_str() const { return std::get(_raw_data); } template -MEOJSON_INLINE string_t& basic_value::as_basic_type_str() +inline string_t& basic_value::as_basic_type_str() { return std::get(_raw_data); } template template -MEOJSON_INLINE decltype(auto) basic_value::emplace(args_t&&... args) +inline decltype(auto) basic_value::emplace(args_t&&... args) { constexpr bool is_array_args = std::is_constructible_v::value_type, args_t...>; constexpr bool is_object_args = std::is_constructible_v::value_type, args_t...>; @@ -1098,26 +1095,26 @@ MEOJSON_INLINE decltype(auto) basic_value::emplace(args_t&&... args) template template -MEOJSON_INLINE decltype(auto) basic_value::array_emplace(args_t&&... args) +inline decltype(auto) basic_value::array_emplace(args_t&&... args) { return emplace(std::forward(args)...); } template template -MEOJSON_INLINE decltype(auto) basic_value::object_emplace(args_t&&... args) +inline decltype(auto) basic_value::object_emplace(args_t&&... args) { return emplace(std::forward(args)...); } template -MEOJSON_INLINE void basic_value::clear() noexcept +inline void basic_value::clear() noexcept { *this = basic_value(); } template -MEOJSON_INLINE string_t basic_value::to_string() const +inline string_t basic_value::to_string() const { switch (_type) { case value_type::null: @@ -1137,7 +1134,7 @@ MEOJSON_INLINE string_t basic_value::to_string() const } template -MEOJSON_INLINE string_t basic_value::format(size_t indent, size_t indent_times) const +inline string_t basic_value::format(size_t indent, size_t indent_times) const { switch (_type) { case value_type::null: @@ -1156,20 +1153,20 @@ MEOJSON_INLINE string_t basic_value::format(size_t indent, size_t inde template template -MEOJSON_INLINE std::vector basic_value::to_vector() const +inline std::vector basic_value::to_vector() const { return as_array().template to_vector(); } template template -MEOJSON_INLINE std::map basic_value::to_map() const +inline std::map basic_value::to_map() const { return as_object().template to_map(); } template -MEOJSON_INLINE basic_value& basic_value::operator=(const basic_value& rhs) +inline basic_value& basic_value::operator=(const basic_value& rhs) { _type = rhs._type; _raw_data = deep_copy(rhs._raw_data); @@ -1178,10 +1175,10 @@ MEOJSON_INLINE basic_value& basic_value::operator=(const bas } template -MEOJSON_INLINE basic_value& basic_value::operator=(basic_value&& rhs) noexcept = default; +inline basic_value& basic_value::operator=(basic_value&& rhs) noexcept = default; template -MEOJSON_INLINE bool basic_value::operator==(const basic_value& rhs) const +inline bool basic_value::operator==(const basic_value& rhs) const { if (_type != rhs._type) return false; @@ -1202,7 +1199,7 @@ MEOJSON_INLINE bool basic_value::operator==(const basic_value -MEOJSON_INLINE const basic_value& basic_value::operator[](size_t pos) const +inline const basic_value& basic_value::operator[](size_t pos) const { // basic_array not support to create by operator[] @@ -1210,7 +1207,7 @@ MEOJSON_INLINE const basic_value& basic_value::operator[](si } template -MEOJSON_INLINE basic_value& basic_value::operator[](size_t pos) +inline basic_value& basic_value::operator[](size_t pos) { // basic_array not support to create by operator[] @@ -1218,7 +1215,7 @@ MEOJSON_INLINE basic_value& basic_value::operator[](size_t p } template -MEOJSON_INLINE basic_value& basic_value::operator[](const string_t& key) +inline basic_value& basic_value::operator[](const string_t& key) { if (empty()) { *this = basic_object(); @@ -1228,7 +1225,7 @@ MEOJSON_INLINE basic_value& basic_value::operator[](const st } template -MEOJSON_INLINE basic_value& basic_value::operator[](string_t&& key) +inline basic_value& basic_value::operator[](string_t&& key) { if (empty()) { *this = basic_object(); @@ -1238,76 +1235,76 @@ MEOJSON_INLINE basic_value& basic_value::operator[](string_t } template -MEOJSON_INLINE basic_value basic_value::operator|(const basic_object& rhs) const& +inline basic_value basic_value::operator|(const basic_object& rhs) const& { return as_object() | rhs; } template -MEOJSON_INLINE basic_value basic_value::operator|(basic_object&& rhs) const& +inline basic_value basic_value::operator|(basic_object&& rhs) const& { return as_object() | std::move(rhs); } template -MEOJSON_INLINE basic_value basic_value::operator|(const basic_object& rhs) && +inline basic_value basic_value::operator|(const basic_object& rhs) && { return std::move(as_object()) | rhs; } template -MEOJSON_INLINE basic_value basic_value::operator|(basic_object&& rhs) && +inline basic_value basic_value::operator|(basic_object&& rhs) && { return std::move(as_object()) | std::move(rhs); } template -MEOJSON_INLINE basic_value& basic_value::operator|=(const basic_object& rhs) +inline basic_value& basic_value::operator|=(const basic_object& rhs) { as_object() |= rhs; return *this; } template -MEOJSON_INLINE basic_value& basic_value::operator|=(basic_object&& rhs) +inline basic_value& basic_value::operator|=(basic_object&& rhs) { as_object() |= std::move(rhs); return *this; } template -MEOJSON_INLINE basic_value basic_value::operator+(const basic_array& rhs) const& +inline basic_value basic_value::operator+(const basic_array& rhs) const& { return as_array() + rhs; } template -MEOJSON_INLINE basic_value basic_value::operator+(basic_array&& rhs) const& +inline basic_value basic_value::operator+(basic_array&& rhs) const& { return as_array() + std::move(rhs); } template -MEOJSON_INLINE basic_value basic_value::operator+(const basic_array& rhs) && +inline basic_value basic_value::operator+(const basic_array& rhs) && { return std::move(as_array()) + rhs; } template -MEOJSON_INLINE basic_value basic_value::operator+(basic_array&& rhs) && +inline basic_value basic_value::operator+(basic_array&& rhs) && { return std::move(as_array()) + std::move(rhs); } template -MEOJSON_INLINE basic_value& basic_value::operator+=(const basic_array& rhs) +inline basic_value& basic_value::operator+=(const basic_array& rhs) { as_array() += rhs; return *this; } template -MEOJSON_INLINE basic_value& basic_value::operator+=(basic_array&& rhs) +inline basic_value& basic_value::operator+=(basic_array&& rhs) { as_array() += std::move(rhs); return *this; @@ -1315,14 +1312,14 @@ MEOJSON_INLINE basic_value& basic_value::operator+=(basic_ar template template -basic_value::basic_value(value_type type, args_t&&... args) +inline basic_value::basic_value(value_type type, args_t&&... args) : _type(type), _raw_data(std::forward(args)...) { static_assert(std::is_constructible_v, "Parameter can't be used to construct a var_t"); } template -MEOJSON_INLINE typename basic_value::var_t basic_value::deep_copy(const var_t& src) +inline typename basic_value::var_t basic_value::deep_copy(const var_t& src) { var_t dst; if (const auto string_ptr = std::get_if(&src)) { @@ -1346,44 +1343,43 @@ MEOJSON_INLINE typename basic_value::var_t basic_value::deep // ****************************** template -MEOJSON_INLINE basic_array::basic_array(std::initializer_list init_list) : _array_data(init_list) +inline basic_array::basic_array(std::initializer_list init_list) : _array_data(init_list) {} template -MEOJSON_INLINE basic_array::basic_array(typename raw_array::size_type size) : _array_data(size) +inline basic_array::basic_array(typename raw_array::size_type size) : _array_data(size) {} template -MEOJSON_INLINE basic_array::basic_array(const basic_value& val) - : basic_array(val.as_array()) +inline basic_array::basic_array(const basic_value& val) : basic_array(val.as_array()) {} template -MEOJSON_INLINE basic_array::basic_array(basic_value&& val) +inline basic_array::basic_array(basic_value&& val) : basic_array(std::move(val.as_array())) {} template -MEOJSON_INLINE void basic_array::clear() noexcept +inline void basic_array::clear() noexcept { _array_data.clear(); } template -MEOJSON_INLINE bool basic_array::erase(size_t pos) +inline bool basic_array::erase(size_t pos) { return erase(_array_data.begin() + pos); } template -MEOJSON_INLINE bool basic_array::erase(iterator iter) +inline bool basic_array::erase(iterator iter) { return _array_data.erase(iter) != _array_data.end(); } template template -MEOJSON_INLINE decltype(auto) basic_array::emplace_back(args_t&&... args) +inline decltype(auto) basic_array::emplace_back(args_t&&... args) { static_assert(std::is_constructible_v, "Parameter can't be used to construct a raw_array::value_type"); @@ -1392,19 +1388,19 @@ MEOJSON_INLINE decltype(auto) basic_array::emplace_back(args_t&&... ar template template -MEOJSON_INLINE decltype(auto) basic_array::push_back(args_t&&... args) +inline decltype(auto) basic_array::push_back(args_t&&... args) { return emplace_back(std::forward(args)...); } template -MEOJSON_INLINE const basic_value& basic_array::at(size_t pos) const +inline const basic_value& basic_array::at(size_t pos) const { return _array_data.at(pos); } template -MEOJSON_INLINE string_t basic_array::to_string() const +inline string_t basic_array::to_string() const { string_t str { '[' }; for (auto iter = _array_data.cbegin(); iter != _array_data.cend();) { @@ -1418,7 +1414,7 @@ MEOJSON_INLINE string_t basic_array::to_string() const } template -MEOJSON_INLINE string_t basic_array::format(size_t indent, size_t indent_times) const +inline string_t basic_array::format(size_t indent, size_t indent_times) const { const string_t tail_indent(indent * indent_times, ' '); const string_t body_indent(indent * (indent_times + 1), ' '); @@ -1437,7 +1433,7 @@ MEOJSON_INLINE string_t basic_array::format(size_t indent, size_t inde template template -MEOJSON_INLINE std::vector basic_array::to_vector() const +inline std::vector basic_array::to_vector() const { std::vector result; for (const auto& elem : _array_data) { @@ -1448,8 +1444,7 @@ MEOJSON_INLINE std::vector basic_array::to_vector() const template template -MEOJSON_INLINE auto basic_array::get_helper(const value_t& default_value, size_t pos, - rest_keys_t&&... rest) const +inline auto basic_array::get_helper(const value_t& default_value, size_t pos, rest_keys_t&&... rest) const { constexpr bool is_json = std::is_same_v, value_t> || std::is_same_v, value_t> || @@ -1470,7 +1465,7 @@ MEOJSON_INLINE auto basic_array::get_helper(const value_t& default_val template template -MEOJSON_INLINE auto basic_array::get_helper(const value_t& default_value, size_t pos) const +inline auto basic_array::get_helper(const value_t& default_value, size_t pos) const { constexpr bool is_json = std::is_same_v, value_t> || std::is_same_v, value_t> || @@ -1507,7 +1502,7 @@ MEOJSON_INLINE auto basic_array::get_helper(const value_t& default_val template template -MEOJSON_INLINE std::optional basic_array::find(size_t pos) const +inline std::optional basic_array::find(size_t pos) const { static_assert(std::is_constructible_v>, "Type can NOT be constructed by basic_value"); @@ -1519,91 +1514,91 @@ MEOJSON_INLINE std::optional basic_array::find(size_t pos) co } template -MEOJSON_INLINE typename basic_array::iterator basic_array::begin() noexcept +inline typename basic_array::iterator basic_array::begin() noexcept { return _array_data.begin(); } template -MEOJSON_INLINE typename basic_array::iterator basic_array::end() noexcept +inline typename basic_array::iterator basic_array::end() noexcept { return _array_data.end(); } template -MEOJSON_INLINE typename basic_array::const_iterator basic_array::begin() const noexcept +inline typename basic_array::const_iterator basic_array::begin() const noexcept { return _array_data.begin(); } template -MEOJSON_INLINE typename basic_array::const_iterator basic_array::end() const noexcept +inline typename basic_array::const_iterator basic_array::end() const noexcept { return _array_data.end(); } template -MEOJSON_INLINE typename basic_array::const_iterator basic_array::cbegin() const noexcept +inline typename basic_array::const_iterator basic_array::cbegin() const noexcept { return _array_data.cbegin(); } template -MEOJSON_INLINE typename basic_array::const_iterator basic_array::cend() const noexcept +inline typename basic_array::const_iterator basic_array::cend() const noexcept { return _array_data.cend(); } template -MEOJSON_INLINE typename basic_array::reverse_iterator basic_array::rbegin() noexcept +inline typename basic_array::reverse_iterator basic_array::rbegin() noexcept { return _array_data.rbegin(); } template -MEOJSON_INLINE typename basic_array::reverse_iterator basic_array::rend() noexcept +inline typename basic_array::reverse_iterator basic_array::rend() noexcept { return _array_data.rend(); } template -MEOJSON_INLINE typename basic_array::const_reverse_iterator basic_array::rbegin() const noexcept +inline typename basic_array::const_reverse_iterator basic_array::rbegin() const noexcept { return _array_data.rbegin(); } template -MEOJSON_INLINE typename basic_array::const_reverse_iterator basic_array::rend() const noexcept +inline typename basic_array::const_reverse_iterator basic_array::rend() const noexcept { return _array_data.rend(); } template -MEOJSON_INLINE typename basic_array::const_reverse_iterator basic_array::crbegin() const noexcept +inline typename basic_array::const_reverse_iterator basic_array::crbegin() const noexcept { return _array_data.crbegin(); } template -MEOJSON_INLINE typename basic_array::const_reverse_iterator basic_array::crend() const noexcept +inline typename basic_array::const_reverse_iterator basic_array::crend() const noexcept { return _array_data.crend(); } template -MEOJSON_INLINE basic_value& basic_array::operator[](size_t pos) +inline basic_value& basic_array::operator[](size_t pos) { return _array_data[pos]; } template -MEOJSON_INLINE const basic_value& basic_array::operator[](size_t pos) const +inline const basic_value& basic_array::operator[](size_t pos) const { return _array_data[pos]; } template -MEOJSON_INLINE basic_array basic_array::operator+(const basic_array& rhs) const& +inline basic_array basic_array::operator+(const basic_array& rhs) const& { basic_array temp = *this; temp._array_data.insert(_array_data.end(), rhs.begin(), rhs.end()); @@ -1611,7 +1606,7 @@ MEOJSON_INLINE basic_array basic_array::operator+(const basi } template -MEOJSON_INLINE basic_array basic_array::operator+(basic_array&& rhs) const& +inline basic_array basic_array::operator+(basic_array&& rhs) const& { basic_array temp = *this; temp._array_data.insert(_array_data.end(), std::make_move_iterator(rhs.begin()), @@ -1620,35 +1615,35 @@ MEOJSON_INLINE basic_array basic_array::operator+(basic_arra } template -MEOJSON_INLINE basic_array basic_array::operator+(const basic_array& rhs) && +inline basic_array basic_array::operator+(const basic_array& rhs) && { _array_data.insert(_array_data.end(), rhs.begin(), rhs.end()); return std::move(*this); } template -MEOJSON_INLINE basic_array basic_array::operator+(basic_array&& rhs) && +inline basic_array basic_array::operator+(basic_array&& rhs) && { _array_data.insert(_array_data.end(), std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end())); return std::move(*this); } template -MEOJSON_INLINE basic_array& basic_array::operator+=(const basic_array& rhs) +inline basic_array& basic_array::operator+=(const basic_array& rhs) { _array_data.insert(_array_data.end(), rhs.begin(), rhs.end()); return *this; } template -MEOJSON_INLINE basic_array& basic_array::operator+=(basic_array&& rhs) +inline basic_array& basic_array::operator+=(basic_array&& rhs) { _array_data.insert(_array_data.end(), std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end())); return *this; } template -MEOJSON_INLINE bool basic_array::operator==(const basic_array& rhs) const +inline bool basic_array::operator==(const basic_array& rhs) const { return _array_data == rhs._array_data; } @@ -1658,53 +1653,52 @@ MEOJSON_INLINE bool basic_array::operator==(const basic_array -MEOJSON_INLINE basic_object::basic_object(std::initializer_list init_list) +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())) {} template -MEOJSON_INLINE basic_object::basic_object(const basic_value& val) - : basic_object(val.as_object()) +inline basic_object::basic_object(const basic_value& val) : basic_object(val.as_object()) {} template -MEOJSON_INLINE basic_object::basic_object(basic_value&& val) +inline basic_object::basic_object(basic_value&& val) : basic_object(std::move(val.as_object())) {} template -MEOJSON_INLINE bool basic_object::contains(const string_t& key) const +inline bool basic_object::contains(const string_t& key) const { return _object_data.find(key) != _object_data.cend(); } template -MEOJSON_INLINE const basic_value& basic_object::at(const string_t& key) const +inline const basic_value& basic_object::at(const string_t& key) const { return _object_data.at(key); } template -MEOJSON_INLINE void basic_object::clear() noexcept +inline void basic_object::clear() noexcept { _object_data.clear(); } template -MEOJSON_INLINE bool basic_object::erase(const string_t& key) +inline bool basic_object::erase(const string_t& key) { return _object_data.erase(key) > 0 ? true : false; } template -MEOJSON_INLINE bool basic_object::erase(iterator iter) +inline bool basic_object::erase(iterator iter) { return _object_data.erase(iter) != _object_data.end(); } template template -MEOJSON_INLINE decltype(auto) basic_object::emplace(args_t&&... args) +inline decltype(auto) basic_object::emplace(args_t&&... args) { static_assert(std::is_constructible_v, "Parameter can't be used to construct a raw_object::value_type"); @@ -1713,13 +1707,13 @@ MEOJSON_INLINE decltype(auto) basic_object::emplace(args_t&&... args) template template -MEOJSON_INLINE decltype(auto) basic_object::insert(args_t&&... args) +inline decltype(auto) basic_object::insert(args_t&&... args) { return emplace(std::forward(args)...); } template -MEOJSON_INLINE string_t basic_object::to_string() const +inline string_t basic_object::to_string() const { string_t str { '{' }; for (auto iter = _object_data.cbegin(); iter != _object_data.cend();) { @@ -1734,7 +1728,7 @@ MEOJSON_INLINE string_t basic_object::to_string() const } template -MEOJSON_INLINE string_t basic_object::format(size_t indent, size_t indent_times) const +inline string_t basic_object::format(size_t indent, size_t indent_times) const { const string_t tail_indent(indent * indent_times, ' '); const string_t body_indent(indent * (indent_times + 1), ' '); @@ -1755,7 +1749,7 @@ MEOJSON_INLINE string_t basic_object::format(size_t indent, size_t ind template template -MEOJSON_INLINE std::map basic_object::to_map() const +inline std::map basic_object::to_map() const { std::map result; for (const auto& [key, val] : _object_data) { @@ -1764,11 +1758,10 @@ MEOJSON_INLINE std::map basic_object::to_map() cons return result; } - template template -MEOJSON_INLINE auto basic_object::get_helper(const value_t& default_value, const string_t& key, - rest_keys_t&&... rest) const +inline auto basic_object::get_helper(const value_t& default_value, const string_t& key, + rest_keys_t&&... rest) const { constexpr bool is_json = std::is_same_v, value_t> || std::is_same_v, value_t> || @@ -1789,7 +1782,7 @@ MEOJSON_INLINE auto basic_object::get_helper(const value_t& default_va template template -MEOJSON_INLINE auto basic_object::get_helper(const value_t& default_value, const string_t& key) const +inline auto basic_object::get_helper(const value_t& default_value, const string_t& key) const { constexpr bool is_json = std::is_same_v, value_t> || std::is_same_v, value_t> || @@ -1826,7 +1819,7 @@ MEOJSON_INLINE auto basic_object::get_helper(const value_t& default_va template template -MEOJSON_INLINE std::optional basic_object::find(const string_t& key) const +inline std::optional basic_object::find(const string_t& key) const { static_assert(std::is_constructible_v>, "value_t can NOT be constructed by basic_value"); @@ -1839,55 +1832,55 @@ MEOJSON_INLINE std::optional basic_object::find(const string_ } template -MEOJSON_INLINE typename basic_object::iterator basic_object::begin() noexcept +inline typename basic_object::iterator basic_object::begin() noexcept { return _object_data.begin(); } template -MEOJSON_INLINE typename basic_object::iterator basic_object::end() noexcept +inline typename basic_object::iterator basic_object::end() noexcept { return _object_data.end(); } template -MEOJSON_INLINE typename basic_object::const_iterator basic_object::begin() const noexcept +inline typename basic_object::const_iterator basic_object::begin() const noexcept { return _object_data.begin(); } template -MEOJSON_INLINE typename basic_object::const_iterator basic_object::end() const noexcept +inline typename basic_object::const_iterator basic_object::end() const noexcept { return _object_data.end(); } template -MEOJSON_INLINE typename basic_object::const_iterator basic_object::cbegin() const noexcept +inline typename basic_object::const_iterator basic_object::cbegin() const noexcept { return _object_data.cbegin(); } template -MEOJSON_INLINE typename basic_object::const_iterator basic_object::cend() const noexcept +inline typename basic_object::const_iterator basic_object::cend() const noexcept { return _object_data.cend(); } template -MEOJSON_INLINE basic_value& basic_object::operator[](const string_t& key) +inline basic_value& basic_object::operator[](const string_t& key) { return _object_data[key]; } template -MEOJSON_INLINE basic_value& basic_object::operator[](string_t&& key) +inline basic_value& basic_object::operator[](string_t&& key) { return _object_data[std::move(key)]; } template -MEOJSON_INLINE basic_object basic_object::operator|(const basic_object& rhs) const& +inline basic_object basic_object::operator|(const basic_object& rhs) const& { basic_object temp = *this; temp._object_data.insert(rhs.begin(), rhs.end()); @@ -1895,7 +1888,7 @@ MEOJSON_INLINE basic_object basic_object::operator|(const ba } template -MEOJSON_INLINE basic_object basic_object::operator|(basic_object&& rhs) const& +inline basic_object basic_object::operator|(basic_object&& rhs) const& { basic_object temp = *this; // temp._object_data.merge(std::move(rhs._object_data)); @@ -1904,14 +1897,14 @@ MEOJSON_INLINE basic_object basic_object::operator|(basic_ob } template -MEOJSON_INLINE basic_object basic_object::operator|(const basic_object& rhs) && +inline basic_object basic_object::operator|(const basic_object& rhs) && { _object_data.insert(rhs.begin(), rhs.end()); return std::move(*this); } template -MEOJSON_INLINE basic_object basic_object::operator|(basic_object&& rhs) && +inline basic_object basic_object::operator|(basic_object&& rhs) && { //_object_data.merge(std::move(rhs._object_data)); _object_data.insert(std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end())); @@ -1919,21 +1912,21 @@ MEOJSON_INLINE basic_object basic_object::operator|(basic_ob } template -MEOJSON_INLINE basic_object& basic_object::operator|=(const basic_object& rhs) +inline basic_object& basic_object::operator|=(const basic_object& rhs) { _object_data.insert(rhs.begin(), rhs.end()); return *this; } template -MEOJSON_INLINE basic_object& basic_object::operator|=(basic_object&& rhs) +inline basic_object& basic_object::operator|=(basic_object&& rhs) { _object_data.insert(std::make_move_iterator(rhs.begin()), std::make_move_iterator(rhs.end())); return *this; } template -MEOJSON_INLINE bool basic_object::operator==(const basic_object& rhs) const +inline bool basic_object::operator==(const basic_object& rhs) const { return _object_data == rhs._object_data; } @@ -1943,14 +1936,13 @@ MEOJSON_INLINE bool basic_object::operator==(const basic_object -MEOJSON_INLINE std::optional> parser::parse( - const parsing_t& content) +inline std::optional> parser::parse(const parsing_t& content) { return parser(content.cbegin(), content.cend()).parse(); } template -MEOJSON_INLINE std::optional> parser::parse() +inline std::optional> parser::parse() { if (!skip_whitespace()) { return std::nullopt; @@ -1982,7 +1974,7 @@ MEOJSON_INLINE std::optional> parser -MEOJSON_INLINE basic_value parser::parse_value() +inline basic_value parser::parse_value() { switch (*_cur) { case 'n': @@ -2014,7 +2006,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_null() +inline basic_value parser::parse_null() { for (const auto& ch : null_string()) { if (*_cur == ch) { @@ -2029,7 +2021,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_boolean() +inline basic_value parser::parse_boolean() { switch (*_cur) { case 't': @@ -2058,7 +2050,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_number() +inline basic_value parser::parse_number() { const auto first = _cur; if (*_cur == '-') { @@ -2097,7 +2089,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_string() +inline basic_value parser::parse_string() { auto string_opt = parse_stdstring(); if (!string_opt) { @@ -2107,7 +2099,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_array() +inline basic_value parser::parse_array() { if (*_cur == '[') { ++_cur; @@ -2158,7 +2150,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE basic_value parser::parse_object() +inline basic_value parser::parse_object() { if (*_cur == '{') { ++_cur; @@ -2222,7 +2214,7 @@ MEOJSON_INLINE basic_value parser:: } template -MEOJSON_INLINE std::optional parser::parse_stdstring() +inline std::optional parser::parse_stdstring() { if (*_cur == '"') { ++_cur; @@ -2298,7 +2290,7 @@ MEOJSON_INLINE std::optional parser } template -MEOJSON_INLINE void parser::skip_string_literal() +inline void parser::skip_string_literal() { if constexpr (sizeof(*_cur) != 1) { return; @@ -2320,7 +2312,7 @@ MEOJSON_INLINE void parser::skip_string_liter } template -MEOJSON_INLINE bool parser::skip_whitespace() noexcept +inline bool parser::skip_whitespace() noexcept { while (_cur != _end) { switch (*_cur) { @@ -2340,7 +2332,7 @@ MEOJSON_INLINE bool parser::skip_whitespace() } template -MEOJSON_INLINE bool parser::skip_digit() +inline bool parser::skip_digit() { // At least one digit if (_cur != _end && std::isdigit(*_cur)) { @@ -2367,20 +2359,20 @@ MEOJSON_INLINE bool parser::skip_digit() // ************************* template -MEOJSON_INLINE auto parse(const parsing_t& content) +auto parse(const parsing_t& content) { using string_t = std::basic_string; return parser::parse(content); } template -MEOJSON_INLINE auto parse(char_t* content) +auto parse(char_t* content) { return parse(std::basic_string_view> { content }); } template -MEOJSON_INLINE auto parse(istream_t& ifs, bool check_bom) +auto parse(istream_t& ifs, bool check_bom) { using string_t = std::basic_string; @@ -2407,7 +2399,7 @@ MEOJSON_INLINE auto parse(istream_t& ifs, bool check_bom) } template -MEOJSON_INLINE auto open(const path_t& filepath, bool check_bom) +auto open(const path_t& filepath, bool check_bom) { using char_t = typename ifstream_t::char_type; using string_t = std::basic_string; @@ -2456,41 +2448,41 @@ ostream_t& operator<<(ostream_t& out, const basic_object& obj) namespace literals { - MEOJSON_INLINE value operator""_json(const char* str, size_t len) + inline value operator""_json(const char* str, size_t len) { return operator""_jvalue(str, len); } - MEOJSON_INLINE wvalue operator""_json(const wchar_t* str, size_t len) + inline wvalue operator""_json(const wchar_t* str, size_t len) { return operator""_jvalue(str, len); } - MEOJSON_INLINE value operator""_jvalue(const char* str, size_t len) + inline value operator""_jvalue(const char* str, size_t len) { return parse(std::string_view(str, len)).value_or(value()); } - MEOJSON_INLINE wvalue operator""_jvalue(const wchar_t* str, size_t len) + inline wvalue operator""_jvalue(const wchar_t* str, size_t len) { return parse(std::wstring_view(str, len)).value_or(wvalue()); } - MEOJSON_INLINE array operator""_jarray(const char* str, size_t len) + inline array operator""_jarray(const char* str, size_t len) { auto val = parse(std::string_view(str, len)).value_or(value()); return val.is_array() ? val.as_array() : array(); } - MEOJSON_INLINE warray operator""_jarray(const wchar_t* str, size_t len) + inline warray operator""_jarray(const wchar_t* str, size_t len) { auto val = parse(std::wstring_view(str, len)).value_or(wvalue()); return val.is_array() ? val.as_array() : warray(); } - MEOJSON_INLINE object operator""_jobject(const char* str, size_t len) + inline object operator""_jobject(const char* str, size_t len) { auto val = parse(std::string_view(str, len)).value_or(value()); return val.is_object() ? val.as_object() : object(); } - MEOJSON_INLINE wobject operator""_jobject(const wchar_t* str, size_t len) + inline wobject operator""_jobject(const wchar_t* str, size_t len) { auto val = parse(std::wstring_view(str, len)).value_or(wvalue()); return val.is_object() ? val.as_object() : wobject(); @@ -2498,7 +2490,7 @@ namespace literals } // namespace literals template -MEOJSON_INLINE const basic_value invalid_value() +const basic_value invalid_value() { return basic_value(basic_value::value_type::invalid, typename basic_value::var_t()); } @@ -2582,7 +2574,7 @@ namespace _serialization_helper } // namespace _serialization_helper template -MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& string_converter) +basic_value serialize(any_t&& arg, string_converter_t&& string_converter) { using namespace _serialization_helper; @@ -2626,7 +2618,7 @@ MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& } template -MEOJSON_INLINE static constexpr string_t unescape_string(const string_t& str) +static constexpr string_t unescape_string(const string_t& str) { using char_t = typename string_t::value_type;