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>
504 T* p = ::new (&storage.u.value)
T();
505 storage.valid =
true;
514 template <
typename T1>
523 T* p = ::new (&storage.u.value)
T(value1);
524 storage.valid =
true;
533 template <
typename T1,
typename T2>
542 T* p = ::new (&storage.u.value)
T(value1, value2);
543 storage.valid =
true;
552 template <
typename T1,
typename T2,
typename T3>
561 T* p = ::new (&storage.u.value)
T(value1, value2, value3);
562 storage.valid =
true;
571 template <
typename T1,
typename T2,
typename T3,
typename T4>
580 T* p = ::new (&storage.u.value)
T(value1, value2, value3, value4);
581 storage.valid =
true;
606 void construct(
const T& value_)
620 void construct(T&& value_)
632 template <
typename... TArgs>
634 void construct(TArgs&&... args)
678 storage_type storage;
684 template <
typename T>
716 if (
other.has_value())
718 storage.construct(
other.value());
730 if (
other.has_value())
732 storage.construct(etl::move(
other.value()));
743 storage.construct(
value_);
753 storage.construct(etl::move(
value_));
779 if (
other.has_value())
781 storage.construct(
other.value());
801 if (
other.has_value())
803 storage.construct(etl::move(
other.value()));
821 storage.construct(
value_);
833 storage.construct(etl::move(
value_));
847#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
851 return &storage.value;
860#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
864 return &storage.value;
873#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
877 return storage.value;
886#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
890 return storage.value;
900#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
904 return etl::move(storage.value);
913#if ETL_IS_DEBUG_BUILD && !(ETL_USING_CPP20 && ETL_USING_STL)
917 return etl::move(storage.value);
925 bool has_value() const ETL_NOEXCEPT
927 return storage.valid;
934 ETL_EXPLICIT
operator bool()
const
945#if ETL_IS_DEBUG_BUILD
949 return storage.value;
958#if ETL_IS_DEBUG_BUILD
962 return storage.value;
981#if ETL_IS_DEBUG_BUILD
985 return etl::move(storage.value);
994#if ETL_IS_DEBUG_BUILD
998 return etl::move(storage.value);
1004 template <
typename U>
1007 value_or(U&& default_value)
const&
1009 return has_value() ? value() :
etl::forward<T>(default_value);
1015 template <
typename U>
1018 value_or(U&& default_value)&&
1020 return has_value() ? etl::move(value()) :
etl::forward<T>(default_value);
1044#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1049 template <
typename...
TArgs>
1068 T* p = ::new (&storage.value)
T();
1069 storage.valid =
true;
1078 template <
typename T1>
1087 T* p = ::new (&storage.value)
T(value1);
1088 storage.valid =
true;
1097 template <
typename T1,
typename T2>
1106 T* p = ::new (&storage.value)
T(value1, value2);
1107 storage.valid =
true;
1116 template <
typename T1,
typename T2,
typename T3>
1125 T* p = ::new (&storage.value)
T(value1, value2, value3);
1126 storage.valid =
true;
1135 template <
typename T1,
typename T2,
typename T3,
typename T4>
1144 T* p = ::new (&storage.value)
T(value1, value2, value3, value4);
1145 storage.valid =
true;
1168 void construct(
const T&
value_)
1177 void construct(T&& value_)
1184 template <
typename... TArgs>
1186 void construct(TArgs&&... args)
1204 storage_type storage;
1208#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<U>::value, int>::type = 0
1209#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if<!etl::is_pod<U>::value, int>::type = 0
1211#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<T>::value, bool>::type
1212#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL ETL_CONSTEXPR20_STL typename etl::enable_if<!etl::is_pod<T>::value, bool>::type
1221 template <
typename T>
1236 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1246 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1263 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1273 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1294 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1304 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1306 optional(
const optional& other)
1325 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1335 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1337 optional(optional&& other)
1347 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1349 optional(
const T& value_)
1357 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1359 optional(
const T& value_)
1378 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1388 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1390 optional(T&& value_)
1391 : impl_t(
etl::move(value_))
1400 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1412 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1436 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1440 impl_t::operator=(
other);
1448 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1452 impl_t::operator=(other);
1462 impl_t::operator=(
other);
1472 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1476 impl_t::operator=(etl::move(
other));
1484 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1488 impl_t::operator=(etl::move(other));
1498 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1502 impl_t::operator=(value_);
1510 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1514 impl_t::operator=(value_);
1524 impl_t::operator=(
value_);
1534 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1538 impl_t::operator=(etl::move(
value_));
1546 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1550 impl_t::operator=(etl::move(value_));
1562 template <
typename T>
1565 if (
lhs.has_value() !=
rhs.has_value())
1569 else if (!
lhs.has_value() && !
rhs.has_value())
1575 return lhs.value() ==
rhs.value();
1582 template <
typename T>
1585 if (
lhs.has_value() !=
rhs.has_value())
1589 else if (!
lhs.has_value() && !
rhs.has_value())
1595 return lhs.value() ==
rhs.value();
1602 template <
typename T>
1611 template <
typename T>
1620 template <
typename T>
1623 if (!
rhs.has_value())
1627 else if (!
lhs.has_value())
1633 return lhs.value() <
rhs.value();
1640 template <
typename T>
1643 if (!
rhs.has_value())
1647 else if (!
lhs.has_value())
1653 return lhs.value() <
rhs.value();
1660 template <
typename T>
1669 template <
typename T>
1678 template <
typename T>
1687 template <
typename T>
1696 template <
typename T>
1705 template <
typename T>
1714 template <
typename T>
1717 return !
lhs.has_value();
1723 template <
typename T>
1726 return !
lhs.has_value();
1732 template <
typename T>
1735 return !
rhs.has_value();
1741 template <
typename T>
1744 return !
rhs.has_value();
1750 template <
typename T>
1759 template <
typename T>
1768 template <
typename T>
1777 template <
typename T>
1786 template <
typename T>
1795 template <
typename T>
1804 template <
typename T>
1807 return rhs.has_value();
1813 template <
typename T>
1816 return rhs.has_value();
1822 template <
typename T>
1825 return !
lhs.has_value();
1831 template <
typename T>
1834 return !
lhs.has_value();
1840 template <
typename T>
1849 template <
typename T>
1858 template <
typename T>
1861 return lhs.has_value();
1867 template <
typename T>
1870 return lhs.has_value();
1876 template <
typename T>
1885 template <
typename T>
1894 template <
typename T>
1903 template <
typename T>
1912 template <
typename T>
1915 return !
rhs.has_value();
1921 template <
typename T>
1924 return !
rhs.has_value();
1930 template <
typename T,
typename U>
1933 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
1939 template <
typename T,
typename U>
1942 return lhs.has_value() ?
lhs.value() ==
rhs :
false;
1948 template <
typename T,
typename U>
1957 template <
typename T,
typename U>
1966 template <
typename T,
typename U>
1969 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
1975 template <
typename T,
typename U>
1978 return rhs.has_value() ?
rhs.value() ==
lhs :
false;
1984 template <
typename T,
typename U>
1993 template <
typename T,
typename U>
2002 template <
typename T,
typename U>
2005 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2011 template <
typename T,
typename U>
2014 return lhs.has_value() ?
lhs.value() <
rhs :
true;
2020 template <
typename T,
typename U>
2023 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2029 template <
typename T,
typename U>
2032 return rhs.has_value() ?
lhs <
rhs.value() :
false;
2038 template <
typename T,
typename U>
2041 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2047 template <
typename T,
typename U>
2050 return lhs.has_value() ?
lhs.value() <=
rhs :
true;
2056 template <
typename T,
typename U>
2059 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2065 template <
typename T,
typename U>
2068 return rhs.has_value() ?
lhs <=
rhs.value() :
false;
2074 template <
typename T,
typename U>
2077 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2083 template <
typename T,
typename U>
2086 return lhs.has_value() ?
lhs.value() >
rhs :
false;
2092 template <
typename T,
typename U>
2095 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2101 template <
typename T,
typename U>
2104 return rhs.has_value() ?
lhs >
rhs.value() :
true;
2110 template <
typename T,
typename U>
2113 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2119 template <
typename T,
typename U>
2122 return lhs.has_value() ?
lhs.value() >=
rhs :
false;
2128 template <
typename T,
typename U>
2131 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2137 template <
typename T,
typename U>
2140 return rhs.has_value() ?
lhs >=
rhs.value() :
true;
2148 template <
typename T>
2157#if ETL_CPP17_SUPPORTED
2158 template <
typename T>
2159 optional(T) -> optional<T>;
2166template <
typename T>
2172#undef ETL_OPTIONAL_ENABLE_CPP14
2173#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2175#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
2176#undef ETL_OPTIONAL_ENABLE_COMSTEXPR_BOOL_RETURN_CPP20_STL
Definition optional.h:1223
optional(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:1283
optional(const T &value_)
Construct from value type.
Definition optional.h:1367
optional(const optional &other)
Copy constructor.
Definition optional.h:1314
optional & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:1424
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:553
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:572
T & emplace(const T1 &value1)
Definition optional.h:515
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:534
T & emplace()
Definition optional.h:496
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:1117
T & emplace()
Definition optional.h:1060
ETL_CONSTEXPR14 T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:943
ETL_CONSTEXPR14 optional_impl(const T &value_)
Constructor from value type.
Definition optional.h:741
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:969
ETL_CONSTEXPR14 optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:714
ETL_CONSTEXPR14 const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:956
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:1098
ETL_CONSTEXPR14 void reset()
Reset back to invalid.
Definition optional.h:1039
ETL_CONSTEXPR14 void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:1028
ETL_CONSTEXPR14 optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:704
ETL_CONSTEXPR14 optional_impl()
Constructor.
Definition optional.h:695
T & emplace(const T1 &value1)
Definition optional.h:1079
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:1136
Definition optional.h:106
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
Definition exception.h:47
T * construct_at(T *p)
Definition memory.h:956
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition memory.h:1006
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:2149
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