5 # ifndef VCCC_OPTIONAL_OPTIONAL_H_
6 # define VCCC_OPTIONAL_OPTIONAL_H_
8 # include <type_traits>
42 private internal::optional::move_assign<T>,
43 private internal::optional::check_copy_constructible<T>,
44 private internal::optional::check_move_constructible<T>,
45 private internal::optional::check_copy_assignable<T>,
46 private internal::optional::check_move_assignable<T> {
47 using base = internal::optional::move_assign<T>;
54 "vccc::optional : T must not be a reference type");
55 static_assert(!std::is_same<std::remove_reference_t<std::decay_t<T>>,
nullopt_t>::
value,
56 "vccc::optional : T must not be vccc::nullopt_t");
57 static_assert(!std::is_same<std::remove_reference_t<std::decay_t<T>>,
in_place_t>::
value,
58 "vccc::optional : T must not be vccc::in_place_t");
60 "vccc::optional : T must be destructible");
62 "vccc::optional : T must be an array type");
76 internal::optional::check_constructible<value_type, optional<U>>
::value &&
77 internal::optional::check_convertible <value_type, optional<U>>
::value,
80 this->construct_if(other);
86 internal::optional::check_constructible<value_type, optional<U>>
::value &&
87 internal::optional::check_convertible <value_type, optional<U>>
::value &&
91 this->construct_if(other);
97 internal::optional::check_constructible<value_type, optional<U>>
::value &&
98 internal::optional::check_convertible <value_type, optional<U>>
::value,
101 this->construct_if(std::move(other));
107 internal::optional::check_constructible<value_type, optional<U>>
::value &&
108 internal::optional::check_convertible <value_type, optional<U>>
::value &&
112 this->construct_if(std::move(other));
116 template<
typename InPlaceT,
124 template<
typename Arg,
typename ...Args,
129 : base(
in_place,
std::forward<Arg>(arg),
std::forward<Args>(args)...) {}
131 template<
typename U,
typename ...Args,
133 std::is_constructible<value_type, std::initializer_list<U>&, Args&&...>
::value,
136 : base(
in_place, ilist,
std::forward<Args>(args)...) {}
177 !std::is_same<std::decay_t<U>, value_type>::
value),
181 this->val = std::forward<U>(
value);
183 this->construct(std::forward<U>(
value));
190 internal::optional::check_constructible<value_type, optional<U>>
::value &&
191 internal::optional::check_convertible <value_type, optional<U>>
::value &&
192 internal::optional::check_assignable <value_type, optional<U>>
::value &&
201 this->construct(*other);
211 internal::optional::check_constructible<value_type, optional<U>>
::value &&
212 internal::optional::check_convertible <value_type, optional<U>>
::value &&
213 internal::optional::check_assignable <value_type, optional<U>>
::value &&
218 if (other.has_value()) {
220 this->val = std::move(*other);
222 this->construct(std::move(*other));
234 constexpr
inline const value_type*
operator->() const noexcept {
return this->pointer(); }
235 constexpr
inline value_type*
operator->() noexcept {
return this->pointer(); }
240 constexpr
inline const value_type&
operator*() const& noexcept {
return this->ref(); }
241 constexpr
inline value_type&
operator*() & noexcept {
return this->ref(); }
242 constexpr
inline const value_type&&
operator*() const&& noexcept {
return std::move(this->ref()); }
243 constexpr
inline value_type&&
operator*() && noexcept {
return std::move(this->ref()); }
246 constexpr
explicit inline operator bool() const noexcept {
255 constexpr
inline value_type&
value() & {
260 constexpr
inline const value_type&
value() const& {
265 constexpr
inline value_type&&
value() && {
268 return std::move(this->ref());
270 constexpr
inline const value_type&&
value() const && {
273 return std::move(this->ref());
282 "vccc::optional<T>::value_or : T must be copy constructible");
284 "vccc::optional<T>::value_or : U&& must be convertible to T");
292 "vccc::optional<T>::value_or : T must be move constructible");
294 "vccc::optional<T>::value_or : U&& must be convertible to T");
303 template<
typename F, std::enable_if_t<
311 template<
typename F, std::enable_if_t<
319 template<
typename F, std::enable_if_t<
323 return vccc::invoke(std::forward<F>(f), std::move(**
this));
327 template<
typename F, std::enable_if_t<
331 return vccc::invoke(std::forward<F>(f), std::move(**
this));
341 using U = std::remove_cv_t<invoke_result_t<F, T&>>;
349 using U = std::remove_cv_t<invoke_result_t<F, const T&>>;
357 using U = std::remove_cv_t<invoke_result_t<F, T>>;
365 using U = std::remove_cv_t<invoke_result_t<F, const T>>;
381 return *
this ? *this : std::forward<F>(f)();
384 move_constructible<T>,
389 return *
this ? std::move(*
this) : std::forward<F>(f)();
397 "vccc::optional<T>::swap : T must be move constructible");
399 if (other.has_value()) {
403 this->construct(std::move(*other));
408 other.construct(**
this);
416 template<
typename Dummy = void,
427 template<
typename Arg,
typename ...Args,
431 value_type&
emplace(Arg&& arg, Args&&... args) {
433 this->construct(std::forward<Arg>(arg), std::forward<Args>(args)...);
437 template<
typename U,
typename ...Args,
439 std::is_constructible<value_type, std::initializer_list<U>&, Args&&...>
::value,
441 value_type&
emplace(std::initializer_list<U> ilist, Args&&... args) {
443 this->construct(ilist, std::forward<Args>(args)...);
451 # if __cplusplus >= 201703
452 template<
class T> optional(T) -> optional<T>;
468 template<
typename T,
typename Arg,
typename ...Args>
473 template<
typename T,
typename U,
typename ...Args>
485 template<
typename T,
typename U >
487 if (
bool(lhs) !=
bool(rhs))
494 template<
typename T,
typename U >
496 if (
bool(lhs) !=
bool(rhs))
503 template<
typename T,
typename U >
512 template<
typename T,
typename U >
521 template<
typename T,
typename U >
530 template<
typename T,
typename U >
605 template<
typename T,
typename U>
607 return bool(opt) ? *opt ==
value :
false;
610 template<
typename T,
typename U>
612 return bool(opt) ?
value == *opt :
false;
615 template<
typename T,
typename U>
617 return bool(opt) ? opt !=
value :
true;
620 template<
typename T,
typename U>
622 return bool(opt) ?
value != opt :
true;
625 template<
typename T,
typename U>
627 return bool(opt) ? opt <
value :
true;
630 template<
typename T,
typename U>
632 return bool(opt) ?
value < opt :
false;
635 template<
typename T,
typename U>
637 return bool(opt) ? opt <=
value :
true;
640 template<
typename T,
typename U>
642 return bool(opt) ?
value <= opt :
false;
645 template<
typename T,
typename U>
647 return bool(opt) ? opt >
value :
false;
650 template<
typename T,
typename U>
652 return bool(opt) ?
value > opt :
true;
655 template<
typename T,
typename U>
657 return bool(opt) ? opt >=
value :
false;
660 template<
typename T,
typename U>
662 return bool(opt) ?
value >= opt :
true;
exception indicating checked access to an optional that doesn't contain a value
Definition: bad_optional_access.h:18
a wrapper that may or may not hold an object
Definition: optional.h:46
constexpr auto and_then(F &&f) const &&
Definition: optional.h:329
constexpr value_type & operator*() &noexcept
Definition: optional.h:241
constexpr value_type value_or(U &&default_value) const &
Definition: optional.h:280
constexpr optional(optional< U > &&other)
Definition: optional.h:100
constexpr optional(in_place_t, std::initializer_list< U > ilist, Args &&... args)
Definition: optional.h:135
constexpr auto and_then(F &&f) const &
Definition: optional.h:313
constexpr value_type * operator->() noexcept
Definition: optional.h:235
constexpr value_type && operator*() &&noexcept
Definition: optional.h:243
value_type & emplace()
Definition: optional.h:421
constexpr auto and_then(F &&f) &
Definition: optional.h:305
constexpr auto transform(F &&f) &
Definition: optional.h:340
constexpr const value_type & operator*() const &noexcept
Definition: optional.h:240
constexpr const value_type & value() const &
Definition: optional.h:260
constexpr const value_type * operator->() const noexcept
Definition: optional.h:234
constexpr auto transform(F &&f) const &&
Definition: optional.h:364
constexpr value_type && value() &&
Definition: optional.h:265
constexpr optional or_else(F &&f) &&
Definition: optional.h:387
constexpr optional() noexcept=default
constexpr bool has_value() const noexcept
Definition: optional.h:249
constexpr optional & operator=(optional const &)=default
constexpr const value_type && operator*() const &&noexcept
Definition: optional.h:242
constexpr auto and_then(F &&f) &&
Definition: optional.h:321
constexpr auto transform(F &&f) &&
Definition: optional.h:356
constexpr value_type value_or(U &&default_value) &&
Definition: optional.h:290
constexpr optional(const optional &other)=default
constexpr optional(InPlaceT)
Definition: optional.h:121
constexpr optional(U &&value)
Definition: optional.h:145
constexpr value_type & value() &
Definition: optional.h:255
optional & operator=(U &&value)
Definition: optional.h:179
constexpr optional(const optional< U > &other)
Definition: optional.h:79
optional & operator=(optional< U > &&other)
Definition: optional.h:217
void swap(optional &other) noexcept(std::is_nothrow_move_constructible< value_type >::value &&vccc::is_nothrow_swappable< value_type >::value)
Definition: optional.h:393
optional & operator=(const optional< U > &other)
Definition: optional.h:196
constexpr const value_type && value() const &&
Definition: optional.h:270
constexpr auto transform(F &&f) const &
Definition: optional.h:348
constexpr optional or_else(F &&f) const &
Definition: optional.h:379
optional & operator=(nullopt_t) noexcept
Definition: optional.h:163
value_type & emplace(Arg &&arg, Args &&... args)
Definition: optional.h:431
constexpr optional(optional &&other)=default
constexpr optional & operator=(optional &&)=default
constexpr optional(in_place_t, Arg &&arg, Args &&... args)
Definition: optional.h:128
value_type & emplace(std::initializer_list< U > ilist, Args &&... args)
Definition: optional.h:441
T value_type
Definition: optional.h:51
constexpr invoke_result_t< F, Args... > invoke(F &&f, Args &&... args) noexcept(is_nothrow_invocable< F, Args... >::value)
Definition: invoke.hpp:38
constexpr optional< std::decay_t< T > > make_optional(T &&value)
Definition: optional.h:459
constexpr bool operator>(const optional< T > &lhs, const optional< U > &rhs)
Definition: optional.h:522
constexpr bool operator<(const optional< T > &lhs, const optional< U > &rhs)
Definition: optional.h:504
constexpr bool operator<=(const optional< T > &lhs, const optional< U > &rhs)
Definition: optional.h:513
constexpr bool operator>=(const optional< T > &lhs, const optional< U > &rhs)
Definition: optional.h:531
void swap(::vccc::optional< T > &lhs, ::vccc::optional< T > &rhs) noexcept(noexcept(lhs.swap(rhs)))
Definition: swap.h:30
typename invoke_result< F, Args... >::type invoke_result_t
Definition: is_invocable.hpp:66
constexpr VCCC_INLINE_OR_STATIC in_place_t in_place
Definition: in_place.hpp:47
Definition: matrix.hpp:495
constexpr std::decay_t< T > default_value()
Definition: sum.hpp:39
Definition: directory.h:12
constexpr bool operator!=(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: mat_expr_operations.hpp:23
constexpr VCCC_INLINE_OR_STATIC detail::element_niebloid< 1 > value
Definition: key_value.hpp:35
constexpr bool operator==(const MatrixBase< E1 > &lhs, const MatrixBase< E2 > &rhs)
Definition: mat_expr_operations.hpp:15
Definition: conjunction.hpp:22
specifies that an object of a type can be copy constructed and move constructed
Definition: copy_constructible.hpp:55
in-place construction tag
Definition: in_place.hpp:25
specifies that a callable type can be invoked with a given set of argument types
Definition: invocable.hpp:52
Definition: is_swappable.hpp:125
Definition: is_specialization.hpp:30
indicator of optional type with uninitialized state
Definition: nullopt_t.h:19