31#ifndef ETL_OPTIONAL_INCLUDED
32#define ETL_OPTIONAL_INCLUDED
70 void operator&()
const ETL_DELETE;
87 optional_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
88 :
exception(reason_, file_name_, line_number_)
97 class optional_invalid :
public optional_exception
101 optional_invalid(string_type file_name_, numeric_type line_number_)
102 : optional_exception(
"optional:invalid", file_name_, line_number_)
110 namespace private_optional
112 template <typename T, bool UseFundamentalPath = etl::is_fundamental<T>::value && !etl::is_const<T>::value>
118 template <
typename T>
123 typedef T value_type;
152 if (other.has_value())
154 storage.construct(other.value());
166 if (other.has_value())
168 storage.construct(etl::move(other.value()));
177 template <
typename U,
178 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type,
etl::in_place_t>::value
179 && !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
181 ETL_CONSTEXPR20_STL optional_impl(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
183 storage.construct(etl::forward<U>(value_));
189 template <
typename... TArgs>
190 ETL_CONSTEXPR20_STL optional_impl(etl::in_place_t, TArgs&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, TArgs...>::value))
192 storage.construct(etl::forward<TArgs>(args)...);
195 #if ETL_HAS_INITIALIZER_LIST
199 template <
typename U,
typename... TArgs >
200 ETL_CONSTEXPR20_STL optional_impl(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
201 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<U>&, TArgs...>::value))
203 storage.construct(ilist, etl::forward<TArgs>(args)...);
239 if (other.has_value())
241 storage.construct(other.value());
261 if (other.has_value())
263 storage.construct(etl::move(other.value()));
279 template <
typename U,
280 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
282 ETL_CONSTEXPR20_STL optional_impl& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
284 storage.construct(etl::forward<U>(value_));
292 storage.construct(value_);
306#if ETL_IS_DEBUG_BUILD
310 return &storage.u.value;
319#if ETL_IS_DEBUG_BUILD
323 return &storage.u.value;
332#if ETL_IS_DEBUG_BUILD
336 return storage.u.value;
345#if ETL_IS_DEBUG_BUILD
349 return storage.u.value;
359 #if ETL_IS_DEBUG_BUILD
363 return etl::move(storage.u.value);
372 #if ETL_IS_DEBUG_BUILD
376 return etl::move(storage.u.value);
384 bool has_value() const ETL_NOEXCEPT
386 return storage.valid;
392 ETL_CONSTEXPR20_STL ETL_EXPLICIT
operator bool()
const
403#if ETL_IS_DEBUG_BUILD
407 return storage.u.value;
414 const T&
value() const ETL_LVALUE_REF_QUALIFIER
416#if ETL_IS_DEBUG_BUILD
420 return storage.u.value;
427 T
value_or(
const T& default_value)
const ETL_LVALUE_REF_QUALIFIER
429 return has_value() ?
value() : default_value;
439 #if ETL_IS_DEBUG_BUILD
443 return etl::move(storage.u.value);
450 const T&& value() const&&
452 #if ETL_IS_DEBUG_BUILD
456 return etl::move(storage.u.value);
462 template <
typename U>
463 ETL_CONSTEXPR20_STL etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value)
const&
465 return has_value() ? value() : static_cast<T>(
etl::forward<U>(default_value));
471 template <
typename U>
472 ETL_CONSTEXPR20_STL etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
474 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
485 *
this = ETL_MOVE(other);
486 other = ETL_MOVE(temp);
498#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
502 template <
typename... Args>
503 ETL_CONSTEXPR20_STL T& emplace(Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
505 storage.construct(etl::forward<Args>(args)...);
507 return storage.u.value;
510 #if ETL_HAS_INITIALIZER_LIST
514 template <
typename U,
typename... Args,
515 typename etl::enable_if< etl::is_constructible<T, std::initializer_list<U>&, Args...>::value,
int>
::type = 0 >
516 ETL_CONSTEXPR20_STL T& emplace(std::initializer_list<U>
ilist, Args&&... args)
517 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<U>&, Args...>::value))
519 storage.construct(
ilist, etl::forward<Args>(args)...);
521 return storage.u.value;
537 T* p = ::new (&storage.u.value) T();
538 storage.valid =
true;
547 template <
typename T1>
548 T&
emplace(
const T1& value1) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, T1>::value))
556 T* p = ::new (&storage.u.value) T(value1);
557 storage.valid =
true;
566 template <
typename T1,
typename T2>
567 T&
emplace(
const T1& value1,
const T2& value2) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, T1, T2>::value))
575 T* p = ::new (&storage.u.value) T(value1, value2);
576 storage.valid =
true;
585 template <
typename T1,
typename T2,
typename T3>
586 T&
emplace(
const T1& value1,
const T2& value2,
const T3& value3) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, T1, T2, T3>::value))
594 T* p = ::new (&storage.u.value) T(value1, value2, value3);
595 storage.valid =
true;
604 template <
typename T1,
typename T2,
typename T3,
typename T4>
605 T&
emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4)
606 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, T1, T2, T3, T4>::value))
614 T* p = ::new (&storage.u.value) T(value1, value2, value3, value4);
615 storage.valid =
true;
632 typedef typename etl::remove_const<T>::type* pointer_type;
644 void construct(
const T& value_)
655 void construct(T&& value_)
664 template <
typename... TArgs>
665 ETL_CONSTEXPR20_STL
void construct(TArgs&&... args)
669 etl::construct_at(
const_cast<pointer_type
>(&u.value), etl::forward<TArgs>(args)...);
704 storage_type storage;
710 template <
typename T>
715 typedef T value_type;
741 if (other.has_value())
743 storage.construct(other.value());
754 if (other.has_value())
756 storage.construct(etl::move(other.value()));
763 ETL_CONSTEXPR14 optional_impl(
const T& value_) ETL_NOEXCEPT
765 storage.construct(value_);
771 ETL_CONSTEXPR14 optional_impl(T&& value_) ETL_NOEXCEPT
773 storage.construct(etl::move(value_));
779 template <
typename... TArgs>
780 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, TArgs&&... args) ETL_NOEXCEPT
782 storage.construct(etl::forward<TArgs>(args)...);
785 #if ETL_HAS_INITIALIZER_LIST
789 template <
typename U,
typename... TArgs >
790 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args) ETL_NOEXCEPT
792 storage.construct(ilist, etl::forward<TArgs>(args)...);
817 if (other.has_value())
819 storage.construct(other.value());
838 if (other.has_value())
840 storage.construct(etl::move(other.value()));
857 storage.construct(value_);
866 ETL_CONSTEXPR14
optional_impl& operator=(T&& value_) ETL_NOEXCEPT
868 storage.construct(etl::move(value_));
881#if ETL_IS_DEBUG_BUILD
885 return &storage.value;
893#if ETL_IS_DEBUG_BUILD
897 return &storage.value;
905#if ETL_IS_DEBUG_BUILD
909 return storage.value;
915 ETL_CONSTEXPR14
const T&
operator*() const ETL_LVALUE_REF_QUALIFIER
917#if ETL_IS_DEBUG_BUILD
921 return storage.value;
930 #if ETL_IS_DEBUG_BUILD
934 return etl::move(storage.value);
940 ETL_CONSTEXPR14
const T&&
operator*() const&&
942 #if ETL_IS_DEBUG_BUILD
946 return etl::move(storage.value);
953 ETL_CONSTEXPR14
bool has_value() const ETL_NOEXCEPT
955 return storage.valid;
961 ETL_CONSTEXPR14 ETL_EXPLICIT
operator bool()
const
969 ETL_CONSTEXPR14 T&
value() ETL_LVALUE_REF_QUALIFIER
971#if ETL_IS_DEBUG_BUILD
975 return storage.value;
981 ETL_CONSTEXPR14
const T&
value() const ETL_LVALUE_REF_QUALIFIER
983#if ETL_IS_DEBUG_BUILD
987 return storage.value;
993 ETL_CONSTEXPR14 T
value_or(
const T& default_value)
const ETL_LVALUE_REF_QUALIFIER
995 return has_value() ?
value() : default_value;
1002 ETL_CONSTEXPR14 T&& value() &&
1004 #if ETL_IS_DEBUG_BUILD
1008 return etl::move(storage.value);
1014 ETL_CONSTEXPR14
const T&& value() const&&
1016 #if ETL_IS_DEBUG_BUILD
1020 return etl::move(storage.value);
1026 template <
typename U>
1027 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value)
const&
1029 return has_value() ? value() : static_cast<T>(
etl::forward<U>(default_value));
1035 template <
typename U>
1036 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
1038 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
1055 ETL_CONSTEXPR14
void reset() ETL_NOEXCEPT
1060#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1065 template <
typename... TArgs>
1066 ETL_CONSTEXPR14 T& emplace(TArgs&&... args) ETL_NOEXCEPT
1068 storage.construct(etl::forward<TArgs>(args)...);
1070 return storage.value;
1085 T* p = ::new (&storage.value) T();
1086 storage.valid =
true;
1095 template <
typename T1>
1104 T* p = ::new (&storage.value) T(value1);
1105 storage.valid =
true;
1114 template <
typename T1,
typename T2>
1115 T&
emplace(
const T1& value1,
const T2& value2) ETL_NOEXCEPT
1123 T* p = ::new (&storage.value) T(value1, value2);
1124 storage.valid =
true;
1133 template <
typename T1,
typename T2,
typename T3>
1134 T&
emplace(
const T1& value1,
const T2& value2,
const T3& value3) ETL_NOEXCEPT
1142 T* p = ::new (&storage.value) T(value1, value2, value3);
1143 storage.valid =
true;
1152 template <
typename T1,
typename T2,
typename T3,
typename T4>
1153 T&
emplace(
const T1& value1,
const T2& value2,
const T3& value3,
const T4& value4) ETL_NOEXCEPT
1161 T* p = ::new (&storage.value) T(value1, value2, value3, value4);
1162 storage.valid =
true;
1176 ETL_CONSTEXPR14 storage_type()
1183 ETL_CONSTEXPR14
void construct(
const T& value_)
1191 ETL_CONSTEXPR14
void construct(T&& value_)
1198 template <
typename... TArgs>
1199 ETL_CONSTEXPR14
void construct(TArgs&&... args)
1201 value = T(etl::forward<TArgs>(args)...);
1207 ETL_CONSTEXPR14
void destroy()
1216 storage_type storage;
1220#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1221#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if< !etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1223#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 \
1224 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1225#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL \
1226 ETL_CONSTEXPR20_STL \
1227 typename etl::enable_if< !etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1236 template <
typename T>
1245 typedef T value_type;
1246 typedef T* iterator;
1247 typedef const T* const_iterator;
1253 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1254 ETL_CONSTEXPR14 optional() ETL_NOEXCEPT
1262 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1263 ETL_CONSTEXPR20_STL optional() ETL_NOEXCEPT
1268 optional() ETL_NOEXCEPT
1278 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1287 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1322 template <
typename U,
1323 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type,
etl::optional<T>>::value
1324 && !etl::is_same<typename etl::decay<U>::type,
etl::in_place_t>::value
1325 && !etl::is_same<typename etl::decay<U>::type,
etl::nullopt_t>::value
1326 && etl::is_pod<typename etl::remove_cv<T>::type>::value,
1328 ETL_CONSTEXPR14
optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1329 : impl_t(
etl::forward<U>(value_))
1336 template <
typename U,
1337 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type,
etl::optional<T>>::value
1338 && !etl::is_same<typename etl::decay<U>::type,
etl::in_place_t>::value
1339 && !etl::is_same<typename etl::decay<U>::type,
etl::nullopt_t>::value
1340 && !etl::is_pod<typename etl::remove_cv<T>::type>::value,
1342 ETL_CONSTEXPR20_STL optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1343 : impl_t(
etl::forward<U>(value_))
1360 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14,
typename... Args>
1361 ETL_CONSTEXPR14
explicit optional(
etl::in_place_t, Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
1369 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL,
typename... Args>
1370 ETL_CONSTEXPR20_STL
explicit optional(
etl::in_place_t, Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
1371 : impl_t(
etl::in_place_t{},
etl::forward<Args>(args)...)
1375 #if ETL_HAS_INITIALIZER_LIST
1379 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14,
typename... TArgs>
1380 ETL_CONSTEXPR14
explicit optional(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
1381 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<U>&, TArgs...>::value))
1382 : impl_t(etl::in_place_t{}, ilist, etl::forward<TArgs>(args)...)
1389 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL,
typename... TArgs>
1390 ETL_CONSTEXPR20_STL
explicit optional(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
1391 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<U>&, TArgs...>::value))
1392 : impl_t(etl::in_place_t{}, ilist, etl::forward<TArgs>(args)...)
1402 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1403 ETL_CONSTEXPR14 optional&
operator=(etl::nullopt_t) ETL_NOEXCEPT
1413 template <
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1414 ETL_CONSTEXPR20_STL optional&
operator=(etl::nullopt_t) ETL_NOEXCEPT
1439 impl_t::operator=(other);
1449 template <
typename U,
1450 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type,
etl::optional<T>>::value
1451 && !etl::is_same<typename etl::decay<U>::type,
etl::nullopt_t>::value
1452 && etl::is_pod<typename etl::remove_cv<T>::type>::value,
1454 ETL_CONSTEXPR14
optional&
operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1456 impl_t::operator=(etl::forward<U>(value_));
1464 template <
typename U,
1465 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type,
etl::optional<T>>::value
1466 && !etl::is_same<typename etl::decay<U>::type,
etl::nullopt_t>::value
1467 && !etl::is_pod<typename etl::remove_cv<T>::type>::value,
1469 ETL_CONSTEXPR20_STL optional&
operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1471 impl_t::operator=(etl::forward<U>(value_));
1481 impl_t::operator=(value_);
1493 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1500 const_iterator
begin() const ETL_NOEXCEPT
1502 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1511 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1518 const_iterator
end() const ETL_NOEXCEPT
1520 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1529 template <
typename T>
1532 if (lhs.has_value() != rhs.has_value())
1536 else if (!lhs.has_value() && !rhs.has_value())
1542 return lhs.value() == rhs.value();
1549 template <
typename T>
1552 if (lhs.has_value() != rhs.has_value())
1556 else if (!lhs.has_value() && !rhs.has_value())
1562 return lhs.value() == rhs.value();
1569 template <
typename T>
1572 return !(lhs == rhs);
1578 template <
typename T>
1581 return !(lhs == rhs);
1587 template <
typename T>
1590 if (!rhs.has_value())
1594 else if (!lhs.has_value())
1600 return lhs.value() < rhs.value();
1607 template <
typename T>
1610 if (!rhs.has_value())
1614 else if (!lhs.has_value())
1620 return lhs.value() < rhs.value();
1627 template <
typename T>
1630 return !(rhs < lhs);
1636 template <
typename T>
1639 return !(rhs < lhs);
1645 template <
typename T>
1654 template <
typename T>
1663 template <
typename T>
1666 return !(lhs < rhs);
1672 template <
typename T>
1675 return !(lhs < rhs);
1681 template <
typename T>
1684 return !lhs.has_value();
1690 template <
typename T>
1693 return !lhs.has_value();
1699 template <
typename T>
1702 return !rhs.has_value();
1708 template <
typename T>
1711 return !rhs.has_value();
1717 template <
typename T>
1726 template <
typename T>
1735 template <
typename T>
1744 template <
typename T>
1753 template <
typename T>
1762 template <
typename T>
1771 template <
typename T>
1774 return rhs.has_value();
1780 template <
typename T>
1783 return rhs.has_value();
1789 template <
typename T>
1792 return !lhs.has_value();
1798 template <
typename T>
1801 return !lhs.has_value();
1807 template <
typename T>
1816 template <
typename T>
1825 template <
typename T>
1828 return lhs.has_value();
1834 template <
typename T>
1837 return lhs.has_value();
1843 template <
typename T>
1852 template <
typename T>
1861 template <
typename T>
1870 template <
typename T>
1879 template <
typename T>
1882 return !rhs.has_value();
1888 template <
typename T>
1891 return !rhs.has_value();
1897 template <
typename T,
typename U>
1900 return lhs.has_value() ? lhs.value() == rhs :
false;
1906 template <
typename T,
typename U>
1909 return lhs.has_value() ? lhs.value() == rhs :
false;
1915 template <
typename T,
typename U>
1918 return !(lhs == rhs);
1924 template <
typename T,
typename U>
1927 return !(lhs == rhs);
1933 template <
typename T,
typename U>
1936 return rhs.has_value() ? rhs.value() == lhs :
false;
1942 template <
typename T,
typename U>
1945 return rhs.has_value() ? rhs.value() == lhs :
false;
1951 template <
typename T,
typename U>
1954 return !(lhs == rhs);
1960 template <
typename T,
typename U>
1963 return !(lhs == rhs);
1969 template <
typename T,
typename U>
1972 return lhs.has_value() ? lhs.value() < rhs :
true;
1978 template <
typename T,
typename U>
1981 return lhs.has_value() ? lhs.value() < rhs :
true;
1987 template <
typename T,
typename U>
1990 return rhs.has_value() ? lhs < rhs.value() :
false;
1996 template <
typename T,
typename U>
1999 return rhs.has_value() ? lhs < rhs.value() :
false;
2005 template <
typename T,
typename U>
2008 return lhs.has_value() ? lhs.value() <= rhs :
true;
2014 template <
typename T,
typename U>
2017 return lhs.has_value() ? lhs.value() <= rhs :
true;
2023 template <
typename T,
typename U>
2026 return rhs.has_value() ? lhs <= rhs.value() :
false;
2032 template <
typename T,
typename U>
2035 return rhs.has_value() ? lhs <= rhs.value() :
false;
2041 template <
typename T,
typename U>
2044 return lhs.has_value() ? lhs.value() > rhs :
false;
2050 template <
typename T,
typename U>
2053 return lhs.has_value() ? lhs.value() > rhs :
false;
2059 template <
typename T,
typename U>
2062 return rhs.has_value() ? lhs > rhs.value() :
true;
2068 template <
typename T,
typename U>
2071 return rhs.has_value() ? lhs > rhs.value() :
true;
2077 template <
typename T,
typename U>
2080 return lhs.has_value() ? lhs.value() >= rhs :
false;
2086 template <
typename T,
typename U>
2089 return lhs.has_value() ? lhs.value() >= rhs :
false;
2095 template <
typename T,
typename U>
2098 return rhs.has_value() ? lhs >= rhs.value() :
true;
2104 template <
typename T,
typename U>
2107 return rhs.has_value() ? lhs >= rhs.value() :
true;
2112#if ETL_CPP11_SUPPORTED
2116 template <
typename T,
typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
2118 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<
typename etl::decay<T>::type, T&&>::value))
2122 template <
typename T,
typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
2123 ETL_CONSTEXPR20_STL etl::optional<typename etl::decay<T>::type>
make_optional(T&& value)
2124 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<
typename etl::decay<T>::type, T&&>::value))
2126 return etl::optional<typename etl::decay<T>::type>(etl::forward<T>(value));
2135 template <
typename T,
typename... Args,
2136 typename etl::enable_if< etl::is_constructible<T, Args...>::value,
int>::type = 0,
2137 typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
2138 ETL_CONSTEXPR14 etl::optional<T>
make_optional(Args&&... args)
2139 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
2141 return etl::optional<T>(etl::in_place_t{}, etl::forward<Args>(args)...);
2143 template <
typename T,
typename... Args,
2144 typename etl::enable_if< etl::is_constructible<T, Args...>::value,
int>::type = 0,
2145 typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
2146 ETL_CONSTEXPR20_STL etl::optional<T>
make_optional(Args&&... args)
2147 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
2149 return etl::optional<T>(etl::in_place_t{}, etl::forward<Args>(args)...);
2152 #if ETL_HAS_INITIALIZER_LIST
2159 template <
typename T,
typename TL,
typename... Args,
2160 typename etl::enable_if< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value,
int>::type = 0,
2161 typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
2162 ETL_CONSTEXPR14 etl::optional<T>
make_optional(std::initializer_list<TL>
ilist, Args&&... args)
2163 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<TL>&, Args...>::value))
2165 return etl::optional<T>(etl::in_place_t{},
ilist, etl::forward<Args>(args)...);
2167 template <
typename T,
typename TL,
typename... Args,
2168 typename etl::enable_if< etl::is_constructible<T, std::initializer_list<TL>&, Args...>::value,
int>::type = 0,
2169 typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
2170 ETL_CONSTEXPR20_STL etl::optional<T>
make_optional(std::initializer_list<TL>
ilist, Args&&... args)
2171 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, std::initializer_list<TL>&, Args...>::value))
2173 return etl::optional<T>(etl::in_place_t{},
ilist, etl::forward<Args>(args)...);
2180 template <
typename T>
2190#if ETL_CPP17_SUPPORTED
2191 template <
typename T>
2192 optional(T) -> optional<T>;
2198 template <
typename T>
2206#undef ETL_OPTIONAL_ENABLE_CPP14
2207#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2209#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14
2210#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
ETL_CONSTEXPR20_STL const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:414
ETL_CONSTEXPR20_STL ~optional_impl() ETL_NOEXCEPT
Destructor.
Definition optional.h:212
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:605
ETL_CONSTEXPR20_STL optional_impl & operator=(const T &value_)
Assignment operator from value type.
Definition optional.h:290
ETL_CONSTEXPR20_STL const T * operator->() const
Pointer operator.
Definition optional.h:317
ETL_CONSTEXPR20_STL optional_impl & operator=(etl::nullopt_t) ETL_NOEXCEPT
Assignment operator from nullopt.
Definition optional.h:221
ETL_CONSTEXPR20_STL const T & operator*() const ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:343
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:427
ETL_CONSTEXPR20_STL optional_impl & operator=(const optional_impl &other) ETL_NOEXCEPT_IF(etl
Assignment operator from optional_impl.
Definition optional.h:235
ETL_CONSTEXPR20_STL void reset() ETL_NOEXCEPT
Reset back to invalid.
Definition optional.h:493
T & emplace(const T1 &value1) ETL_NOEXCEPT_IF((etl
Definition optional.h:548
ETL_CONSTEXPR20_STL void swap(optional_impl &other) ETL_NOEXCEPT_IF(etl
Swaps this value with another.
Definition optional.h:482
T & emplace(const T1 &value1, const T2 &value2) ETL_NOEXCEPT_IF((etl
Definition optional.h:567
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3) ETL_NOEXCEPT_IF((etl
Definition optional.h:586
ETL_CONSTEXPR20_STL T & operator*() ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:330
ETL_CONSTEXPR20_STL optional_impl() ETL_NOEXCEPT
Constructor.
Definition optional.h:130
ETL_CONSTEXPR20_STL optional_impl(etl::nullopt_t) ETL_NOEXCEPT
Constructor with nullopt.
Definition optional.h:139
ETL_CONSTEXPR20_STL optional_impl(const optional_impl &other) ETL_NOEXCEPT_IF(etl
Copy constructor.
Definition optional.h:150
T & emplace() ETL_NOEXCEPT_IF((etl
Definition optional.h:529
ETL_CONSTEXPR20_STL T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:401
ETL_CONSTEXPR20_STL T * operator->()
Pointer operator.
Definition optional.h:304
T & emplace() ETL_NOEXCEPT
Definition optional.h:1077
ETL_CONSTEXPR14 T * operator->()
Pointer operator.
Definition optional.h:879
ETL_CONSTEXPR14 const T * operator->() const
Pointer operator.
Definition optional.h:891
ETL_CONSTEXPR14 optional_impl() ETL_NOEXCEPT
Constructor.
Definition optional.h:721
T & emplace(const T1 &value1, const T2 &value2) ETL_NOEXCEPT
Definition optional.h:1115
ETL_CONSTEXPR14 T & operator*() ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:903
ETL_CONSTEXPR14 optional_impl(const optional_impl &other) ETL_NOEXCEPT
Copy constructor.
Definition optional.h:739
ETL_CONSTEXPR14 T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:969
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:993
ETL_CONSTEXPR14 optional_impl & operator=(const optional_impl &other) ETL_NOEXCEPT
Assignment operator from optional_impl.
Definition optional.h:813
ETL_CONSTEXPR14 const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:981
ETL_CONSTEXPR14 const T & operator*() const ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:915
ETL_CONSTEXPR14 void reset() ETL_NOEXCEPT
Reset back to invalid.
Definition optional.h:1055
ETL_CONSTEXPR14 void swap(optional_impl &other) ETL_NOEXCEPT
Swaps this value with another.
Definition optional.h:1045
ETL_CONSTEXPR14 optional_impl(etl::nullopt_t) ETL_NOEXCEPT
Constructor with nullopt.
Definition optional.h:729
T & emplace(const T1 &value1) ETL_NOEXCEPT
Definition optional.h:1096
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3) ETL_NOEXCEPT
Definition optional.h:1134
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4) ETL_NOEXCEPT
Definition optional.h:1153
ETL_CONSTEXPR14 optional_impl & operator=(etl::nullopt_t) ETL_NOEXCEPT
Assignment operator from nullopt.
Definition optional.h:800
ETL_CONSTEXPR14 optional_impl & operator=(const T &value_) ETL_NOEXCEPT
Assignment operator from value type.
Definition optional.h:855
Definition optional.h:113
Make this a clone of the supplied priority queue.
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
T * construct_at(T *p)
Definition memory.h:1751
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition memory.h:1819
optional & operator=(const optional &other)
Assignment operator from optional.
Definition optional.h:1437
optional & operator=(etl::nullopt_t) ETL_NOEXCEPT
Assignment operator from nullopt.
Definition optional.h:1424
optional(etl::nullopt_t) ETL_NOEXCEPT
Constructor with nullopt.
Definition optional.h:1296
ETL_CONSTEXPR20_STL const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the optional.
Definition optional.h:1500
ETL_CONSTEXPR20_STL iterator begin() ETL_NOEXCEPT
Returns an iterator to the beginning of the optional.
Definition optional.h:1491
ETL_CONSTEXPR20_STL iterator end() ETL_NOEXCEPT
Returns an iterator to the end of the optional.
Definition optional.h:1509
optional & operator=(const T &value_)
Assignment operator from value type.
Definition optional.h:1479
optional(const T &value_)
Construct from value type.
Definition optional.h:1350
optional(const optional &other)
Copy constructor.
Definition optional.h:1309
ETL_CONSTEXPR20_STL const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the optional.
Definition optional.h:1518
Definition optional.h:1238
const nullopt_t nullopt
Definition optional.h:77
ETL_CONSTEXPR14 void swap(etl::typed_storage_ext< T > &lhs, etl::typed_storage_ext< T > &rhs) ETL_NOEXCEPT
Swap two etl::typed_storage_ext.
Definition alignment.h:856
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
ETL_CONSTEXPR20_STL etl::optional< typename etl::decay< T >::type > make_optional(T &value)
Make an optional.
Definition optional.h:2181
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1130
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1144
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
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:541
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1103
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1117
in_place disambiguation tags.
Definition utility.h:941