mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-06-08 07:06:52 +02:00
start work on webconsole with templates
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
47460d86b2
commit
a843be75f3
60 changed files with 24925 additions and 38 deletions
68
libi2pd_webconsole/nlohmann/detail/json_ref.hpp
Normal file
68
libi2pd_webconsole/nlohmann/detail/json_ref.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
#include <utility>
|
||||
|
||||
#include <nlohmann/detail/meta/type_traits.hpp>
|
||||
|
||||
namespace nlohmann
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename BasicJsonType>
|
||||
class json_ref
|
||||
{
|
||||
public:
|
||||
using value_type = BasicJsonType;
|
||||
|
||||
json_ref(value_type&& value)
|
||||
: owned_value(std::move(value))
|
||||
{}
|
||||
|
||||
json_ref(const value_type& value)
|
||||
: value_ref(&value)
|
||||
{}
|
||||
|
||||
json_ref(std::initializer_list<json_ref> init)
|
||||
: owned_value(init)
|
||||
{}
|
||||
|
||||
template <
|
||||
class... Args,
|
||||
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
|
||||
json_ref(Args && ... args)
|
||||
: owned_value(std::forward<Args>(args)...)
|
||||
{}
|
||||
|
||||
// class should be movable only
|
||||
json_ref(json_ref&&) noexcept = default;
|
||||
json_ref(const json_ref&) = delete;
|
||||
json_ref& operator=(const json_ref&) = delete;
|
||||
json_ref& operator=(json_ref&&) = delete;
|
||||
~json_ref() = default;
|
||||
|
||||
value_type moved_or_copied() const
|
||||
{
|
||||
if (value_ref == nullptr)
|
||||
{
|
||||
return std::move(owned_value);
|
||||
}
|
||||
return *value_ref;
|
||||
}
|
||||
|
||||
value_type const& operator*() const
|
||||
{
|
||||
return value_ref ? *value_ref : owned_value;
|
||||
}
|
||||
|
||||
value_type const* operator->() const
|
||||
{
|
||||
return &** this;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable value_type owned_value = nullptr;
|
||||
value_type const* value_ref = nullptr;
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace nlohmann
|
Loading…
Add table
Add a link
Reference in a new issue