5 #ifndef VCCC_RANGES_MOVABLE_BOX_HPP
6 #define VCCC_RANGES_MOVABLE_BOX_HPP
8 #include <initializer_list>
26 struct movable_box_store_obj_only
30 copy_constructible<T>,
31 std::is_nothrow_move_constructible<T>,
32 std::is_nothrow_copy_constructible<T> >,
34 negation< copy_constructible<T> >,
37 negation< copy_constructible<T> >,
38 std::is_nothrow_copy_constructible<T> >
42 struct movable_box_storage_base;
45 struct movable_box_storage_base<T, true> {
47 constexpr movable_box_storage_base() =
default;
48 constexpr movable_box_storage_base(
const movable_box_storage_base&) =
default;
49 constexpr movable_box_storage_base(movable_box_storage_base&&) =
default;
50 constexpr movable_box_storage_base& operator=(
const movable_box_storage_base&) =
default;
51 constexpr movable_box_storage_base& operator=(movable_box_storage_base&&) =
default;
53 template<
typename InPlace, std::enable_if_t<conjunction<
54 std::is_same<in_place_t, InPlace>,
55 std::is_constructible<T>
57 constexpr movable_box_storage_base(InPlace)
61 template<
typename U, std::enable_if_t<conjunction<
62 negation< std::is_same<in_place_t, remove_cvref_t<U>> >,
63 negation< std::is_same<movable_box_storage_base, remove_cvref_t<U>> >,
64 std::is_constructible<T, U>
66 constexpr movable_box_storage_base(U&& arg)
68 : value_(
std::forward<U>(arg)) {}
70 template<
typename Arg,
typename... Args, std::enable_if_t<conjunction<
71 std::is_constructible<T, Arg, Args...>
73 constexpr movable_box_storage_base(in_place_t, Arg&& arg, Args&&... args)
75 : value_(
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
77 template<
typename U,
typename... Args, std::enable_if_t<conjunction<
78 std::is_constructible<T, std::initializer_list<U>, Args...>
80 constexpr movable_box_storage_base(in_place_t, std::initializer_list<U> il, Args&&... args)
81 noexcept(std::is_nothrow_constructible<T, std::initializer_list<U>, Args...>::
value)
82 : value_(il,
std::forward<Args>(args)...) {}
84 template<
typename U, std::enable_if_t<conjunction<
85 negation< std::is_same<movable_box_storage_base, std::decay_t<U>> >,
86 std::is_assignable<T, U>
89 value_ = std::forward<U>(arg);
93 constexpr
explicit operator bool() const noexcept {
return true; }
94 constexpr
bool has_value() const noexcept {
return true; }
96 constexpr
const T* operator->() const noexcept {
return vccc::addressof(value_); }
98 constexpr
const T&
operator*() const& noexcept {
return value_; }
99 constexpr T&
operator*() & noexcept {
return value_; }
100 constexpr
const T&&
operator*() const&& noexcept {
return std::move(value_); }
101 constexpr T&&
operator*() && noexcept {
return std::move(value_); }
103 constexpr
void reset() noexcept { value_.~T(); }
105 template<
typename... Args, std::enable_if_t<std::is_constructible<T, Args...>
::value,
int> = 0>
106 constexpr T& emplace(Args&&... args)
107 noexcept(conjunction< std::is_nothrow_constructible<T, Args...>,
108 std::is_nothrow_destructible<T> >::
value)
111 ::new(this->operator->()) T(std::forward<Args>(args)...);
115 template<
typename U,
typename... Args, std::enable_if_t<std::is_constructible<T, std::initializer_list<U>, Args...>
::value,
int> = 0>
116 constexpr T& emplace(std::initializer_list<U> il, Args&&... args)
117 noexcept(conjunction< std::is_nothrow_constructible<T, std::initializer_list<U>, Args...>,
118 std::is_nothrow_destructible<T> >::
value)
121 ::new(this->operator->()) T(il, std::forward<Args>(args)...);
130 struct movable_box_storage_base<T, false> :
private optional<T> {
131 using base = optional<T>;
134 using base::operator=;
135 using base::operator->;
136 using base::operator*;
137 using base::operator bool;
138 using base::has_value;
143 template<
typename T,
bool = conjunction<copyable<T>, copy_constructible<T>>::value >
144 struct movable_box_storage_copy_assign : movable_box_storage_base<T> {
145 using base = movable_box_storage_base<T>;
150 struct movable_box_storage_copy_assign<T, false> : movable_box_storage_base<T> {
151 using base = movable_box_storage_base<T>;
154 constexpr movable_box_storage_copy_assign() =
default;
155 constexpr movable_box_storage_copy_assign(
const movable_box_storage_copy_assign&) =
default;
156 constexpr movable_box_storage_copy_assign(movable_box_storage_copy_assign&&) =
default;
158 movable_box_storage_copy_assign& operator=(
const movable_box_storage_copy_assign& other)
163 this->emplace(*other);
169 constexpr movable_box_storage_copy_assign& operator=(movable_box_storage_copy_assign&&) =
default;
173 struct movable_box_storage_move_assign : movable_box_storage_copy_assign<T> {
174 using base = movable_box_storage_copy_assign<T>;
177 constexpr movable_box_storage_move_assign() =
default;
178 constexpr movable_box_storage_move_assign(
const movable_box_storage_move_assign&) =
default;
179 constexpr movable_box_storage_move_assign(movable_box_storage_move_assign&&) =
default;
180 constexpr movable_box_storage_move_assign& operator=(
const movable_box_storage_move_assign&) =
default;
181 constexpr movable_box_storage_move_assign& operator=(movable_box_storage_move_assign&& other) =
default;
185 struct movable_box_storage_move_assign<T, false> : movable_box_storage_copy_assign<T> {
186 using base = movable_box_storage_copy_assign<T>;
189 constexpr movable_box_storage_move_assign() =
default;
190 constexpr movable_box_storage_move_assign(
const movable_box_storage_move_assign&) =
default;
191 constexpr movable_box_storage_move_assign(movable_box_storage_move_assign&&) =
default;
192 constexpr movable_box_storage_move_assign& operator=(
const movable_box_storage_move_assign&) =
default;
193 constexpr movable_box_storage_move_assign& operator=(movable_box_storage_move_assign&& other)
198 this->emplace(std::move(*other));
212 class movable_box :
public detail::movable_box_storage_move_assign<T> {
213 using base = detail::movable_box_storage_move_assign<T>;
Definition: movable_box.hpp:212
constexpr movable_box(const movable_box &)=default
constexpr movable_box()=default
constexpr movable_box(movable_box &&)=default
constexpr movable_box & operator=(movable_box &&)=default
constexpr movable_box & operator=(const movable_box &)=default
constexpr MatrixMulMatrix< E1, E2 > operator*(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: matrix_mul_matrix.hpp:77
std::enable_if_t< std::is_object< T >::value, T * > addressof(T &t) noexcept
Definition: addressof.hpp:33
Definition: matrix.hpp:495
Definition: directory.h:12
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35