view dep/toml11/toml/storage.hpp @ 337:a7d4e5107531

dep/animone: REFACTOR ALL THE THINGS 1: animone now has its own syntax divergent from anisthesia, making different platforms actually have their own sections 2: process names in animone are now called `comm' (this will probably break things). this is what its called in bsd/linux so I'm just going to use it everywhere 3: the X11 code now checks for the existence of a UTF-8 window title and passes it if available 4: ANYTHING THATS NOT LINUX IS 100% UNTESTED AND CAN AND WILL BREAK! I still actually need to test the bsd code. to be honest I'm probably going to move all of the bsds into separate files because they're all essentially different operating systems at this point
author Paper <paper@paper.us.eu.org>
date Wed, 19 Jun 2024 12:51:15 -0400
parents 3b355fa948c7
children
line wrap: on
line source

//     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