31#ifndef ETL_OPTIONAL_INCLUDED
32#define ETL_OPTIONAL_INCLUDED
70 void operator&()
const ETL_DELETE;
110 namespace private_optional
118 template <
typename T>
123 typedef T value_type;
151 if (
other.has_value())
153 storage.construct(
other.value());
165 if (
other.has_value())
167 storage.construct(etl::move(
other.value()));
177 storage.construct(
value_);
186 storage.construct(etl::move(
value_));
192 template <
typename...
TArgs>
199#if ETL_HAS_INITIALIZER_LIST
203 template <
typename U,
typename...
TArgs >
205 std::initializer_list<U> ilist,
244 if (
other.has_value())
246 storage.construct(
other.value());
266 if (
other.has_value())
268 storage.construct(etl::move(
other.value()));
286 storage.construct(
value_);
298 storage.construct(etl::move(
value_));
312#if ETL_IS_DEBUG_BUILD
316 return &storage.u.value;
323 const T* operator ->()
const
325#if ETL_IS_DEBUG_BUILD
329 return &storage.u.value;
338#if ETL_IS_DEBUG_BUILD
342 return storage.u.value;
351#if ETL_IS_DEBUG_BUILD
355 return storage.u.value;
365#if ETL_IS_DEBUG_BUILD
369 return etl::move(storage.u.value);
378#if ETL_IS_DEBUG_BUILD
382 return etl::move(storage.u.value);
390 bool has_value()
const ETL_NOEXCEPT
392 return storage.valid;
399 ETL_EXPLICIT
operator bool()
const
410#if ETL_IS_DEBUG_BUILD
414 return storage.u.value;
423#if ETL_IS_DEBUG_BUILD
427 return storage.u.value;
446#if ETL_IS_DEBUG_BUILD
450 return etl::move(storage.u.value);
459#if ETL_IS_DEBUG_BUILD
463 return etl::move(storage.u.value);
469 template <
typename U>
480 template <
typename U>
515#if ETL_IS_DEBUG_BUILD
519 storage.construct(
other.value());
521 return storage.u.value;
524#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
531 template <
typename U,
540 return storage.u.value;
551 return storage.u.value;
566 T* p =
::new (&storage.u.value)
T();
567 storage.valid =
true;
576 template <
typename T1>
587 T* p =
::new (&storage.u.value)
T(value1);
588 storage.valid =
true;
597 template <
typename T1,
typename T2>
606 T* p =
::new (&storage.u.value)
T(value1, value2);
607 storage.valid =
true;
616 template <
typename T1,
typename T2,
typename T3>
625 T* p =
::new (&storage.u.value)
T(value1, value2, value3);
626 storage.valid =
true;
635 template <
typename T1,
typename T2,
typename T3,
typename T4>
644 T* p =
::new (&storage.u.value)
T(value1, value2, value3, value4);
645 storage.valid =
true;
660 typedef typename etl::remove_const<T>::type* pointer_type;
672 void construct(
const T& value_)
683 void construct(T&& value_)
692 template <
typename... TArgs>
694 void construct(TArgs&&... args)
735 storage_type storage;
741 template <
typename T>
746 typedef T value_type;
774 if (
other.has_value())
776 storage.construct(
other.value());
788 if (
other.has_value())
790 storage.construct(etl::move(
other.value()));
800 storage.construct(
value_);
809 storage.construct(etl::move(
value_));
815 template <
typename...
TArgs>
822#if ETL_HAS_INITIALIZER_LIST
826 template <
typename U,
typename...
TArgs >
828 std::initializer_list<U> ilist,
858 if (
other.has_value())
860 storage.construct(
other.value());
880 if (
other.has_value())
882 storage.construct(etl::move(
other.value()));
900 storage.construct(
value_);
912 storage.construct(etl::move(
value_));
926#if ETL_IS_DEBUG_BUILD
930 return &storage.value;
937 const T* operator ->()
const
939#if ETL_IS_DEBUG_BUILD
943 return &storage.value;
952#if ETL_IS_DEBUG_BUILD
956 return storage.value;
965#if ETL_IS_DEBUG_BUILD
969 return storage.value;
979#if ETL_IS_DEBUG_BUILD
983 return etl::move(storage.value);
992#if ETL_IS_DEBUG_BUILD
996 return etl::move(storage.value);
1004 bool has_value()
const ETL_NOEXCEPT
1006 return storage.valid;
1024#if ETL_IS_DEBUG_BUILD
1028 return storage.value;
1037#if ETL_IS_DEBUG_BUILD
1041 return storage.value;
1060#if ETL_IS_DEBUG_BUILD
1064 return etl::move(storage.value);
1071 const T&& value()
const&&
1073#if ETL_IS_DEBUG_BUILD
1077 return etl::move(storage.value);
1083 template <
typename U>
1094 template <
typename U>
1129#if ETL_IS_DEBUG_BUILD
1133 storage.construct(
other.value());
1135 return storage.u.value;
1138#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1143 template <
typename...
TArgs>
1149 return storage.value;
1164 T* p =
::new (&storage.value)
T();
1165 storage.valid =
true;
1174 template <
typename T1>
1185 T* p =
::new (&storage.value)
T(value1);
1186 storage.valid =
true;
1195 template <
typename T1,
typename T2>
1204 T* p =
::new (&storage.value)
T(value1, value2);
1205 storage.valid =
true;
1214 template <
typename T1,
typename T2,
typename T3>
1223 T* p =
::new (&storage.value)
T(value1, value2, value3);
1224 storage.valid =
true;
1233 template <
typename T1,
typename T2,
typename T3,
typename T4>
1242 T* p =
::new (&storage.value)
T(value1, value2, value3, value4);
1243 storage.valid =
true;
1266 void construct(
const T& value_)
1275 void construct(T&& value_)
1282 template <
typename... TArgs>
1284 void construct(TArgs&&... args)
1302 storage_type storage;
1306#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1307#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if<!etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1309#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1310#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL ETL_CONSTEXPR20_STL typename etl::enable_if<!etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1319 template <
typename T>
1328 typedef T value_type;
1334 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1344 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1361 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1371 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1392 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1402 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1404 optional(
const optional&
other)
1423 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1433 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1435 optional(optional&&
other)
1445 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1455 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1476 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1486 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1498 template <
typename U =
T, ETL_OPTIONAL_ENABLE_CPP14,
typename...
Args>
1508 template <
typename U =
T, ETL_OPTIONAL_ENABLE_CPP20_STL,
typename...
Args>
1515#if ETL_HAS_INITIALIZER_LIST
1519 template <
typename U =
T, ETL_OPTIONAL_ENABLE_CPP14,
typename...
TArgs>
1522 std::initializer_list<U> ilist,
1531 template <
typename U =
T, ETL_OPTIONAL_ENABLE_CPP20_STL,
typename...
TArgs>
1534 std::initializer_list<U> ilist,
1546 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1558 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1582 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1586 impl_t::operator=(
other);
1594 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1598 impl_t::operator=(
other);
1608 impl_t::operator=(
other);
1618 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1622 impl_t::operator=(etl::move(
other));
1630 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1634 impl_t::operator=(etl::move(
other));
1644 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1648 impl_t::operator=(
value_);
1656 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1660 impl_t::operator=(
value_);
1670 impl_t::operator=(
value_);
1680 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1684 impl_t::operator=(etl::move(
value_));
1692 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1696 impl_t::operator=(etl::move(
value_));
1708 template <
typename T>
1711 if (
lhs.has_value() !=
rhs.has_value())
1715 else if (!
lhs.has_value() && !
rhs.has_value())
1721 return lhs.value() ==
rhs.value();
1728 template <
typename T>
1731 if (
lhs.has_value() !=
rhs.has_value())
1735 else if (!
lhs.has_value() && !
rhs.has_value())
1741 return lhs.value() ==
rhs.value();
1748 template <
typename T>
1757 template <
typename T>
1766 template <
typename T>
1769 if (!
rhs.has_value())
1773 else if (!
lhs.has_value())
1779 return lhs.value() <
rhs.value();
1786 template <
typename T>
1789 if (!
rhs.has_value())
1793 else if (!
lhs.has_value())
1799 return lhs.value() <
rhs.value();
1806 template <
typename T>
1815 template <
typename T>
1824 template <
typename T>
1833 template <
typename T>
1842 template <
typename T>
1851 template <
typename T>
1860 template <
typename T>
1863 return !
lhs.has_value();
1869 template <
typename T>
1872 return !
lhs.has_value();
1878 template <
typename T>
1881 return !
rhs.has_value();
1887 template <
typename T>
1890 return !
rhs.has_value();
1896 template <
typename T>
1905 template <
typename T>
1914 template <
typename T>
1923 template <
typename T>
1932 template <
typename T>
1941 template <
typename T>
1950 template <
typename T>
1953 return rhs.has_value();
1959 template <
typename T>
1962 return rhs.has_value();
1968 template <
typename T>
1971 return !
lhs.has_value();
1977 template <
typename T>
1980 return !
lhs.has_value();
1986 template <
typename T>
1995 template <
typename T>
2004 template <
typename T>
2007 return lhs.has_value();
2013 template <
typename T>
2016 return lhs.has_value();
2022 template <
typename T>
2031 template <
typename T>
2040 template <
typename T>
2049 template <
typename T>
2058 template <
typename T>
2061 return !
rhs.has_value();
2067 template <
typename T>
2070 return !
rhs.has_value();
2076 template <
typename T,
typename U>
2079 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
2085 template <
typename T,
typename U>
2088 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
2094 template <
typename T,
typename U>
2103 template <
typename T,
typename U>
2112 template <
typename T,
typename U>
2115 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
2121 template <
typename T,
typename U>
2124 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
2130 template <
typename T,
typename U>
2139 template <
typename T,
typename U>
2148 template <
typename T,
typename U>
2151 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2157 template <
typename T,
typename U>
2160 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2166 template <
typename T,
typename U>
2169 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2175 template <
typename T,
typename U>
2178 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2184 template <
typename T,
typename U>
2187 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2193 template <
typename T,
typename U>
2196 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2202 template <
typename T,
typename U>
2205 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2211 template <
typename T,
typename U>
2214 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2220 template <
typename T,
typename U>
2223 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2229 template <
typename T,
typename U>
2232 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2238 template <
typename T,
typename U>
2241 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2247 template <
typename T,
typename U>
2250 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2256 template <
typename T,
typename U>
2259 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2265 template <
typename T,
typename U>
2268 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2274 template <
typename T,
typename U>
2277 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2283 template <
typename T,
typename U>
2286 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2294 template <
typename T>
2303#if ETL_CPP17_SUPPORTED
2304 template <
typename T>
2312template <
typename T>
2318#undef ETL_OPTIONAL_ENABLE_CPP14
2319#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2321#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14
2322#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
Definition optional.h:1321
optional(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:1381
optional(const T &value_)
Construct from value type.
Definition optional.h:1465
optional(const optional &other)
Copy constructor.
Definition optional.h:1412
optional & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:1570
Definition optional.h:120
ETL_CONSTEXPR20_STL const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:421
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:617
ETL_CONSTEXPR20_STL optional_impl()
Constructor.
Definition optional.h:130
ETL_CONSTEXPR20_STL void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:493
ETL_CONSTEXPR20_STL optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:139
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:636
etl::enable_if<!etl::is_base_of< this_type, typenameetl::remove_cv< typenameetl::remove_reference< T1 >::type >::type >::value &&!etl::is_same< etl::optional< T >, typenameetl::remove_cv< typenameetl::remove_reference< T1 >::type >::type >::value, T & >::type emplace(const T1 &value1)
Definition optional.h:579
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:434
ETL_CONSTEXPR20_STL ~optional_impl()
Destructor.
Definition optional.h:217
ETL_CONSTEXPR20_STL optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:149
ETL_CONSTEXPR20_STL void reset()
Reset back to invalid.
Definition optional.h:504
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:598
T & emplace()
Definition optional.h:558
ETL_CONSTEXPR20_STL T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:408
Definition optional.h:743
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:1215
T & emplace()
Definition optional.h:1156
ETL_CONSTEXPR14 T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:1022
etl::enable_if<!etl::is_base_of< this_type, typenameetl::remove_cv< typenameetl::remove_reference< T1 >::type >::type >::value &&!etl::is_same< etl::optional< T >, typenameetl::remove_cv< typenameetl::remove_reference< T1 >::type >::type >::value, T & >::type emplace(const T1 &value1)
Definition optional.h:1177
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:1048
ETL_CONSTEXPR14 optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:772
ETL_CONSTEXPR14 const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:1035
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:1196
ETL_CONSTEXPR14 void reset()
Reset back to invalid.
Definition optional.h:1118
ETL_CONSTEXPR14 void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:1107
ETL_CONSTEXPR14 optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:762
ETL_CONSTEXPR14 optional_impl()
Constructor.
Definition optional.h:753
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:1234
Definition optional.h:113
#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
enable_if
Definition type_traits_generator.h:1254
is_base_of
Definition type_traits_generator.h:1315
is_const
Definition type_traits_generator.h:971
is_same
Definition type_traits_generator.h:1104
remove_cv
Definition type_traits_generator.h:1031
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR20_STL etl::optional< typename etl::decay< T >::type > make_optional(T &value)
Make an optional.
Definition optional.h:2295
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
ETL_CONSTEXPR14 enable_if<!etl::is_specialization< TRep2, etl::chrono::duration >::value, etl::chrono::duration< typenameetl::common_type< TRep1, TRep2 >::type, TPeriod1 > >::type operator*(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator *.
Definition duration.h:545
void destroy(const T *const p)
Destroys the object.
Definition variant_pool_generator.h:370
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:315
const nullopt_t nullopt
Definition optional.h:77
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
in_place disambiguation tags.
Definition utility.h:617