diff --git a/src/json.hpp b/src/json.hpp index 9d48e7a6..4e043ad5 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -128,7 +128,7 @@ struct has_mapped_type std::is_integral()))>::value; }; -} +} // namespace /*! @brief a class to store JSON values @@ -767,7 +767,7 @@ class basic_json }; std::unique_ptr object(alloc.allocate(1), deleter); alloc.construct(object.get(), std::forward(args)...); - assert(object.get() != nullptr); + assert(object != nullptr); return object.release(); } @@ -2583,29 +2583,25 @@ class basic_json template::value and std::is_convertible::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_object()) { return T(m_value.object->begin(), m_value.object->end()); } - else - { - throw std::domain_error("type must be object, but is " + type_name()); - } + + throw std::domain_error("type must be object, but is " + type_name()); } /// get an object (explicit) - object_t get_impl(object_t*) const + object_t get_impl(object_t* /*unused*/) const { if (is_object()) { return *(m_value.object); } - else - { - throw std::domain_error("type must be object, but is " + type_name()); - } + + throw std::domain_error("type must be object, but is " + type_name()); } /// get an array (explicit) @@ -2615,7 +2611,7 @@ class basic_json not std::is_arithmetic::value and not std::is_convertible::value and not has_mapped_type::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_array()) { @@ -2627,17 +2623,15 @@ class basic_json }); return to_vector; } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) template::value and not std::is_same::value, int>::type = 0> - std::vector get_impl(std::vector*) const + std::vector get_impl(std::vector* /*unused*/) const { if (is_array()) { @@ -2650,60 +2644,52 @@ class basic_json }); return to_vector; } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) template::value and not has_mapped_type::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_array()) { return T(m_value.array->begin(), m_value.array->end()); } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) - array_t get_impl(array_t*) const + array_t get_impl(array_t* /*unused*/) const { if (is_array()) { return *(m_value.array); } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get a string (explicit) template::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_string()) { return *m_value.string; } - else - { - throw std::domain_error("type must be string, but is " + type_name()); - } + + throw std::domain_error("type must be string, but is " + type_name()); } /// get a number (explicit) template::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { switch (m_type) { @@ -2730,7 +2716,7 @@ class basic_json } /// get a boolean (explicit) - constexpr boolean_t get_impl(boolean_t*) const + constexpr boolean_t get_impl(boolean_t* /*unused*/) const { return is_boolean() ? m_value.boolean @@ -2738,85 +2724,85 @@ class basic_json } /// get a pointer to the value (object) - object_t* get_impl_ptr(object_t*) noexcept + object_t* get_impl_ptr(object_t* /*unused*/) noexcept { return is_object() ? m_value.object : nullptr; } /// get a pointer to the value (object) - constexpr const object_t* get_impl_ptr(const object_t*) const noexcept + constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept { return is_object() ? m_value.object : nullptr; } /// get a pointer to the value (array) - array_t* get_impl_ptr(array_t*) noexcept + array_t* get_impl_ptr(array_t* /*unused*/) noexcept { return is_array() ? m_value.array : nullptr; } /// get a pointer to the value (array) - constexpr const array_t* get_impl_ptr(const array_t*) const noexcept + constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept { return is_array() ? m_value.array : nullptr; } /// get a pointer to the value (string) - string_t* get_impl_ptr(string_t*) noexcept + string_t* get_impl_ptr(string_t* /*unused*/) noexcept { return is_string() ? m_value.string : nullptr; } /// get a pointer to the value (string) - constexpr const string_t* get_impl_ptr(const string_t*) const noexcept + constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept { return is_string() ? m_value.string : nullptr; } /// get a pointer to the value (boolean) - boolean_t* get_impl_ptr(boolean_t*) noexcept + boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept { return is_boolean() ? &m_value.boolean : nullptr; } /// get a pointer to the value (boolean) - constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept + constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept { return is_boolean() ? &m_value.boolean : nullptr; } /// get a pointer to the value (integer number) - number_integer_t* get_impl_ptr(number_integer_t*) noexcept + number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept { return is_number_integer() ? &m_value.number_integer : nullptr; } /// get a pointer to the value (integer number) - constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept + constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept { return is_number_integer() ? &m_value.number_integer : nullptr; } /// get a pointer to the value (unsigned number) - number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept + number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept { return is_number_unsigned() ? &m_value.number_unsigned : nullptr; } /// get a pointer to the value (unsigned number) - constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept + constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept { return is_number_unsigned() ? &m_value.number_unsigned : nullptr; } /// get a pointer to the value (floating-point number) - number_float_t* get_impl_ptr(number_float_t*) noexcept + number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept { return is_number_float() ? &m_value.number_float : nullptr; } /// get a pointer to the value (floating-point number) - constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept + constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept { return is_number_float() ? &m_value.number_float : nullptr; } @@ -2845,11 +2831,9 @@ class basic_json { return *ptr; } - else - { - throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " + - obj.type_name()); - } + + throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " + + obj.type_name()); } public: @@ -3349,10 +3333,8 @@ class basic_json return m_value.array->operator[](idx); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3381,10 +3363,8 @@ class basic_json { return m_value.array->operator[](idx); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3429,10 +3409,8 @@ class basic_json { return m_value.object->operator[](key); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3473,10 +3451,8 @@ class basic_json assert(m_value.object->find(key) != m_value.object->end()); return m_value.object->find(key)->second; } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3590,10 +3566,8 @@ class basic_json { return m_value.object->operator[](key); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3635,10 +3609,8 @@ class basic_json assert(m_value.object->find(key) != m_value.object->end()); return m_value.object->find(key)->second; } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3702,10 +3674,8 @@ class basic_json { return *it; } - else - { - return default_value; - } + + return default_value; } else { @@ -4131,10 +4101,8 @@ class basic_json { return m_value.object->erase(key); } - else - { - throw std::domain_error("cannot use erase() with " + type_name()); - } + + throw std::domain_error("cannot use erase() with " + type_name()); } /*! @@ -5186,10 +5154,8 @@ class basic_json result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); return result; } - else - { - throw std::domain_error("cannot use insert() with " + type_name()); - } + + throw std::domain_error("cannot use insert() with " + type_name()); } /*! @@ -5241,10 +5207,8 @@ class basic_json result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); return result; } - else - { - throw std::domain_error("cannot use insert() with " + type_name()); - } + + throw std::domain_error("cannot use insert() with " + type_name()); } /*! @@ -6122,7 +6086,7 @@ class basic_json { // assertion to check that the iterator range is indeed contiguous, // see http://stackoverflow.com/a/35008842/266378 for more discussion - assert(std::accumulate(first, last, std::make_pair(true, 0), + assert(std::accumulate(first, last, std::pair(true, 0), [&first](std::pair res, decltype(*first) val) { res.first &= (val == *(std::next(std::addressof(*first), res.second++))); @@ -6327,7 +6291,7 @@ class basic_json } T result; - uint8_t* ptr = reinterpret_cast(&result); + auto* ptr = reinterpret_cast(&result); for (size_t i = 0; i < sizeof(T); ++i) { *ptr++ = vec[current_index + sizeof(T) - i]; @@ -6473,7 +6437,7 @@ class basic_json { // float 64 v.push_back(0xcb); - const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + const auto* helper = reinterpret_cast(&(j.m_value.number_float)); for (size_t i = 0; i < 8; ++i) { v.push_back(helper[7 - i]); @@ -6716,7 +6680,7 @@ class basic_json { // Double-Precision Float v.push_back(0xfb); - const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + const auto* helper = reinterpret_cast(&(j.m_value.number_float)); for (size_t i = 0; i < 8; ++i) { v.push_back(helper[7 - i]); @@ -6916,7 +6880,7 @@ class basic_json { return v[current_idx]; } - else if (v[current_idx] <= 0x8f) // fixmap + if (v[current_idx] <= 0x8f) // fixmap { basic_json result = value_t::object; const size_t len = v[current_idx] & 0x0f; @@ -7577,7 +7541,7 @@ class basic_json { val = mant == 0 ? INFINITY : NAN; } - return half & 0x8000 ? -val : val; + return (half & 0x8000) != 0 ? -val : val; } case 0xfa: // Single-Precision Float (four-byte IEEE 754) @@ -7800,10 +7764,8 @@ class basic_json // from c (1 byte) to \uxxxx (6 bytes) return res + 5; } - else - { - return res; - } + + return res; } } }); @@ -8509,10 +8471,8 @@ class basic_json { return *m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8545,10 +8505,8 @@ class basic_json { return m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8861,10 +8819,8 @@ class basic_json { return *m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8881,10 +8837,8 @@ class basic_json { return m_it.object_iterator->first; } - else - { - throw std::domain_error("cannot use key() for non-object iterators"); - } + + throw std::domain_error("cannot use key() for non-object iterators"); } /*! @@ -10209,7 +10163,7 @@ basic_json_parser_66: assert(m_marker == nullptr or m_marker <= m_limit); // number of processed characters (p) - const size_t num_processed_chars = static_cast(m_start - m_content); + const auto num_processed_chars = static_cast(m_start - m_content); // offset for m_marker wrt. to m_start const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start; // number of unprocessed characters (u) @@ -10601,7 +10555,7 @@ basic_json_parser_66: else { // parse with strtod - result.m_value.number_float = str_to_float_t(static_cast(nullptr), NULL); + result.m_value.number_float = str_to_float_t(static_cast(nullptr), nullptr); // replace infinity and NAN by null if (not std::isfinite(result.m_value.number_float)) @@ -11336,7 +11290,7 @@ basic_json_parser_66: // - start: position after the previous slash for ( // search for the first slash after the first character - size_t slash = reference_string.find_first_of("/", 1), + size_t slash = reference_string.find_first_of('/', 1), // set the beginning of the first reference token start = 1; // we can stop if start == string::npos+1 = 0 @@ -11345,16 +11299,16 @@ basic_json_parser_66: // (will eventually be 0 if slash == std::string::npos) start = slash + 1, // find next slash - slash = reference_string.find_first_of("/", start)) + slash = reference_string.find_first_of('/', start)) { // use the text between the beginning of the reference token // (start) and the last slash (slash). auto reference_token = reference_string.substr(start, slash - start); // check reference tokens are properly escaped - for (size_t pos = reference_token.find_first_of("~"); + for (size_t pos = reference_token.find_first_of('~'); pos != std::string::npos; - pos = reference_token.find_first_of("~", pos + 1)) + pos = reference_token.find_first_of('~', pos + 1)) { assert(reference_token[pos] == '~'); @@ -12188,7 +12142,7 @@ uses the standard template types. @since version 1.0.0 */ using json = basic_json<>; -} +} // namespace nlohmann /////////////////////// @@ -12229,7 +12183,7 @@ struct hash return h(j.dump()); } }; -} +} // namespace std /*! @brief user-defined string literal for JSON values diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index e1a43b54..a64762b9 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -128,7 +128,7 @@ struct has_mapped_type std::is_integral()))>::value; }; -} +} // namespace /*! @brief a class to store JSON values @@ -767,7 +767,7 @@ class basic_json }; std::unique_ptr object(alloc.allocate(1), deleter); alloc.construct(object.get(), std::forward(args)...); - assert(object.get() != nullptr); + assert(object != nullptr); return object.release(); } @@ -2583,29 +2583,25 @@ class basic_json template::value and std::is_convertible::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_object()) { return T(m_value.object->begin(), m_value.object->end()); } - else - { - throw std::domain_error("type must be object, but is " + type_name()); - } + + throw std::domain_error("type must be object, but is " + type_name()); } /// get an object (explicit) - object_t get_impl(object_t*) const + object_t get_impl(object_t* /*unused*/) const { if (is_object()) { return *(m_value.object); } - else - { - throw std::domain_error("type must be object, but is " + type_name()); - } + + throw std::domain_error("type must be object, but is " + type_name()); } /// get an array (explicit) @@ -2615,7 +2611,7 @@ class basic_json not std::is_arithmetic::value and not std::is_convertible::value and not has_mapped_type::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_array()) { @@ -2627,17 +2623,15 @@ class basic_json }); return to_vector; } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) template::value and not std::is_same::value, int>::type = 0> - std::vector get_impl(std::vector*) const + std::vector get_impl(std::vector* /*unused*/) const { if (is_array()) { @@ -2650,60 +2644,52 @@ class basic_json }); return to_vector; } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) template::value and not has_mapped_type::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_array()) { return T(m_value.array->begin(), m_value.array->end()); } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get an array (explicit) - array_t get_impl(array_t*) const + array_t get_impl(array_t* /*unused*/) const { if (is_array()) { return *(m_value.array); } - else - { - throw std::domain_error("type must be array, but is " + type_name()); - } + + throw std::domain_error("type must be array, but is " + type_name()); } /// get a string (explicit) template::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { if (is_string()) { return *m_value.string; } - else - { - throw std::domain_error("type must be string, but is " + type_name()); - } + + throw std::domain_error("type must be string, but is " + type_name()); } /// get a number (explicit) template::value, int>::type = 0> - T get_impl(T*) const + T get_impl(T* /*unused*/) const { switch (m_type) { @@ -2730,7 +2716,7 @@ class basic_json } /// get a boolean (explicit) - constexpr boolean_t get_impl(boolean_t*) const + constexpr boolean_t get_impl(boolean_t* /*unused*/) const { return is_boolean() ? m_value.boolean @@ -2738,85 +2724,85 @@ class basic_json } /// get a pointer to the value (object) - object_t* get_impl_ptr(object_t*) noexcept + object_t* get_impl_ptr(object_t* /*unused*/) noexcept { return is_object() ? m_value.object : nullptr; } /// get a pointer to the value (object) - constexpr const object_t* get_impl_ptr(const object_t*) const noexcept + constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept { return is_object() ? m_value.object : nullptr; } /// get a pointer to the value (array) - array_t* get_impl_ptr(array_t*) noexcept + array_t* get_impl_ptr(array_t* /*unused*/) noexcept { return is_array() ? m_value.array : nullptr; } /// get a pointer to the value (array) - constexpr const array_t* get_impl_ptr(const array_t*) const noexcept + constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept { return is_array() ? m_value.array : nullptr; } /// get a pointer to the value (string) - string_t* get_impl_ptr(string_t*) noexcept + string_t* get_impl_ptr(string_t* /*unused*/) noexcept { return is_string() ? m_value.string : nullptr; } /// get a pointer to the value (string) - constexpr const string_t* get_impl_ptr(const string_t*) const noexcept + constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept { return is_string() ? m_value.string : nullptr; } /// get a pointer to the value (boolean) - boolean_t* get_impl_ptr(boolean_t*) noexcept + boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept { return is_boolean() ? &m_value.boolean : nullptr; } /// get a pointer to the value (boolean) - constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept + constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept { return is_boolean() ? &m_value.boolean : nullptr; } /// get a pointer to the value (integer number) - number_integer_t* get_impl_ptr(number_integer_t*) noexcept + number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept { return is_number_integer() ? &m_value.number_integer : nullptr; } /// get a pointer to the value (integer number) - constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept + constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept { return is_number_integer() ? &m_value.number_integer : nullptr; } /// get a pointer to the value (unsigned number) - number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept + number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept { return is_number_unsigned() ? &m_value.number_unsigned : nullptr; } /// get a pointer to the value (unsigned number) - constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept + constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept { return is_number_unsigned() ? &m_value.number_unsigned : nullptr; } /// get a pointer to the value (floating-point number) - number_float_t* get_impl_ptr(number_float_t*) noexcept + number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept { return is_number_float() ? &m_value.number_float : nullptr; } /// get a pointer to the value (floating-point number) - constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept + constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept { return is_number_float() ? &m_value.number_float : nullptr; } @@ -2845,11 +2831,9 @@ class basic_json { return *ptr; } - else - { - throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " + - obj.type_name()); - } + + throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " + + obj.type_name()); } public: @@ -3349,10 +3333,8 @@ class basic_json return m_value.array->operator[](idx); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3381,10 +3363,8 @@ class basic_json { return m_value.array->operator[](idx); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3429,10 +3409,8 @@ class basic_json { return m_value.object->operator[](key); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3473,10 +3451,8 @@ class basic_json assert(m_value.object->find(key) != m_value.object->end()); return m_value.object->find(key)->second; } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3590,10 +3566,8 @@ class basic_json { return m_value.object->operator[](key); } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3635,10 +3609,8 @@ class basic_json assert(m_value.object->find(key) != m_value.object->end()); return m_value.object->find(key)->second; } - else - { - throw std::domain_error("cannot use operator[] with " + type_name()); - } + + throw std::domain_error("cannot use operator[] with " + type_name()); } /*! @@ -3702,10 +3674,8 @@ class basic_json { return *it; } - else - { - return default_value; - } + + return default_value; } else { @@ -4131,10 +4101,8 @@ class basic_json { return m_value.object->erase(key); } - else - { - throw std::domain_error("cannot use erase() with " + type_name()); - } + + throw std::domain_error("cannot use erase() with " + type_name()); } /*! @@ -5186,10 +5154,8 @@ class basic_json result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); return result; } - else - { - throw std::domain_error("cannot use insert() with " + type_name()); - } + + throw std::domain_error("cannot use insert() with " + type_name()); } /*! @@ -5241,10 +5207,8 @@ class basic_json result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); return result; } - else - { - throw std::domain_error("cannot use insert() with " + type_name()); - } + + throw std::domain_error("cannot use insert() with " + type_name()); } /*! @@ -6122,7 +6086,7 @@ class basic_json { // assertion to check that the iterator range is indeed contiguous, // see http://stackoverflow.com/a/35008842/266378 for more discussion - assert(std::accumulate(first, last, std::make_pair(true, 0), + assert(std::accumulate(first, last, std::pair(true, 0), [&first](std::pair res, decltype(*first) val) { res.first &= (val == *(std::next(std::addressof(*first), res.second++))); @@ -6327,7 +6291,7 @@ class basic_json } T result; - uint8_t* ptr = reinterpret_cast(&result); + auto* ptr = reinterpret_cast(&result); for (size_t i = 0; i < sizeof(T); ++i) { *ptr++ = vec[current_index + sizeof(T) - i]; @@ -6473,7 +6437,7 @@ class basic_json { // float 64 v.push_back(0xcb); - const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + const auto* helper = reinterpret_cast(&(j.m_value.number_float)); for (size_t i = 0; i < 8; ++i) { v.push_back(helper[7 - i]); @@ -6716,7 +6680,7 @@ class basic_json { // Double-Precision Float v.push_back(0xfb); - const uint8_t* helper = reinterpret_cast(&(j.m_value.number_float)); + const auto* helper = reinterpret_cast(&(j.m_value.number_float)); for (size_t i = 0; i < 8; ++i) { v.push_back(helper[7 - i]); @@ -6916,7 +6880,7 @@ class basic_json { return v[current_idx]; } - else if (v[current_idx] <= 0x8f) // fixmap + if (v[current_idx] <= 0x8f) // fixmap { basic_json result = value_t::object; const size_t len = v[current_idx] & 0x0f; @@ -7577,7 +7541,7 @@ class basic_json { val = mant == 0 ? INFINITY : NAN; } - return half & 0x8000 ? -val : val; + return (half & 0x8000) != 0 ? -val : val; } case 0xfa: // Single-Precision Float (four-byte IEEE 754) @@ -7800,10 +7764,8 @@ class basic_json // from c (1 byte) to \uxxxx (6 bytes) return res + 5; } - else - { - return res; - } + + return res; } } }); @@ -8509,10 +8471,8 @@ class basic_json { return *m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8545,10 +8505,8 @@ class basic_json { return m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8861,10 +8819,8 @@ class basic_json { return *m_object; } - else - { - throw std::out_of_range("cannot get value"); - } + + throw std::out_of_range("cannot get value"); } } } @@ -8881,10 +8837,8 @@ class basic_json { return m_it.object_iterator->first; } - else - { - throw std::domain_error("cannot use key() for non-object iterators"); - } + + throw std::domain_error("cannot use key() for non-object iterators"); } /*! @@ -9359,7 +9313,7 @@ class basic_json assert(m_marker == nullptr or m_marker <= m_limit); // number of processed characters (p) - const size_t num_processed_chars = static_cast(m_start - m_content); + const auto num_processed_chars = static_cast(m_start - m_content); // offset for m_marker wrt. to m_start const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start; // number of unprocessed characters (u) @@ -9751,7 +9705,7 @@ class basic_json else { // parse with strtod - result.m_value.number_float = str_to_float_t(static_cast(nullptr), NULL); + result.m_value.number_float = str_to_float_t(static_cast(nullptr), nullptr); // replace infinity and NAN by null if (not std::isfinite(result.m_value.number_float)) @@ -10486,7 +10440,7 @@ class basic_json // - start: position after the previous slash for ( // search for the first slash after the first character - size_t slash = reference_string.find_first_of("/", 1), + size_t slash = reference_string.find_first_of('/', 1), // set the beginning of the first reference token start = 1; // we can stop if start == string::npos+1 = 0 @@ -10495,16 +10449,16 @@ class basic_json // (will eventually be 0 if slash == std::string::npos) start = slash + 1, // find next slash - slash = reference_string.find_first_of("/", start)) + slash = reference_string.find_first_of('/', start)) { // use the text between the beginning of the reference token // (start) and the last slash (slash). auto reference_token = reference_string.substr(start, slash - start); // check reference tokens are properly escaped - for (size_t pos = reference_token.find_first_of("~"); + for (size_t pos = reference_token.find_first_of('~'); pos != std::string::npos; - pos = reference_token.find_first_of("~", pos + 1)) + pos = reference_token.find_first_of('~', pos + 1)) { assert(reference_token[pos] == '~'); @@ -11338,7 +11292,7 @@ uses the standard template types. @since version 1.0.0 */ using json = basic_json<>; -} +} // namespace nlohmann /////////////////////// @@ -11379,7 +11333,7 @@ struct hash return h(j.dump()); } }; -} +} // namespace std /*! @brief user-defined string literal for JSON values diff --git a/test/src/unit-allocator.cpp b/test/src/unit-allocator.cpp index f11d8538..76f9a16b 100644 --- a/test/src/unit-allocator.cpp +++ b/test/src/unit-allocator.cpp @@ -80,7 +80,7 @@ struct my_allocator : std::allocator } else { - ::new(reinterpret_cast(p)) T(std::forward(args)...); + ::new (reinterpret_cast(p)) T(std::forward(args)...); } } diff --git a/test/src/unit-constructor1.cpp b/test/src/unit-constructor1.cpp index 6bfb4402..d03a5f40 100644 --- a/test/src/unit-constructor1.cpp +++ b/test/src/unit-constructor1.cpp @@ -912,7 +912,7 @@ TEST_CASE("constructors") SECTION("array") { - json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false} , 13 }; + json j { {"one", 1}, {"two", 1u}, {"three", 2.2}, {"four", false}, 13 }; CHECK(j.type() == json::value_t::array); } }