sled/3party/toml11/toml/storage.hpp
tqcq 3ff3323424
All checks were successful
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m24s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Successful in 1m23s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m24s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m45s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 2m23s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m45s
feat add toml
2024-04-09 00:34:09 +08:00

44 lines
1.1 KiB
C++

// Copyright Toru Niina 2017.
// Distributed under the MIT License.
#ifndef TOML11_STORAGE_HPP
#define TOML11_STORAGE_HPP
#include "utility.hpp"
namespace toml
{
namespace detail
{
// this contains pointer and deep-copy the content if copied.
// to avoid recursive pointer.
template<typename T>
struct storage
{
using value_type = T;
explicit storage(value_type const& v): ptr(toml::make_unique<T>(v)) {}
explicit storage(value_type&& v): ptr(toml::make_unique<T>(std::move(v))) {}
~storage() = default;
storage(const storage& rhs): ptr(toml::make_unique<T>(*rhs.ptr)) {}
storage& operator=(const storage& rhs)
{
this->ptr = toml::make_unique<T>(*rhs.ptr);
return *this;
}
storage(storage&&) = default;
storage& operator=(storage&&) = default;
bool is_ok() const noexcept {return static_cast<bool>(ptr);}
value_type& value() & noexcept {return *ptr;}
value_type const& value() const& noexcept {return *ptr;}
value_type&& value() && noexcept {return std::move(*ptr);}
private:
std::unique_ptr<value_type> ptr;
};
} // detail
} // toml
#endif// TOML11_STORAGE_HPP