31#ifndef ETL_OPTIONAL_INCLUDED
32#define ETL_OPTIONAL_INCLUDED
63 void operator&()
const ETL_DELETE;
103 namespace private_optional
111 template <
typename T>
143 if (
other.has_value())
145 storage.construct(
other.value());
157 if (
other.has_value())
159 storage.construct(etl::move(
other.value()));
170 storage.construct(
value_);
180 storage.construct(etl::move(
value_));
215 if (
other.has_value())
217 storage.construct(
other.value());
237 if (
other.has_value())
239 storage.construct(etl::move(
other.value()));
257 storage.construct(
value_);
269 storage.construct(etl::move(
value_));
283#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
287 return &storage.u.value;
296#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
300 return &storage.u.value;
309#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
313 return storage.u.value;
322#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
326 return storage.u.value;
336#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
340 return etl::move(storage.u.value);
349#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
353 return etl::move(storage.u.value);
361 bool has_value() const ETL_NOEXCEPT
363 return storage.valid;
370 ETL_EXPLICIT
operator bool()
const
381#if ETL_IS_DEBUG_BUILD
385 return storage.u.value;
394#if ETL_IS_DEBUG_BUILD
398 return storage.u.value;
417#if ETL_IS_DEBUG_BUILD
421 return etl::move(storage.u.value);
430#if ETL_IS_DEBUG_BUILD
434 return etl::move(storage.u.value);
440 template <
typename U>
443 value_or(U&& default_value)
const&
445 return has_value() ? value() :
etl::forward<T>(default_value);
451 template <
typename U>
454 value_or(U&& default_value)&&
456 return has_value() ? etl::move(value()) :
etl::forward<T>(default_value);
480#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
485 template <
typename...
TArgs>
491 return storage.u.value;
506 T* p = ::new (&storage.u.value)
T();
507 storage.valid =
true;
516 template <
typename T1>
525 T* p = ::new (&storage.u.value)
T(value1);
526 storage.valid =
true;
535 template <
typename T1,
typename T2>
544 T* p = ::new (&storage.u.value)
T(value1, value2);
545 storage.valid =
true;
554 template <
typename T1,
typename T2,
typename T3>
563 T* p = ::new (&storage.u.value)
T(value1, value2, value3);
564 storage.valid =
true;
573 template <
typename T1,
typename T2,
typename T3,
typename T4>
582 T* p = ::new (&storage.u.value)
T(value1, value2, value3, value4);
583 storage.valid =
true;
608 void construct(
const T& value_)
622 void construct(T&& value_)
634 template <
typename... TArgs>
636 void construct(TArgs&&... args)
680 storage_type storage;
686 template <
typename T>
718 if (
other.has_value())
720 storage.construct(
other.value());
732 if (
other.has_value())
734 storage.construct(etl::move(
other.value()));
745 storage.construct(
value_);
755 storage.construct(etl::move(
value_));
781 if (
other.has_value())
783 storage.construct(
other.value());
803 if (
other.has_value())
805 storage.construct(etl::move(
other.value()));
823 storage.construct(
value_);
835 storage.construct(etl::move(
value_));
849#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
853 return &storage.value;
862#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
866 return &storage.value;
875#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
879 return storage.value;
888#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
892 return storage.value;
902#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
906 return etl::move(storage.value);
915#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
919 return etl::move(storage.value);
927 bool has_value() const ETL_NOEXCEPT
929 return storage.valid;
936 ETL_EXPLICIT
operator bool()
const
947#if ETL_IS_DEBUG_BUILD
951 return storage.value;
960#if ETL_IS_DEBUG_BUILD
964 return storage.value;
983#if ETL_IS_DEBUG_BUILD
987 return etl::move(storage.value);
996#if ETL_IS_DEBUG_BUILD
1000 return etl::move(storage.value);
1006 template <
typename U>
1009 value_or(U&& default_value)
const&
1011 return has_value() ? value() :
etl::forward<T>(default_value);
1017 template <
typename U>
1020 value_or(U&& default_value)&&
1022 return has_value() ? etl::move(value()) :
etl::forward<T>(default_value);
1046#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1051 template <
typename...
TArgs>
1057 return storage.value;
1072 T* p = ::new (&storage.value)
T();
1073 storage.valid =
true;
1082 template <
typename T1>
1091 T* p = ::new (&storage.value)
T(value1);
1092 storage.valid =
true;
1101 template <
typename T1,
typename T2>
1110 T* p = ::new (&storage.value)
T(value1, value2);
1111 storage.valid =
true;
1120 template <
typename T1,
typename T2,
typename T3>
1129 T* p = ::new (&storage.value)
T(value1, value2, value3);
1130 storage.valid =
true;
1139 template <
typename T1,
typename T2,
typename T3,
typename T4>
1148 T* p = ::new (&storage.value)
T(value1, value2, value3, value4);
1149 storage.valid =
true;
1172 void construct(
const T&
value_)
1181 void construct(T&& value_)
1188 template <
typename... TArgs>
1190 void construct(TArgs&&... args)
1208 storage_type storage;
1212#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<U>::value, int>::type = 0
1213#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if<!etl::is_pod<U>::value, int>::type = 0
1215#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<T>::value, bool>::type
1216#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL ETL_CONSTEXPR20_STL typename etl::enable_if<!etl::is_pod<T>::value, bool>::type
1225 template <
typename T>
1240 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1250 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1267 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1277 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1298 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1308 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1310 optional(
const optional& other)
1329 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1339 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1341 optional(optional&& other)
1351 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1353 optional(
const T& value_)
1361 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1363 optional(
const T& value_)
1382 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1392 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1394 optional(T&& value_)
1395 : impl_t(
etl::move(value_))
1404 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1416 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1440 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1444 impl_t::operator=(
other);
1452 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1456 impl_t::operator=(other);
1466 impl_t::operator=(
other);
1476 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1480 impl_t::operator=(etl::move(
other));
1488 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1492 impl_t::operator=(etl::move(other));
1502 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1506 impl_t::operator=(value_);
1514 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1518 impl_t::operator=(value_);
1528 impl_t::operator=(
value_);
1538 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1542 impl_t::operator=(etl::move(
value_));
1550 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1554 impl_t::operator=(etl::move(value_));
1566 template <
typename T>
1569 if (
lhs.has_value() !=
rhs.has_value())
1573 else if (!
lhs.has_value() && !
rhs.has_value())
1579 return lhs.value() ==
rhs.value();
1586 template <
typename T>
1589 if (
lhs.has_value() !=
rhs.has_value())
1593 else if (!
lhs.has_value() && !
rhs.has_value())
1599 return lhs.value() ==
rhs.value();
1606 template <
typename T>
1615 template <
typename T>
1624 template <
typename T>
1627 if (!
rhs.has_value())
1631 else if (!
lhs.has_value())
1637 return lhs.value() <
rhs.value();
1644 template <
typename T>
1647 if (!
rhs.has_value())
1651 else if (!
lhs.has_value())
1657 return lhs.value() <
rhs.value();
1664 template <
typename T>
1673 template <
typename T>
1682 template <
typename T>
1691 template <
typename T>
1700 template <
typename T>
1709 template <
typename T>
1718 template <
typename T>
1721 return !
lhs.has_value();
1727 template <
typename T>
1730 return !
lhs.has_value();
1736 template <
typename T>
1739 return !
rhs.has_value();
1745 template <
typename T>
1748 return !
rhs.has_value();
1754 template <
typename T>
1763 template <
typename T>
1772 template <
typename T>
1781 template <
typename T>
1790 template <
typename T>
1799 template <
typename T>
1808 template <
typename T>
1811 return rhs.has_value();
1817 template <
typename T>
1820 return rhs.has_value();
1826 template <
typename T>
1829 return !
lhs.has_value();
1835 template <
typename T>
1838 return !
lhs.has_value();
1844 template <
typename T>
1853 template <
typename T>
1862 template <
typename T>
1865 return lhs.has_value();
1871 template <
typename T>
1874 return lhs.has_value();
1880 template <
typename T>
1889 template <
typename T>
1898 template <
typename T>
1907 template <
typename T>
1916 template <
typename T>
1919 return !
rhs.has_value();
1925 template <
typename T>
1928 return !
rhs.has_value();
1934 template <
typename T,
typename U>
1937 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
1943 template <
typename T,
typename U>
1946 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
1952 template <
typename T,
typename U>
1961 template <
typename T,
typename U>
1970 template <
typename T,
typename U>
1973 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
1979 template <
typename T,
typename U>
1982 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
1988 template <
typename T,
typename U>
1997 template <
typename T,
typename U>
2006 template <
typename T,
typename U>
2009 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2015 template <
typename T,
typename U>
2018 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2024 template <
typename T,
typename U>
2027 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2033 template <
typename T,
typename U>
2036 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2042 template <
typename T,
typename U>
2045 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2051 template <
typename T,
typename U>
2054 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2060 template <
typename T,
typename U>
2063 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2069 template <
typename T,
typename U>
2072 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2078 template <
typename T,
typename U>
2081 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2087 template <
typename T,
typename U>
2090 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2096 template <
typename T,
typename U>
2099 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2105 template <
typename T,
typename U>
2108 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2114 template <
typename T,
typename U>
2117 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2123 template <
typename T,
typename U>
2126 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2132 template <
typename T,
typename U>
2135 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2141 template <
typename T,
typename U>
2144 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2152 template <
typename T>
2161#if ETL_CPP17_SUPPORTED
2162 template <
typename T>
2163 optional(T) -> optional<T>;
2170template <
typename T>
2176#undef ETL_OPTIONAL_ENABLE_CPP14
2177#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2179#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
2180#undef ETL_OPTIONAL_ENABLE_COMSTEXPR_BOOL_RETURN_CPP20_STL
Definition optional.h:1227
optional(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:1287
optional(const T &value_)
Construct from value type.
Definition optional.h:1371
optional(const optional &other)
Copy constructor.
Definition optional.h:1318
optional & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:1428
ETL_CONSTEXPR20_STL const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:392
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:555
ETL_CONSTEXPR20_STL optional_impl()
Constructor.
Definition optional.h:122
ETL_CONSTEXPR20_STL optional_impl(const T &value_)
Constructor from value type.
Definition optional.h:168
ETL_CONSTEXPR20_STL void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:464
ETL_CONSTEXPR20_STL optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:131
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:574
T & emplace(const T1 &value1)
Definition optional.h:517
ETL_CONSTEXPR20_STL T value_or(const T &default_value) const ETL_LVALUE_REF_QUALIFIER
Gets the value or a default if not valid.
Definition optional.h:405
ETL_CONSTEXPR20_STL ~optional_impl()
Destructor.
Definition optional.h:188
ETL_CONSTEXPR20_STL optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:141
ETL_CONSTEXPR20_STL void reset()
Reset back to invalid.
Definition optional.h:475
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:536
T & emplace()
Definition optional.h:498
ETL_CONSTEXPR20_STL T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:379
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:1121
T & emplace()
Definition optional.h:1064
ETL_CONSTEXPR14 T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:945
ETL_CONSTEXPR14 optional_impl(const T &value_)
Constructor from value type.
Definition optional.h:743
ETL_CONSTEXPR14 T value_or(const T &default_value) const ETL_LVALUE_REF_QUALIFIER
Gets the value or a default if not valid.
Definition optional.h:971
ETL_CONSTEXPR14 optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:716
ETL_CONSTEXPR14 const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:958
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:1102
ETL_CONSTEXPR14 void reset()
Reset back to invalid.
Definition optional.h:1041
ETL_CONSTEXPR14 void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:1030
ETL_CONSTEXPR14 optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:706
ETL_CONSTEXPR14 optional_impl()
Constructor.
Definition optional.h:697
T & emplace(const T1 &value1)
Definition optional.h:1083
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:1140
Definition optional.h:106
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
T * construct_at(T *p)
Definition memory.h:977
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition memory.h:1027
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR20_STL etl::optional< typename etl::decay< T >::type > make_optional(T &value)
Make an optional.
Definition optional.h:2153
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:693
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:705
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
void destroy(const T *const p)
Destroys the object.
Definition variant_pool_generator.h:370
const nullopt_t nullopt
Definition optional.h:70
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:666
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:681
pair holds two objects of arbitrary type
Definition utility.h:164