mirror of
https://github.com/nlohmann/json
synced 2025-01-05 23:21:06 +00:00
🔨 cleanup after #663
This commit is contained in:
parent
3d67ec40a6
commit
850d856aae
@ -849,7 +849,9 @@ I deeply appreciate the help of the following people.
|
|||||||
- [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`.
|
- [Steffen](https://github.com/koemeet) fixed a potential issue with MSVC and `std::min`.
|
||||||
- [Mike Tzou](https://github.com/Chocobo1) fixed some typos.
|
- [Mike Tzou](https://github.com/Chocobo1) fixed some typos.
|
||||||
- [amrcode](https://github.com/amrcode) noted a missleading documentation about comparison of floats.
|
- [amrcode](https://github.com/amrcode) noted a missleading documentation about comparison of floats.
|
||||||
- [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`
|
- [Oleg Endo](https://github.com/olegendo) reduced the memory consumption by replacing `<iostream>` with `<iosfwd>`.
|
||||||
|
- [dan-42](https://github.com/dan-42) cleaned up the CMake files to simplify including/reusing of the library.
|
||||||
|
- [Nikita Ofitserov](https://github.com/himikof) allowed for moving values from initializer lists.
|
||||||
|
|
||||||
|
|
||||||
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
|
||||||
@ -912,7 +914,7 @@ $ make json_unit -Ctest
|
|||||||
$ ./test/json_unit "*"
|
$ ./test/json_unit "*"
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
All tests passed (13391115 assertions in 49 test cases)
|
All tests passed (14504461 assertions in 48 test cases)
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, you can use [CMake](https://cmake.org) and run
|
Alternatively, you can use [CMake](https://cmake.org) and run
|
||||||
|
57
src/json.hpp
57
src/json.hpp
@ -6843,63 +6843,61 @@ class serializer
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
struct json_ref
|
class json_ref
|
||||||
{
|
{
|
||||||
typedef BasicJsonType value_type;
|
public:
|
||||||
|
using value_type = BasicJsonType;
|
||||||
|
|
||||||
json_ref(value_type&& value)
|
json_ref(value_type&& value)
|
||||||
: owned_value_(std::move(value))
|
: owned_value(std::move(value)),
|
||||||
, is_rvalue_(true)
|
value_ref(&owned_value),
|
||||||
{
|
is_rvalue(true)
|
||||||
value_ref_ = &owned_value_;
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
json_ref(const value_type& value)
|
json_ref(const value_type& value)
|
||||||
: value_ref_(const_cast<value_type*>(&value))
|
: value_ref(const_cast<value_type*>(&value)),
|
||||||
, is_rvalue_(false)
|
is_rvalue(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
json_ref(std::initializer_list<json_ref> init)
|
json_ref(std::initializer_list<json_ref> init)
|
||||||
: owned_value_(init)
|
: owned_value(init),
|
||||||
, is_rvalue_(true)
|
value_ref(&owned_value),
|
||||||
{
|
is_rvalue(true)
|
||||||
value_ref_ = &owned_value_;
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
json_ref(Args... args)
|
json_ref(Args... args)
|
||||||
: owned_value_(std::forward<Args>(args)...)
|
: owned_value(std::forward<Args>(args)...),
|
||||||
, is_rvalue_(true)
|
value_ref(&owned_value),
|
||||||
{
|
is_rvalue(true)
|
||||||
value_ref_ = &owned_value_;
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
value_type moved_or_copied() const
|
value_type moved_or_copied() const
|
||||||
{
|
{
|
||||||
if (is_rvalue_)
|
if (is_rvalue)
|
||||||
{
|
{
|
||||||
return std::move(*value_ref_);
|
return std::move(*value_ref);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return *value_ref_;
|
return *value_ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type const& operator*() const
|
value_type const& operator*() const
|
||||||
{
|
{
|
||||||
return *static_cast<value_type const*>(value_ref_);
|
return *static_cast<value_type const*>(value_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type const* operator->() const
|
value_type const* operator->() const
|
||||||
{
|
{
|
||||||
return static_cast<value_type const*>(value_ref_);
|
return static_cast<value_type const*>(value_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
value_type * value_ref_;
|
mutable value_type owned_value;
|
||||||
mutable value_type owned_value_;
|
value_type* value_ref = nullptr;
|
||||||
bool is_rvalue_;
|
const bool is_rvalue;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@ -8510,7 +8508,7 @@ class basic_json
|
|||||||
|
|
||||||
std::for_each(init.begin(), init.end(), [this](const detail::json_ref<basic_json>& element_ref)
|
std::for_each(init.begin(), init.end(), [this](const detail::json_ref<basic_json>& element_ref)
|
||||||
{
|
{
|
||||||
basic_json element = element_ref.moved_or_copied();
|
auto element = element_ref.moved_or_copied();
|
||||||
m_value.object->emplace(
|
m_value.object->emplace(
|
||||||
std::move(*((*element.m_value.array)[0].m_value.string)),
|
std::move(*((*element.m_value.array)[0].m_value.string)),
|
||||||
std::move((*element.m_value.array)[1]));
|
std::move((*element.m_value.array)[1]));
|
||||||
@ -8775,8 +8773,7 @@ class basic_json
|
|||||||
|
|
||||||
basic_json(const detail::json_ref<basic_json>& ref)
|
basic_json(const detail::json_ref<basic_json>& ref)
|
||||||
: basic_json(ref.moved_or_copied())
|
: basic_json(ref.moved_or_copied())
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief copy constructor
|
@brief copy constructor
|
||||||
|
Loading…
Reference in New Issue
Block a user