48 template <
class U,
class C2,
class D2>
53 constexpr auto& unique()
noexcept {
return storage.second(); }
54 constexpr auto const& unique()
const noexcept {
return storage.second(); }
57 constexpr T* get()
noexcept {
return unique().get(); }
58 constexpr T
const* get()
const noexcept {
return unique().get(); }
60 constexpr CopyCtor& getCopyCtor()
noexcept {
return storage.first(); }
61 constexpr CopyCtor
const& getCopyCtor()
const noexcept {
return storage.first(); }
63 constexpr Deleter& getDeleter()
noexcept {
return unique().get_deleter(); }
64 constexpr Deleter
const& getDeleter()
const noexcept {
return unique().get_deleter(); }
66 constexpr T* release()
noexcept {
return unique().release(); }
68 constexpr void reset(T* ptr =
nullptr, CopyCtor
const& copy = CopyCtor{})
noexcept {
70 return unique().reset(ptr);
73 constexpr explicit operator bool()
const noexcept {
return get(); }
75 template <
class... Args>
76 constexpr T& emplace(Args&&... args) {
77 reset(
new T(std::forward<Args>(args)...));
82 std::unique_ptr<T, Deleter> clone()
const noexcept {
84 return std::unique_ptr<T, Deleter>{getCopyCtor()(*get()), getDeleter()};
86 return std::unique_ptr<T, Deleter>{
nullptr, getDeleter()};
90 constexpr IndirectValue(std::nullptr_t) noexcept : storage(zeroThenVariadicArgs) {}
92 constexpr IndirectValue(T* ptr) noexcept : storage(zeroThenVariadicArgs, ptr) {}
94 constexpr IndirectValue() noexcept : storage(zeroThenVariadicArgs) {}
96 template <
class... Args>
98 : storage(zeroThenVariadicArgs,
new T(std::forward<Args>(args)...)) {}
101 : storage(oneThenVariadicArgs, other.getCopyCtor(), other.clone()) {}
103 template <
class U,
class C2,
class D2>
104 requires(std::is_convertible_v<U*, T*>)
106 : storage(oneThenVariadicArgs, other.getCopyCtor(), other.clone()) {}
109 : storage(oneThenVariadicArgs, std::move(other.getCopyCtor()), std::move(other.unique())) {}
111 template <
class U,
class C2,
class D2>
112 requires(std::is_convertible_v<U*, T*>)
114 : storage(oneThenVariadicArgs, std::move(other.getCopyCtor()), std::move(other.unique())) {}
117 if (std::addressof(other) ==
this) {
120 unique() = other.clone();
121 getCopyCtor() = other.getCopyCtor();
124 template <
class U,
class C2,
class D2>
125 requires(std::is_convertible_v<U*, T*>)
127 )
noexcept(std::is_nothrow_copy_constructible_v<U>) {
128 if constexpr (std::is_same_v<U, T>) {
129 if (std::addressof(other) ==
this) {
133 unique() = other.clone();
134 getCopyCtor() = other.getCopyCtor();
139 if (std::addressof(other) ==
this) {
142 unique() = std::move(other.unique());
143 getCopyCtor() = std::move(other.getCopyCtor());
146 template <
class U,
class C2,
class D2>
147 requires(std::is_convertible_v<U*, T*>)
149 if constexpr (std::is_same_v<U, T>) {
150 if (std::addressof(other) ==
this) {
154 unique() = std::move(other.unique());
155 getCopyCtor() = std::move(other.getCopyCtor());
159 [[nodiscard]]
constexpr T* operator->()
noexcept {
return get(); }
160 [[nodiscard]]
constexpr T
const* operator->()
const noexcept {
return get(); }
161 [[nodiscard]]
constexpr T& operator*() &
noexcept {
return *get(); }
162 [[nodiscard]]
constexpr T
const& operator*()
const&
noexcept {
return *get(); }
163 [[nodiscard]]
constexpr T&& operator*() &&
noexcept {
return std::forward<T>(*get()); }
164 [[nodiscard]]
constexpr T
const&& operator*()
const&&
noexcept {
return std::forward<T const>(*get()); }
171[[nodiscard]]
constexpr auto operator<=>(IndirectValue<T, C, D>
const& lhs, IndirectValue<T, C, D>
const& rhs) {