30 #ifndef BPSTD_OPTIONAL_HPP
31 #define BPSTD_OPTIONAL_HPP
33 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
35 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
37 #include "detail/config.hpp"
38 #include "detail/enable_overload.hpp"
44 #include <initializer_list>
45 #include <type_traits>
49 BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE
61 template <
typename T,
typename U>
63 std::is_constructible<T, optional<U>&>,
64 std::is_constructible<T, const optional<U>&>,
65 std::is_constructible<T, optional<U>&&>,
66 std::is_constructible<T, const optional<U>&&>,
67 std::is_convertible<optional<U>&, T>,
68 std::is_convertible<const optional<U>&, T>,
69 std::is_convertible<optional<U>&&, T>,
70 std::is_convertible<const optional<U>&&, T>
73 template <
typename T,
typename U>
75 optional_is_convertible<T,U>,
76 std::is_constructible<T, const U&>
79 template <
typename T,
typename U>
81 optional_is_convertible<T,U>,
82 std::is_constructible<T, U&&>
85 template <
typename T,
typename U>
87 std::is_constructible<T, U&&>,
92 template <
typename T,
typename U>
94 optional_is_convertible<T,U>,
95 std::is_assignable<T&, optional<U>&>,
96 std::is_assignable<T&, const optional<U>&>,
97 std::is_assignable<T&, optional<U>&&>,
98 std::is_assignable<T&, const optional<U>&&>
101 template <
typename T,
typename U>
102 using optional_is_copy_convert_assignable =
conjunction<
103 optional_is_convert_assignable<T,U>,
104 std::is_constructible<T, const U&>,
105 std::is_assignable<T&, const U&>
108 template <
typename T,
typename U>
109 using optional_is_move_convert_assignable =
conjunction<
110 optional_is_convert_assignable<T,U>,
111 std::is_constructible<T, U&&>,
112 std::is_assignable<T&, U&&>
115 template <
typename T,
typename U>
118 std::is_constructible<T,U>,
119 std::is_assignable<T,U>,
150 constexpr
explicit nullopt_t(
int) noexcept{}
164 template <
typename T,
bool IsTrivial>
class optional_base;
166 template <
typename T>
167 class optional_base<T,true>
174 constexpr optional_base(nullopt_t) noexcept;
176 template <
typename...Args>
177 constexpr optional_base(in_place_t, Args&&...args)
178 noexcept(std::is_nothrow_constructible<T,Args...>::value);
180 optional_base(optional_base&& other) =
default;
181 optional_base(
const optional_base& other) =
default;
185 optional_base& operator=(optional_base&& other) =
default;
186 optional_base& operator=(
const optional_base& other) =
default;
193 BPSTD_CPP14_CONSTEXPR T* val() noexcept;
194 constexpr const T* val() const noexcept;
196 constexpr
bool contains_value() const noexcept;
203 template <typename...Args>
204 void construct(Args&&...args);
218 template <
typename...Args>
219 constexpr storage_type(in_place_t, Args&&...args)
220 : something(bpstd::forward<Args>(args)...){}
221 constexpr storage_type() : nothing(){}
229 storage_type m_storage;
233 template <
typename T>
234 class optional_base<T,false>
242 optional_base(nullopt_t) noexcept;
244 template <
typename...Args>
245 optional_base(in_place_t, Args&&...args)
246 noexcept(std::is_nothrow_constructible<T,Args...>::value);
248 optional_base(optional_base&& other) =
default;
249 optional_base(
const optional_base& other) =
default;
253 ~optional_base() noexcept(std::is_nothrow_destructible<T>::value);
257 optional_base& operator=(optional_base&& other) = default;
258 optional_base& operator=(const optional_base& other) = default;
266 const T* val() const noexcept;
267 bool contains_value() const noexcept;
274 template <typename...Args>
275 void construct(Args&&...args);
288 template <
typename...Args>
289 storage_type(in_place_t, Args&&...args)
290 : something(bpstd::forward<Args>(args)...){}
291 storage_type() : nothing(){}
300 storage_type m_storage;
339 template <
typename T>
341 : detail::optional_base<T,std::is_trivially_destructible<T>::value>
344 !std::is_void<T>::value,
345 "optional<void> is ill-formed"
348 !std::is_reference<T>::value,
349 "optional<T> is ill-formed"
352 !std::is_abstract<T>::value,
353 "optional of an abstract-type is ill-formed"
356 using base_type = detail::optional_base<T,std::is_trivially_destructible<T>::value>;
391 optional(detail::disable_overload_if_t<std::is_copy_constructible<T>::
value,const
optional&> other) = delete;
409 optional(detail::disable_overload_if_t<std::is_move_constructible<T>::
value,
optional&&> other) = delete;
439 template <typename U,
440 enable_if_t<detail::optional_is_copy_convertible<T,U>::
value && std::is_convertible<const U&, T>::
value>* =
nullptr>
443 template <typename U,
444 enable_if_t<detail::optional_is_copy_convertible<T,U>::
value && !std::is_convertible<const U&, T>::
value>* =
nullptr>
476 template <typename U,
477 enable_if_t<detail::optional_is_move_convertible<T,U>::
value && std::is_convertible<U&&, T>::
value>* =
nullptr>
480 template <typename U,
481 enable_if_t<detail::optional_is_move_convertible<T,U>::
value && !std::is_convertible<U&&, T>::
value>* =
nullptr>
492 template <typename...Args,
493 typename=enable_if_t<std::is_constructible<T,Args...>::
value>>
504 template <typename U, typename...Args,
505 typename=enable_if_t<std::is_constructible<T, std::initializer_list<U>&, Args...>::
value>>
507 std::initializer_list<U> ilist,
529 template <typename U=T,
530 enable_if_t<detail::optional_is_value_convertible<T,U>::
value && std::is_convertible<U&&, T>::
value>* =
nullptr>
533 template <typename U=T,
534 enable_if_t<detail::optional_is_value_convertible<T,U>::
value && !std::is_convertible<U&&, T>::
value>* =
nullptr>
549 optional& operator=(detail::enable_overload_if_t<std::is_copy_constructible<T>::
value && std::is_copy_assignable<T>::
value,const
optional&> other);
550 optional& operator=(detail::disable_overload_if_t<std::is_copy_constructible<T>::
value && std::is_copy_assignable<T>::
value,const
optional&> other) = delete;
561 optional& operator=(detail::enable_overload_if_t<std::is_move_constructible<T>::
value && std::is_move_assignable<T>::
value,
optional&&> other);
562 optional& operator=(detail::disable_overload_if_t<std::is_move_constructible<T>::
value && std::is_move_assignable<T>::
value,
optional&&> other) = delete;
580 template <typename U=T,
581 typename=enable_if_t<detail::optional_is_value_assignable<T,U>::
value>>
619 template <typename U>
620 optional& operator=(enable_if_t<detail::optional_is_copy_convert_assignable<T,U>::
value,const
optional<U>&> other);
658 template <typename U>
659 optional& operator=(enable_if_t<detail::optional_is_move_convert_assignable<T,U>::
value,
optional<U>&&> other);
671 BPSTD_CPP14_CONSTEXPR
value_type* operator->() noexcept;
672 constexpr const
value_type* operator->() const noexcept;
681 BPSTD_CPP14_CONSTEXPR
value_type& operator*() & noexcept;
682 BPSTD_CPP14_CONSTEXPR
value_type&& operator*() && noexcept;
683 constexpr const
value_type& operator*() const& noexcept;
684 constexpr const
value_type&& operator*() const&& noexcept;
691 constexpr explicit operator
bool() const noexcept;
697 constexpr
bool has_value() const noexcept;
729 template <typename U>
731 template <typename U>
749 void reset() noexcept(std::is_nothrow_destructible<T>::
value);
757 template <typename...Args>
767 template <typename U,typename...Args >
768 void emplace(std::initializer_list<U> ilist, Args&&...args);
779 template <typename T>
780 BPSTD_CPP14_CONSTEXPR
bool operator==(const
optional<T>& lhs, const
optional<T>& rhs);
781 template <typename T>
782 BPSTD_CPP14_CONSTEXPR
bool operator!=(const
optional<T>& lhs, const
optional<T>& rhs);
783 template <typename T>
784 BPSTD_CPP14_CONSTEXPR
bool operator<(const
optional<T>& lhs, const
optional<T>& rhs);
785 template <typename T>
786 BPSTD_CPP14_CONSTEXPR
bool operator>(const
optional<T>& lhs, const
optional<T>& rhs);
787 template <typename T>
788 BPSTD_CPP14_CONSTEXPR
bool operator<=(const
optional<T>& lhs, const
optional<T>& rhs);
789 template <typename T>
790 BPSTD_CPP14_CONSTEXPR
bool operator>=(const
optional<T>& lhs, const
optional<T>& rhs);
794 template <typename T>
796 template <typename T>
798 template <typename T>
800 template <typename T>
802 template <typename T>
804 template <typename T>
806 template <typename T>
808 template <typename T>
810 template <typename T>
812 template <typename T>
814 template <typename T>
816 template <typename T>
821 template <typename T>
822 constexpr
bool operator==(const
optional<T>& opt, const T&
value);
823 template <typename T>
824 constexpr
bool operator==(const T&
value, const
optional<T>& opt);
825 template <typename T>
826 constexpr
bool operator!=(const
optional<T>& opt, const T&
value);
827 template <typename T>
828 constexpr
bool operator!=(const T&
value, const
optional<T>& opt);
829 template <typename T>
830 constexpr
bool operator<(const
optional<T>& opt, const T&
value);
831 template <typename T>
832 constexpr
bool operator<(const T&
value, const
optional<T>& opt);
833 template <typename T>
834 constexpr
bool operator>(const
optional<T>& opt, const T&
value);
835 template <typename T>
836 constexpr
bool operator>(const T&
value, const
optional<T>& opt);
837 template <typename T>
838 constexpr
bool operator<=(const
optional<T>& opt, const T&
value);
839 template <typename T>
840 constexpr
bool operator<=(const T&
value, const
optional<T>& opt);
841 template <typename T>
842 constexpr
bool operator>=(const
optional<T>& opt, const T&
value);
843 template <typename T>
844 constexpr
bool operator>=(const T&
value, const
optional<T>& opt);
853 template <typename T>
860 template <typename T, typename... Args >
861 constexpr
optional<T> make_optional(Args&&... args);
869 template <typename T, typename U, typename... Args >
870 constexpr
optional<T> make_optional(std::initializer_list<U> il, Args&&... args);
878 template <typename T>
891 template <typename T>
892 inline BPSTD_INLINE_VISIBILITY constexpr
893 bpstd::detail::optional_base<T,true>
901 template <
typename T>
902 template <
typename...Args>
903 inline BPSTD_INLINE_VISIBILITY constexpr
904 bpstd::detail::optional_base<T,true>::optional_base(in_place_t, Args&&...args)
905 noexcept(std::is_nothrow_constructible<T,Args...>::value)
906 : m_storage(in_place, bpstd::forward<Args>(args)...),
916 template <
typename T>
917 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
918 T* bpstd::detail::optional_base<T,true>::val()
921 return &m_storage.something;
924 template <
typename T>
925 inline BPSTD_INLINE_VISIBILITY constexpr
926 const T* bpstd::detail::optional_base<T,true>::val()
929 return &m_storage.something;
932 template <
typename T>
933 inline BPSTD_INLINE_VISIBILITY constexpr
934 bool bpstd::detail::optional_base<T,true>::contains_value()
944 template <
typename T>
945 template <
typename...Args>
946 inline BPSTD_INLINE_VISIBILITY
947 void bpstd::detail::optional_base<T,true>::construct(Args&&...args)
949 m_storage.something = T(bpstd::forward<Args>(args)...);
953 template <
typename T>
954 inline BPSTD_INLINE_VISIBILITY
955 void bpstd::detail::optional_base<T,true>::destruct()
968 template <
typename T>
969 inline BPSTD_INLINE_VISIBILITY
970 bpstd::detail::optional_base<T,false>
971 ::optional_base(nullopt_t)
978 template <
typename T>
979 template <
typename...Args>
980 inline BPSTD_INLINE_VISIBILITY
981 bpstd::detail::optional_base<T,false>
982 ::optional_base(in_place_t, Args&&...args)
983 noexcept(std::is_nothrow_constructible<T,Args...>::value)
984 : m_storage(in_place, bpstd::forward<Args>(args)...),
992 template <
typename T>
993 inline BPSTD_INLINE_VISIBILITY
994 bpstd::detail::optional_base<T,false>::~optional_base()
995 noexcept(std::is_nothrow_destructible<T>::
value)
998 m_storage.something.~T();
1006 template <
typename T>
1007 inline BPSTD_INLINE_VISIBILITY
1008 T* bpstd::detail::optional_base<T,false>::val()
1011 return &m_storage.something;
1014 template <
typename T>
1015 inline BPSTD_INLINE_VISIBILITY
1016 const T* bpstd::detail::optional_base<T,false>::val()
1019 return &m_storage.something;
1022 template <
typename T>
1023 inline BPSTD_INLINE_VISIBILITY
1024 bool bpstd::detail::optional_base<T,false>::contains_value()
1034 template <
typename T>
1035 template <
typename...Args>
1036 inline BPSTD_INLINE_VISIBILITY
1037 void bpstd::detail::optional_base<T,false>::construct(Args&&...args)
1039 new (&m_storage.something) T(bpstd::forward<Args>(args)...);
1043 template <
typename T>
1044 inline BPSTD_INLINE_VISIBILITY
1045 void bpstd::detail::optional_base<T,false>::destruct()
1048 m_storage.something.~T();
1061 template <
typename T>
1062 inline BPSTD_INLINE_VISIBILITY constexpr
1070 template <
typename T>
1071 inline BPSTD_INLINE_VISIBILITY constexpr
1081 template <
typename T>
1082 inline BPSTD_INLINE_VISIBILITY
1087 if (other.has_value())
1089 base_type::construct(*other);
1093 template <
typename T>
1094 inline BPSTD_INLINE_VISIBILITY
1099 if (other.has_value())
1101 base_type::construct(bpstd::move(*other));
1107 template <
typename T>
1108 template <
typename U,
1109 bpstd::enable_if_t<bpstd::detail::optional_is_copy_convertible<T,U>::value && std::is_convertible<const U&, T>::value>*>
1110 inline BPSTD_INLINE_VISIBILITY
1114 if (other.has_value())
1116 base_type::construct(*other);
1120 template <
typename T>
1121 template <
typename U,
1122 bpstd::enable_if_t<bpstd::detail::optional_is_copy_convertible<T,U>::value && !std::is_convertible<const U&, T>::value>*>
1123 inline BPSTD_INLINE_VISIBILITY
1127 if (other.has_value())
1129 base_type::construct(*other);
1135 template <
typename T>
1136 template <
typename U,
1137 bpstd::enable_if_t<bpstd::detail::optional_is_move_convertible<T,U>::value && std::is_convertible<U&&, T>::value>*>
1138 inline BPSTD_INLINE_VISIBILITY
1142 if (other.has_value())
1144 base_type::construct(bpstd::move(*other));
1147 template <
typename T>
1148 template <
typename U,
1149 bpstd::enable_if_t<bpstd::detail::optional_is_move_convertible<T,U>::value && !std::is_convertible<U&&, T>::value>*>
1150 inline BPSTD_INLINE_VISIBILITY
1154 if (other.has_value())
1156 base_type::construct(bpstd::move(*other));
1160 template <
typename T>
1161 template <
typename...Args,
typename>
1162 inline BPSTD_INLINE_VISIBILITY constexpr
1164 : base_type{ in_place, bpstd::forward<Args>(args)... }
1169 template <
typename T>
1170 template <
typename U,
typename...Args,
typename>
1171 inline BPSTD_INLINE_VISIBILITY constexpr
1174 std::initializer_list<U> ilist,
1176 : base_type{ in_place, ilist, bpstd::forward<Args>(args)... }
1181 template <
typename T>
1182 template <
typename U,
1183 bpstd::enable_if_t<bpstd::detail::optional_is_value_convertible<T,U>::value && std::is_convertible<U&&, T>::value>*>
1184 inline BPSTD_INLINE_VISIBILITY constexpr
1186 : base_type{ in_place, bpstd::forward<U>(
value) }
1191 template <
typename T>
1192 template <
typename U,
1193 bpstd::enable_if_t<bpstd::detail::optional_is_value_convertible<T,U>::value && !std::is_convertible<U&&, T>::value>*>
1194 inline BPSTD_INLINE_VISIBILITY constexpr
1196 : base_type{ in_place, bpstd::forward<U>(
value) }
1203 template <
typename T>
1204 inline BPSTD_INLINE_VISIBILITY
1207 base_type::destruct();
1211 template <
typename T>
1212 inline BPSTD_INLINE_VISIBILITY
1216 if (has_value() && other.has_value()) {
1217 (*base_type::val()) = (*other);
1218 }
else if (has_value()) {
1219 base_type::destruct();
1220 }
else if (other.has_value()) {
1221 base_type::construct(*other);
1227 template <
typename T>
1228 inline BPSTD_INLINE_VISIBILITY
1232 if (has_value() && other.has_value()) {
1233 (*base_type::val()) = bpstd::move(*other);
1234 }
else if (has_value()) {
1235 base_type::destruct();
1236 }
else if (other.has_value()) {
1237 base_type::construct(bpstd::move( *other ));
1243 template <
typename T>
1244 template <
typename U,
typename>
1245 inline BPSTD_INLINE_VISIBILITY
1249 (*base_type::val()) = bpstd::forward<U>(value);
1251 base_type::construct(bpstd::forward<U>(value));
1260 template <
typename T>
1261 inline BPSTD_INLINE_VISIBILITY constexpr
1265 return base_type::contains_value();
1268 template <
typename T>
1269 inline BPSTD_INLINE_VISIBILITY constexpr
1273 return base_type::contains_value();
1278 template <
typename T>
1279 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1284 return base_type::val();
1287 template <
typename T>
1288 inline BPSTD_INLINE_VISIBILITY constexpr
1293 return base_type::val();
1298 template <
typename T>
1299 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1304 return *base_type::val();
1307 template <
typename T>
1308 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1313 return bpstd::move(*base_type::val());
1318 template <
typename T>
1319 inline BPSTD_INLINE_VISIBILITY constexpr
1324 return *base_type::val();
1327 template <
typename T>
1328 inline BPSTD_INLINE_VISIBILITY constexpr
1333 return bpstd::move(*base_type::val());
1338 template <
typename T>
1339 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1344 if (
static_cast<bool>(*
this)) {
1345 return *base_type::val();
1350 template <
typename T>
1351 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1356 if (
static_cast<bool>(*
this)) {
1357 return bpstd::move(*base_type::val());
1359 throw bad_optional_access{};
1364 template <
typename T>
1365 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1370 if (
static_cast<bool>(*
this)) {
1371 return *base_type::val();
1373 throw bad_optional_access{};
1376 template <
typename T>
1377 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1382 if (
static_cast<bool>(*
this)) {
1383 return bpstd::move(*base_type::val());
1385 throw bad_optional_access{};
1390 template <
typename T>
1391 template <
typename U>
1392 inline BPSTD_INLINE_VISIBILITY constexpr
1397 return bool(*
this) ? (*base_type::val()) : bpstd::forward<U>(default_value);
1400 template <
typename T>
1401 template <
typename U>
1402 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1407 return bool(*
this) ? (*base_type::val()) : bpstd::forward<U>(default_value);
1414 template <
typename T>
1415 inline BPSTD_INLINE_VISIBILITY
1420 if (has_value() && other.has_value()){
1421 swap(*base_type::val(), *other);
1422 }
else if (has_value()) {
1423 other = bpstd::move(*
this);
1425 }
else if (other.has_value()) {
1426 *
this = bpstd::move(other);
1431 template <
typename T>
1432 inline BPSTD_INLINE_VISIBILITY
1434 noexcept(std::is_nothrow_destructible<T>::value)
1436 base_type::destruct();
1441 template <
typename T>
1442 template <
typename...Args>
1443 inline BPSTD_INLINE_VISIBILITY
1446 base_type::destruct();
1447 base_type::construct(bpstd::forward<Args>(args)...);
1450 template <
typename T>
1451 template <
typename U,
typename...Args>
1452 inline BPSTD_INLINE_VISIBILITY
1456 base_type::destruct();
1457 base_type::construct(ilist, bpstd::forward<Args>(args)...);
1468 template <
typename T>
1469 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1471 bpstd::operator==(
const optional<T>& lhs,
const optional<T>& rhs)
1473 if (
static_cast<bool>(lhs) !=
static_cast<bool>(rhs)) {
1476 if (!
static_cast<bool>(lhs)) {
1479 return *lhs == *rhs;
1482 template <
typename T>
1483 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1485 bpstd::operator!=(
const optional<T>& lhs,
const optional<T>& rhs)
1487 if (
static_cast<bool>(lhs) !=
static_cast<bool>(rhs)) {
1490 if (!
static_cast<bool>(lhs)) {
1493 return *lhs != *rhs;
1496 template <
typename T>
1497 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1499 bpstd::operator<(
const optional<T>& lhs,
const optional<T>& rhs)
1501 if (!
static_cast<bool>(rhs)) {
1504 if (!
static_cast<bool>(lhs)) {
1510 template <
typename T>
1511 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1513 bpstd::operator>(
const optional<T>& lhs,
const optional<T>& rhs)
1515 if (!
static_cast<bool>(lhs)) {
1518 if (!
static_cast<bool>(rhs)) {
1524 template <
typename T>
1525 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1527 bpstd::operator<=(
const optional<T>& lhs,
const optional<T>& rhs)
1529 if (!
static_cast<bool>(lhs)) {
1532 if (!
static_cast<bool>(rhs)) {
1535 return *lhs <= *rhs;
1538 template <
typename T>
1539 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
1541 bpstd::operator>=(
const optional<T>& lhs,
const optional<T>& rhs)
1543 if (!
static_cast<bool>(rhs)) {
1546 if (!
static_cast<bool>(lhs)) {
1549 return *lhs >= *rhs;
1554 template <
typename T>
1555 inline BPSTD_INLINE_VISIBILITY constexpr
1556 bool bpstd::operator==(
const optional<T>& opt, nullopt_t)
1562 template <
typename T>
1563 inline BPSTD_INLINE_VISIBILITY constexpr
1564 bool bpstd::operator==(nullopt_t,
const optional<T>& opt)
1570 template <
typename T>
1571 inline BPSTD_INLINE_VISIBILITY constexpr
1572 bool bpstd::operator!=(
const optional<T>& opt, nullopt_t)
1575 return static_cast<bool>(opt);
1578 template <
typename T>
1579 inline BPSTD_INLINE_VISIBILITY constexpr
1580 bool bpstd::operator!=(nullopt_t,
const optional<T>& opt)
1583 return static_cast<bool>(opt);
1586 template <
typename T>
1587 inline BPSTD_INLINE_VISIBILITY constexpr
1588 bool bpstd::operator<(
const optional<T>&, nullopt_t)
1594 template <
typename T>
1595 inline BPSTD_INLINE_VISIBILITY constexpr
1596 bool bpstd::operator<(nullopt_t,
const optional<T>& opt)
1599 return static_cast<bool>(opt);
1602 template <
typename T>
1603 inline BPSTD_INLINE_VISIBILITY constexpr
1604 bool bpstd::operator>(
const optional<T>& opt, nullopt_t)
1607 return static_cast<bool>(opt);
1610 template <
typename T>
1611 inline BPSTD_INLINE_VISIBILITY constexpr
1612 bool bpstd::operator>(nullopt_t,
const optional<T>&)
1618 template <
typename T>
1619 inline BPSTD_INLINE_VISIBILITY constexpr
1620 bool bpstd::operator<=(
const optional<T>& opt, nullopt_t)
1626 template <
typename T>
1627 inline BPSTD_INLINE_VISIBILITY constexpr
1628 bool bpstd::operator<=(nullopt_t,
const optional<T>&)
1634 template <
typename T>
1635 inline BPSTD_INLINE_VISIBILITY constexpr
1636 bool bpstd::operator>=(
const optional<T>&, nullopt_t)
1642 template <
typename T>
1643 inline BPSTD_INLINE_VISIBILITY constexpr
1644 bool bpstd::operator>=(nullopt_t,
const optional<T>& opt)
1652 template <
typename T>
1653 inline BPSTD_INLINE_VISIBILITY constexpr
1654 bool bpstd::operator==(
const optional<T>& opt,
const T& value)
1656 return static_cast<bool>(opt) ? *opt == value :
false;
1659 template <
typename T>
1660 inline BPSTD_INLINE_VISIBILITY constexpr
1661 bool bpstd::operator==(
const T& value,
const optional<T>& opt)
1663 return static_cast<bool>(opt) ? value == *opt :
false;
1666 template <
typename T>
1667 inline BPSTD_INLINE_VISIBILITY constexpr
1668 bool bpstd::operator!=(
const optional<T>& opt,
const T& value)
1670 return static_cast<bool>(opt) ? *opt != value :
true;
1673 template <
typename T>
1674 inline BPSTD_INLINE_VISIBILITY constexpr
1675 bool bpstd::operator!=(
const T& value,
const optional<T>& opt)
1677 return static_cast<bool>(opt) ? value != *opt :
true;
1680 template <
typename T>
1681 inline BPSTD_INLINE_VISIBILITY constexpr
1682 bool bpstd::operator<(
const optional<T>& opt,
const T& value)
1684 return static_cast<bool>(opt) ? *opt < value :
true;
1687 template <
typename T>
1688 inline BPSTD_INLINE_VISIBILITY constexpr
1689 bool bpstd::operator<(
const T& value,
const optional<T>& opt)
1691 return static_cast<bool>(opt) ? value < *opt :
false;
1694 template <
typename T>
1695 inline BPSTD_INLINE_VISIBILITY constexpr
1696 bool bpstd::operator>(
const optional<T>& opt,
const T& value)
1698 return static_cast<bool>(opt) ? *opt > value :
false;
1701 template <
typename T>
1702 inline BPSTD_INLINE_VISIBILITY constexpr
1703 bool bpstd::operator>(
const T& value,
const optional<T>& opt)
1705 return static_cast<bool>(opt) ? value > *opt :
true;
1708 template <
typename T>
1709 inline BPSTD_INLINE_VISIBILITY constexpr
1710 bool bpstd::operator<=(
const optional<T>& opt,
const T& value)
1712 return static_cast<bool>(opt) ? *opt <= value :
true;
1715 template <
typename T>
1716 inline BPSTD_INLINE_VISIBILITY constexpr
1717 bool bpstd::operator<=(
const T& value,
const optional<T>& opt)
1719 return static_cast<bool>(opt) ? value <= *opt :
false;
1722 template <
typename T>
1723 inline BPSTD_INLINE_VISIBILITY constexpr
1724 bool bpstd::operator>=(
const optional<T>& opt,
const T& value)
1726 return static_cast<bool>(opt) ? *opt >= value :
false;
1729 template <
typename T>
1730 inline BPSTD_INLINE_VISIBILITY constexpr
1731 bool bpstd::operator>=(
const T& value,
const optional<T>& opt)
1733 return static_cast<bool>(opt) ? value >= *opt :
true;
1740 template <
typename T>
1741 inline BPSTD_INLINE_VISIBILITY constexpr
1744 return optional<decay_t<T>>(bpstd::forward<T>(value));
1747 template <
typename T,
typename... Args >
1748 inline BPSTD_INLINE_VISIBILITY constexpr
1751 return optional<T>(in_place, bpstd::forward<Args>(args)...);
1754 template <
typename T,
typename U,
typename... Args >
1755 inline BPSTD_INLINE_VISIBILITY constexpr
1760 std::forward<std::initializer_list<U>>(il),
1761 std::forward<Args>(args)...
1765 template <
typename T>
1766 inline BPSTD_INLINE_VISIBILITY
1767 void bpstd::swap(optional<T>& lhs, optional<T>& rhs)
1772 BPSTD_COMPILER_DIAGNOSTIC_POSTAMBLE