Embedded Template Library 1.0
Loading...
Searching...
No Matches
optional.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2015 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_OPTIONAL_INCLUDED
32#define ETL_OPTIONAL_INCLUDED
33
34#include "platform.h"
35#include "alignment.h"
36#include "error_handler.h"
37#include "exception.h"
38#include "initializer_list.h"
39#include "memory.h"
40#include "placement_new.h"
41#include "type_traits.h"
42#include "utility.h"
43
44namespace etl
45{
46 //*****************************************************************************
47 // Forward declaration of etl::optional
48 //*****************************************************************************
49 template <typename T>
50 class optional;
51
52 //*****************************************************************************
55 //*****************************************************************************
57 {
58 public:
59
60 // Convertible to any type of null non-member pointer.
61 template <class T>
62 operator T*() const
63 {
64 return 0;
65 }
66
67 private:
68
69 // Can't take address of nullopt.
70 void operator&() const ETL_DELETE;
71 };
72
73 //*****************************************************************************
76 //*****************************************************************************
77 const nullopt_t nullopt = {};
78
79 //***************************************************************************
82 //***************************************************************************
83 class optional_exception : public exception
84 {
85 public:
86
87 optional_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
88 : exception(reason_, file_name_, line_number_)
89 {
90 }
91 };
92
93 //***************************************************************************
96 //***************************************************************************
97 class optional_invalid : public optional_exception
98 {
99 public:
100
101 optional_invalid(string_type file_name_, numeric_type line_number_)
102 : optional_exception("optional:invalid", file_name_, line_number_)
103 {
104 }
105 };
106
107 //*****************************************************************************
108 // Implementations for fundamental and non fundamental types.
109 //*****************************************************************************
110 namespace private_optional
111 {
112 template <typename T, bool UseFundamentalPath = etl::is_fundamental<T>::value && !etl::is_const<T>::value>
114
115 //*****************************************************************************
116 // Implementation for non fundamental types.
117 //*****************************************************************************
118 template <typename T>
119 class optional_impl<T, false>
120 {
121 protected:
122
123 typedef T value_type;
124 typedef optional_impl<T, false> this_type;
125
126 //***************************************************************************
128 //***************************************************************************
129 ETL_CONSTEXPR20_STL
131 : storage()
132 {
133 }
134
135 //***************************************************************************
137 //***************************************************************************
138 ETL_CONSTEXPR20_STL
140 : storage()
141 {
142 }
143
145 //***************************************************************************
147 //***************************************************************************
148 ETL_CONSTEXPR20_STL
150 {
151 if (other.has_value())
152 {
153 storage.construct(other.value());
154 }
155 }
157
158#if ETL_USING_CPP11
159 //***************************************************************************
161 //***************************************************************************
162 ETL_CONSTEXPR20_STL
164 {
165 if (other.has_value())
166 {
167 storage.construct(etl::move(other.value()));
168 }
169 }
170
171 //***************************************************************************
175 //***************************************************************************
176 template <typename U,
177 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
178 && !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
179 int>::type = 0>
180 ETL_CONSTEXPR20_STL optional_impl(U&& value_)
181 {
182 storage.construct(etl::forward<U>(value_));
183 }
184
185 //***************************************************************************
187 //***************************************************************************
188 template <typename... TArgs>
189 ETL_CONSTEXPR20_STL optional_impl(etl::in_place_t, TArgs&&... args)
190 {
191 storage.construct(etl::forward<TArgs>(args)...);
192 }
193
194 #if ETL_HAS_INITIALIZER_LIST
195 //*******************************************
197 //*******************************************
198 template <typename U, typename... TArgs >
199 ETL_CONSTEXPR20_STL optional_impl(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
200 {
201 storage.construct(ilist, etl::forward<TArgs>(args)...);
202 }
203 #endif
204#endif
205
206 //***************************************************************************
208 //***************************************************************************
209 ETL_CONSTEXPR20_STL
211 {
212 storage.destroy();
213 }
214
215 //***************************************************************************
217 //***************************************************************************
218 ETL_CONSTEXPR20_STL
220 {
221 if (has_value())
222 {
223 storage.destroy();
224 }
225
226 return *this;
227 }
228
229 //***************************************************************************
231 //***************************************************************************
232 ETL_CONSTEXPR20_STL
234 {
235 if (this != &other)
236 {
237 if (other.has_value())
238 {
239 storage.construct(other.value());
240 }
241 else
242 {
243 storage.destroy();
244 }
245 }
246
247 return *this;
248 }
249
250#if ETL_USING_CPP11
251 //***************************************************************************
253 //***************************************************************************
254 ETL_CONSTEXPR20_STL
255 optional_impl& operator=(optional_impl&& other)
256 {
257 if (this != &other)
258 {
259 if (other.has_value())
260 {
261 storage.construct(etl::move(other.value()));
262 }
263 else
264 {
265 storage.destroy();
266 }
267 }
268
269 return *this;
270 }
271#endif
272
273 //***************************************************************************
275 //***************************************************************************
276#if ETL_USING_CPP11
277 template <typename U,
278 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, optional_impl>::value,
279 int>::type = 0>
280 ETL_CONSTEXPR20_STL optional_impl& operator=(U&& value_)
281 {
282 storage.construct(etl::forward<U>(value_));
283
284 return *this;
285 }
286#else
287 ETL_CONSTEXPR20_STL
288 optional_impl& operator=(const T& value_)
289 {
290 storage.construct(value_);
291
292 return *this;
293 }
294#endif
295
296 public:
297
298 //***************************************************************************
300 //***************************************************************************
301 ETL_CONSTEXPR20_STL
303 {
304#if ETL_IS_DEBUG_BUILD
305 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
306#endif
307
308 return &storage.u.value;
309 }
310
311 //***************************************************************************
313 //***************************************************************************
314 ETL_CONSTEXPR20_STL
315 const T* operator->() const
316 {
317#if ETL_IS_DEBUG_BUILD
318 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
319#endif
320
321 return &storage.u.value;
322 }
323
324 //***************************************************************************
326 //***************************************************************************
327 ETL_CONSTEXPR20_STL
328 T& operator*() ETL_LVALUE_REF_QUALIFIER
329 {
330#if ETL_IS_DEBUG_BUILD
331 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
332#endif
333
334 return storage.u.value;
335 }
336
337 //***************************************************************************
339 //***************************************************************************
340 ETL_CONSTEXPR20_STL
341 const T& operator*() const ETL_LVALUE_REF_QUALIFIER
342 {
343#if ETL_IS_DEBUG_BUILD
344 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
345#endif
346
347 return storage.u.value;
348 }
349
350#if ETL_USING_CPP11
351 //***************************************************************************
353 //***************************************************************************
354 ETL_CONSTEXPR20_STL
355 T&& operator*() &&
356 {
357 #if ETL_IS_DEBUG_BUILD
358 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
359 #endif
360
361 return etl::move(storage.u.value);
362 }
363
364 //***************************************************************************
366 //***************************************************************************
367 ETL_CONSTEXPR20_STL
368 const T&& operator*() const&&
369 {
370 #if ETL_IS_DEBUG_BUILD
371 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
372 #endif
373
374 return etl::move(storage.u.value);
375 }
376#endif
377
378 //***************************************************************************
379 // Check whether optional contains value
380 //***************************************************************************
381 ETL_CONSTEXPR20_STL
382 bool has_value() const ETL_NOEXCEPT
383 {
384 return storage.valid;
385 }
386
387 //***************************************************************************
389 //***************************************************************************
390 ETL_CONSTEXPR20_STL ETL_EXPLICIT operator bool() const
391 {
392 return has_value();
393 }
394
395 //***************************************************************************
397 //***************************************************************************
398 ETL_CONSTEXPR20_STL
399 T& value() ETL_LVALUE_REF_QUALIFIER
400 {
401#if ETL_IS_DEBUG_BUILD
402 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
403#endif
404
405 return storage.u.value;
406 }
407
408 //***************************************************************************
410 //***************************************************************************
411 ETL_CONSTEXPR20_STL
412 const T& value() const ETL_LVALUE_REF_QUALIFIER
413 {
414#if ETL_IS_DEBUG_BUILD
415 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
416#endif
417
418 return storage.u.value;
419 }
420
421 //***************************************************************************
423 //***************************************************************************
424 ETL_CONSTEXPR20_STL
425 T value_or(const T& default_value) const ETL_LVALUE_REF_QUALIFIER
426 {
427 return has_value() ? value() : default_value;
428 }
429
430#if ETL_USING_CPP11
431 //***************************************************************************
433 //***************************************************************************
434 ETL_CONSTEXPR20_STL
435 T&& value() &&
436 {
437 #if ETL_IS_DEBUG_BUILD
438 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
439 #endif
440
441 return etl::move(storage.u.value);
442 }
443
444 //***************************************************************************
446 //***************************************************************************
447 ETL_CONSTEXPR20_STL
448 const T&& value() const&&
449 {
450 #if ETL_IS_DEBUG_BUILD
451 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
452 #endif
453
454 return etl::move(storage.u.value);
455 }
456
457 //***************************************************************************
459 //***************************************************************************
460 template <typename U>
461 ETL_CONSTEXPR20_STL etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) const&
462 {
463 return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
464 }
465
466 //***************************************************************************
468 //***************************************************************************
469 template <typename U>
470 ETL_CONSTEXPR20_STL etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
471 {
472 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
473 }
474#endif
475
476 //***************************************************************************
478 //***************************************************************************
479 ETL_CONSTEXPR20_STL
480 void swap(optional_impl& other)
481 {
482 optional_impl temp(*this);
483 *this = other;
484 other = temp;
485 }
486
487 //***************************************************************************
489 //***************************************************************************
490 ETL_CONSTEXPR20_STL
491 void reset()
492 {
493 storage.destroy();
494 }
495
496 //*************************************************************************
498 //*************************************************************************
499 ETL_CONSTEXPR20_STL
500 T& emplace(const optional_impl<T>& other)
501 {
502#if ETL_IS_DEBUG_BUILD
503 ETL_ASSERT(other.has_value(), ETL_ERROR(optional_invalid));
504#endif
505
506 storage.construct(other.value());
507
508 return storage.u.value;
509 }
510
511#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
512 //*************************************************************************
517 //*************************************************************************
518 template < typename U, typename... URest,
519 typename etl::enable_if<
520 !etl::is_base_of< optional_impl, typename etl::remove_cv< typename etl::remove_reference<U>::type>::type>::value, int>::type = 0>
521 ETL_CONSTEXPR20_STL T& emplace(U&& first, URest&&... rest)
522 {
523 storage.construct(etl::forward<U>(first), etl::forward<URest>(rest)...);
524
525 return storage.u.value;
526 }
527
528 //*************************************************************************
530 //*************************************************************************
531 ETL_CONSTEXPR20_STL
532 T& emplace()
533 {
534 storage.construct();
535
536 return storage.u.value;
537 }
538#else
539 //*************************************************************************
542 //*************************************************************************
544 {
545 if (has_value())
546 {
547 // Destroy the old one.
548 storage.destroy();
549 }
550
551 T* p = ::new (&storage.u.value) T();
552 storage.valid = true;
553
554 return *p;
555 }
556
557 //*************************************************************************
560 //*************************************************************************
561 template <typename T1>
562 typename etl::enable_if<
563 !etl::is_base_of< this_type, typename etl::remove_cv< typename etl::remove_reference<T1>::type>::type>::value
564 && !etl::is_same< etl::optional<T>, typename etl::remove_cv< typename etl::remove_reference< T1>::type>::type>::value,
565 T&>::type
566 emplace(const T1& value1)
567 {
568 if (has_value())
569 {
570 // Destroy the old one.
571 storage.destroy();
572 }
573
574 T* p = ::new (&storage.u.value) T(value1);
575 storage.valid = true;
576
577 return *p;
578 }
579
580 //*************************************************************************
583 //*************************************************************************
584 template <typename T1, typename T2>
585 T& emplace(const T1& value1, const T2& value2)
586 {
587 if (has_value())
588 {
589 // Destroy the old one.
590 storage.destroy();
591 }
592
593 T* p = ::new (&storage.u.value) T(value1, value2);
594 storage.valid = true;
595
596 return *p;
597 }
598
599 //*************************************************************************
602 //*************************************************************************
603 template <typename T1, typename T2, typename T3>
604 T& emplace(const T1& value1, const T2& value2, const T3& value3)
605 {
606 if (has_value())
607 {
608 // Destroy the old one.
609 storage.destroy();
610 }
611
612 T* p = ::new (&storage.u.value) T(value1, value2, value3);
613 storage.valid = true;
614
615 return *p;
616 }
617
618 //*************************************************************************
621 //*************************************************************************
622 template <typename T1, typename T2, typename T3, typename T4>
623 T& emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
624 {
625 if (has_value())
626 {
627 // Destroy the old one.
628 storage.destroy();
629 }
630
631 T* p = ::new (&storage.u.value) T(value1, value2, value3, value4);
632 storage.valid = true;
633
634 return *p;
635 }
636#endif
637
638 private:
639
640 struct dummy_t
641 {
642 };
643
644 //*************************************
645 // The storage for the optional value.
646 //*************************************
647 struct storage_type
648 {
649 typedef typename etl::remove_const<T>::type* pointer_type;
650
651 //*******************************
652 ETL_CONSTEXPR20_STL
653 storage_type()
654 : u()
655 , valid(false)
656 {
657 }
658
659 //*******************************
660 ETL_CONSTEXPR20_STL
661 void construct(const T& value_)
662 {
663 destroy();
664
665 etl::construct_at(const_cast<pointer_type>(&u.value), value_);
666 valid = true;
667 }
668
669#if ETL_USING_CPP11
670 //*******************************
671 ETL_CONSTEXPR20_STL
672 void construct(T&& value_)
673 {
674 destroy();
675
676 etl::construct_at(const_cast<pointer_type>(&u.value), etl::move(value_));
677 valid = true;
678 }
679
680 //*******************************
681 template <typename... TArgs>
682 ETL_CONSTEXPR20_STL void construct(TArgs&&... args)
683 {
684 destroy();
685
686 etl::construct_at(const_cast<pointer_type>(&u.value), etl::forward<TArgs>(args)...);
687 valid = true;
688 }
689#endif
690
691 //*******************************
692 ETL_CONSTEXPR20_STL
693 void destroy()
694 {
695 if (valid)
696 {
697 etl::destroy_at(const_cast<pointer_type>(&u.value));
698 valid = false;
699 }
700 }
701
702 //*******************************
703 union union_type
704 {
705 ETL_CONSTEXPR20_STL
706 union_type()
707 : dummy()
708 {
709 }
710
711 ETL_CONSTEXPR20_STL
712 ~union_type() {}
713
714 dummy_t dummy;
715 T value;
716 } u;
717
718 bool valid;
719 };
720
721 storage_type storage;
722 };
723
724 //*****************************************************************************
725 // Implementation for fundamental types.
726 //*****************************************************************************
727 template <typename T>
728 class optional_impl<T, true>
729 {
730 protected:
731
732 typedef T value_type;
733 typedef optional_impl<T, true> this_type;
734
735 //***************************************************************************
737 //***************************************************************************
738 ETL_CONSTEXPR14 optional_impl()
739 : storage()
740 {
741 }
742
743 //***************************************************************************
745 //***************************************************************************
747 : storage()
748 {
749 }
750
752 //***************************************************************************
754 //***************************************************************************
755 ETL_CONSTEXPR14 optional_impl(const optional_impl<T>& other)
756 {
757 if (other.has_value())
758 {
759 storage.construct(other.value());
760 }
761 }
763
764#if ETL_USING_CPP11
765 //***************************************************************************
767 //***************************************************************************
768 ETL_CONSTEXPR14 optional_impl(optional_impl&& other)
769 {
770 if (other.has_value())
771 {
772 storage.construct(etl::move(other.value()));
773 }
774 }
775
776 //***************************************************************************
778 //***************************************************************************
779 ETL_CONSTEXPR14 optional_impl(const T& value_)
780 {
781 storage.construct(value_);
782 }
783
784 //***************************************************************************
786 //***************************************************************************
787 ETL_CONSTEXPR14 optional_impl(T&& value_)
788 {
789 storage.construct(etl::move(value_));
790 }
791
792 //***************************************************************************
794 //***************************************************************************
795 template <typename... TArgs>
796 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, TArgs&&... args)
797 {
798 storage.construct(etl::forward<TArgs>(args)...);
799 }
800
801 #if ETL_HAS_INITIALIZER_LIST
802 //*******************************************
804 //*******************************************
805 template <typename U, typename... TArgs >
806 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
807 {
808 storage.construct(ilist, etl::forward<TArgs>(args)...);
809 }
810 #endif
811#endif
812
813 //***************************************************************************
815 //***************************************************************************
817 {
818 if (has_value())
819 {
820 storage.destroy();
821 }
822
823 return *this;
824 }
825
826 //***************************************************************************
828 //***************************************************************************
829 ETL_CONSTEXPR14 optional_impl& operator=(const optional_impl<T>& other)
830 {
831 if (this != &other)
832 {
833 if (other.has_value())
834 {
835 storage.construct(other.value());
836 }
837 else
838 {
839 storage.destroy();
840 }
841 }
842
843 return *this;
844 }
845
846#if ETL_USING_CPP11
847 //***************************************************************************
849 //***************************************************************************
850 ETL_CONSTEXPR14 optional_impl& operator=(optional_impl&& other)
851 {
852 if (this != &other)
853 {
854 if (other.has_value())
855 {
856 storage.construct(etl::move(other.value()));
857 }
858 else
859 {
860 storage.destroy();
861 }
862 }
863
864 return *this;
865 }
866#endif
867
868 //***************************************************************************
870 //***************************************************************************
871 ETL_CONSTEXPR14 optional_impl& operator=(const T& value_)
872 {
873 storage.construct(value_);
874
875 return *this;
876 }
877
878#if ETL_USING_CPP11
879 //***************************************************************************
881 //***************************************************************************
882 ETL_CONSTEXPR14 optional_impl& operator=(T&& value_)
883 {
884 storage.construct(etl::move(value_));
885
886 return *this;
887 }
888#endif
889
890 public:
891
892 //***************************************************************************
894 //***************************************************************************
895 ETL_CONSTEXPR14 T* operator->()
896 {
897#if ETL_IS_DEBUG_BUILD
898 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
899#endif
900
901 return &storage.value;
902 }
903
904 //***************************************************************************
906 //***************************************************************************
907 ETL_CONSTEXPR14 const T* operator->() const
908 {
909#if ETL_IS_DEBUG_BUILD
910 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
911#endif
912
913 return &storage.value;
914 }
915
916 //***************************************************************************
918 //***************************************************************************
919 ETL_CONSTEXPR14 T& operator*() ETL_LVALUE_REF_QUALIFIER
920 {
921#if ETL_IS_DEBUG_BUILD
922 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
923#endif
924
925 return storage.value;
926 }
927
928 //***************************************************************************
930 //***************************************************************************
931 ETL_CONSTEXPR14 const T& operator*() const ETL_LVALUE_REF_QUALIFIER
932 {
933#if ETL_IS_DEBUG_BUILD
934 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
935#endif
936
937 return storage.value;
938 }
939
940#if ETL_USING_CPP11
941 //***************************************************************************
943 //***************************************************************************
944 ETL_CONSTEXPR14 T&& operator*() &&
945 {
946 #if ETL_IS_DEBUG_BUILD
947 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
948 #endif
949
950 return etl::move(storage.value);
951 }
952
953 //***************************************************************************
955 //***************************************************************************
956 ETL_CONSTEXPR14 const T&& operator*() const&&
957 {
958 #if ETL_IS_DEBUG_BUILD
959 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
960 #endif
961
962 return etl::move(storage.value);
963 }
964#endif
965
966 //***************************************************************************
967 // Check whether optional contains value
968 //***************************************************************************
969 ETL_CONSTEXPR14 bool has_value() const ETL_NOEXCEPT
970 {
971 return storage.valid;
972 }
973
974 //***************************************************************************
976 //***************************************************************************
977 ETL_CONSTEXPR14 ETL_EXPLICIT operator bool() const
978 {
979 return has_value();
980 }
981
982 //***************************************************************************
984 //***************************************************************************
985 ETL_CONSTEXPR14 T& value() ETL_LVALUE_REF_QUALIFIER
986 {
987#if ETL_IS_DEBUG_BUILD
988 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
989#endif
990
991 return storage.value;
992 }
993
994 //***************************************************************************
996 //***************************************************************************
997 ETL_CONSTEXPR14 const T& value() const ETL_LVALUE_REF_QUALIFIER
998 {
999#if ETL_IS_DEBUG_BUILD
1000 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
1001#endif
1002
1003 return storage.value;
1004 }
1005
1006 //***************************************************************************
1008 //***************************************************************************
1009 ETL_CONSTEXPR14 T value_or(const T& default_value) const ETL_LVALUE_REF_QUALIFIER
1010 {
1011 return has_value() ? value() : default_value;
1012 }
1013
1014#if ETL_USING_CPP11
1015 //***************************************************************************
1017 //***************************************************************************
1018 ETL_CONSTEXPR14 T&& value() &&
1019 {
1020 #if ETL_IS_DEBUG_BUILD
1021 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
1022 #endif
1023
1024 return etl::move(storage.value);
1025 }
1026
1027 //***************************************************************************
1029 //***************************************************************************
1030 ETL_CONSTEXPR14 const T&& value() const&&
1031 {
1032 #if ETL_IS_DEBUG_BUILD
1033 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
1034 #endif
1035
1036 return etl::move(storage.value);
1037 }
1038
1039 //***************************************************************************
1041 //***************************************************************************
1042 template <typename U>
1043 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) const&
1044 {
1045 return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
1046 }
1047
1048 //***************************************************************************
1050 //***************************************************************************
1051 template <typename U>
1052 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
1053 {
1054 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
1055 }
1056#endif
1057
1058 //***************************************************************************
1060 //***************************************************************************
1061 ETL_CONSTEXPR14 void swap(optional_impl& other)
1062 {
1063 optional_impl temp(*this);
1064 *this = other;
1065 other = temp;
1066 }
1067
1068 //***************************************************************************
1070 //***************************************************************************
1071 ETL_CONSTEXPR14 void reset()
1072 {
1073 storage.destroy();
1074 }
1075
1076 //*************************************************************************
1078 //*************************************************************************
1079 ETL_CONSTEXPR20_STL
1080 T& emplace(const optional_impl<T>& other)
1081 {
1082#if ETL_IS_DEBUG_BUILD
1083 ETL_ASSERT(other.has_value(), ETL_ERROR(optional_invalid));
1084#endif
1085
1086 storage.construct(other.value());
1087
1088 return storage.u.value;
1089 }
1090
1091#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1092 //*************************************************************************
1095 //*************************************************************************
1096 template <typename... TArgs>
1097 ETL_CONSTEXPR14 T& emplace(TArgs&&... args)
1098 {
1099 storage.construct(etl::forward<TArgs>(args)...);
1100
1101 return storage.value;
1102 }
1103#else
1104 //*************************************************************************
1107 //*************************************************************************
1109 {
1110 if (has_value())
1111 {
1112 // Destroy the old one.
1113 storage.destroy();
1114 }
1115
1116 T* p = ::new (&storage.value) T();
1117 storage.valid = true;
1118
1119 return *p;
1120 }
1121
1122 //*************************************************************************
1125 //*************************************************************************
1126 template <typename T1>
1127 typename etl::enable_if<
1128 !etl::is_base_of< this_type, typename etl::remove_cv< typename etl::remove_reference<T1>::type>::type>::value
1129 && !etl::is_same< etl::optional<T>, typename etl::remove_cv< typename etl::remove_reference< T1>::type>::type>::value,
1130 T&>::type
1131 emplace(const T1& value1)
1132 {
1133 if (has_value())
1134 {
1135 // Destroy the old one.
1136 storage.destroy();
1137 }
1138
1139 T* p = ::new (&storage.value) T(value1);
1140 storage.valid = true;
1141
1142 return *p;
1143 }
1144
1145 //*************************************************************************
1148 //*************************************************************************
1149 template <typename T1, typename T2>
1150 T& emplace(const T1& value1, const T2& value2)
1151 {
1152 if (has_value())
1153 {
1154 // Destroy the old one.
1155 storage.destroy();
1156 }
1157
1158 T* p = ::new (&storage.value) T(value1, value2);
1159 storage.valid = true;
1160
1161 return *p;
1162 }
1163
1164 //*************************************************************************
1167 //*************************************************************************
1168 template <typename T1, typename T2, typename T3>
1169 T& emplace(const T1& value1, const T2& value2, const T3& value3)
1170 {
1171 if (has_value())
1172 {
1173 // Destroy the old one.
1174 storage.destroy();
1175 }
1176
1177 T* p = ::new (&storage.value) T(value1, value2, value3);
1178 storage.valid = true;
1179
1180 return *p;
1181 }
1182
1183 //*************************************************************************
1186 //*************************************************************************
1187 template <typename T1, typename T2, typename T3, typename T4>
1188 T& emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4)
1189 {
1190 if (has_value())
1191 {
1192 // Destroy the old one.
1193 storage.destroy();
1194 }
1195
1196 T* p = ::new (&storage.value) T(value1, value2, value3, value4);
1197 storage.valid = true;
1198
1199 return *p;
1200 }
1201#endif
1202
1203 private:
1204
1205 //*************************************
1206 // The storage for the optional value.
1207 //*************************************
1208 struct storage_type
1209 {
1210 //*******************************
1211 ETL_CONSTEXPR14 storage_type()
1212 : value()
1213 , valid(false)
1214 {
1215 }
1216
1217 //*******************************
1218 ETL_CONSTEXPR14 void construct(const T& value_)
1219 {
1220 value = value_;
1221 valid = true;
1222 }
1223
1224#if ETL_USING_CPP11
1225 //*******************************
1226 ETL_CONSTEXPR14 void construct(T&& value_)
1227 {
1228 value = value_;
1229 valid = true;
1230 }
1231
1232 //*******************************
1233 template <typename... TArgs>
1234 ETL_CONSTEXPR14 void construct(TArgs&&... args)
1235 {
1236 value = T(etl::forward<TArgs>(args)...);
1237 valid = true;
1238 }
1239#endif
1240
1241 //*******************************
1242 ETL_CONSTEXPR14 void destroy()
1243 {
1244 valid = false;
1245 }
1246
1247 T value;
1248 bool valid;
1249 };
1250
1251 storage_type storage;
1252 };
1253 } // namespace private_optional
1254
1255#define ETL_OPTIONAL_ENABLE_CPP14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1256#define ETL_OPTIONAL_ENABLE_CPP20_STL typename etl::enable_if< !etl::is_pod<typename etl::remove_cv<U>::type>::value, int>::type = 0
1257
1258#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 \
1259 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1260#define ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL \
1261 ETL_CONSTEXPR20_STL \
1262 typename etl::enable_if< !etl::is_pod<typename etl::remove_cv<T>::type>::value, bool>::type
1263
1264 //*****************************************************************************
1270 //*****************************************************************************
1271 template <typename T>
1272 class optional : public private_optional::optional_impl<T>
1273 {
1274 private:
1275
1277
1278 public:
1279
1280 typedef T value_type;
1281 typedef T* iterator;
1282 typedef const T* const_iterator;
1283
1284#if ETL_USING_CPP11
1285 //***************************************************************************
1287 //***************************************************************************
1288 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1289 ETL_CONSTEXPR14 optional()
1290 : impl_t()
1291 {
1292 }
1293
1294 //***************************************************************************
1296 //***************************************************************************
1297 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1298 ETL_CONSTEXPR20_STL optional()
1299 : impl_t()
1300 {
1301 }
1302#else
1303 optional()
1304 : impl_t()
1305 {
1306 }
1307#endif
1308
1309#if ETL_USING_CPP11
1310 //***************************************************************************
1312 //***************************************************************************
1313 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1314 ETL_CONSTEXPR14 optional(etl::nullopt_t)
1315 : impl_t(etl::nullopt)
1316 {
1317 }
1318
1319 //***************************************************************************
1321 //***************************************************************************
1322 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1323 ETL_CONSTEXPR20_STL optional(etl::nullopt_t)
1324 : impl_t(etl::nullopt)
1325 {
1326 }
1327#else
1328 //***************************************************************************
1330 //***************************************************************************
1332 : impl_t(etl::nullopt)
1333 {
1334 }
1335#endif
1336
1338#if ETL_USING_CPP11
1339 //***************************************************************************
1341 //***************************************************************************
1342 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1343 ETL_CONSTEXPR14 optional(const optional& other)
1344 : impl_t(other)
1345 {
1346 }
1347
1348 //***************************************************************************
1350 //***************************************************************************
1351 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1352 ETL_CONSTEXPR20_STL optional(const optional& other)
1353 : impl_t(other)
1354 {
1355 }
1356#else
1357 //***************************************************************************
1359 //***************************************************************************
1360 optional(const optional& other)
1361 : impl_t(other)
1362 {
1363 }
1364#endif
1365#include "private/diagnostic_pop.h"
1366
1367#if ETL_USING_CPP11
1368 //***************************************************************************
1370 //***************************************************************************
1371 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1372 ETL_CONSTEXPR14 optional(optional&& other)
1373 : impl_t(other)
1374 {
1375 }
1376
1377 //***************************************************************************
1379 //***************************************************************************
1380 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1381 ETL_CONSTEXPR20_STL optional(optional&& other)
1382 : impl_t(other)
1383 {
1384 }
1385#endif
1386
1387#if ETL_USING_CPP11
1388 //***************************************************************************
1392 //***************************************************************************
1393 template < typename U,
1394 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
1395 && !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
1396 && !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
1397 && etl::is_pod<typename etl::remove_cv<T>::type>::value,
1398 int>::type = 0>
1399 ETL_CONSTEXPR14 optional(U&& value_)
1400 : impl_t(etl::forward<U>(value_))
1401 {
1402 }
1403
1404 //***************************************************************************
1406 //***************************************************************************
1407 template < typename U,
1408 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
1409 && !etl::is_same<typename etl::decay<U>::type, etl::in_place_t>::value
1410 && !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
1411 && !etl::is_pod<typename etl::remove_cv<T>::type>::value,
1412 int>::type = 0>
1413 ETL_CONSTEXPR20_STL optional(U&& value_)
1414 : impl_t(etl::forward<U>(value_))
1415 {
1416 }
1417#else
1418 //***************************************************************************
1420 //***************************************************************************
1421 optional(const T& value_)
1422 : impl_t(value_)
1423 {
1424 }
1425#endif
1426
1427#if ETL_USING_CPP11
1428 //***************************************************************************
1430 //***************************************************************************
1431 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14, typename... Args>
1432 ETL_CONSTEXPR14 explicit optional(etl::in_place_t, Args&&... args)
1433 : impl_t(etl::in_place_t{}, etl::forward<Args>(args)...)
1434 {
1435 }
1436
1437 //***************************************************************************
1439 //***************************************************************************
1440 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL, typename... Args>
1441 ETL_CONSTEXPR20_STL explicit optional(etl::in_place_t, Args&&... args)
1442 : impl_t(etl::in_place_t{}, etl::forward<Args>(args)...)
1443 {
1444 }
1445
1446 #if ETL_HAS_INITIALIZER_LIST
1447 //*******************************************
1449 //*******************************************
1450 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14, typename... TArgs>
1451 ETL_CONSTEXPR14 explicit optional(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
1452 : impl_t(etl::in_place_t{}, ilist, etl::forward<TArgs>(args)...)
1453 {
1454 }
1455
1456 //*******************************************
1458 //*******************************************
1459 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL, typename... TArgs>
1460 ETL_CONSTEXPR20_STL explicit optional(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args)
1461 : impl_t(etl::in_place_t{}, ilist, etl::forward<TArgs>(args)...)
1462 {
1463 }
1464 #endif
1465#endif
1466
1467#if ETL_USING_CPP11
1468 //***************************************************************************
1470 //***************************************************************************
1471 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1472 ETL_CONSTEXPR14 optional& operator=(etl::nullopt_t)
1473 {
1474 impl_t::operator=(etl::nullopt);
1475
1476 return *this;
1477 }
1478
1479 //***************************************************************************
1481 //***************************************************************************
1482 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1483 ETL_CONSTEXPR20_STL optional& operator=(etl::nullopt_t)
1484 {
1485 impl_t::operator=(etl::nullopt);
1486
1487 return *this;
1488 }
1489#else
1490 //***************************************************************************
1492 //***************************************************************************
1494 {
1495 impl_t::operator=(etl::nullopt);
1496
1497 return *this;
1498 }
1499#endif
1500
1501#if ETL_USING_CPP11
1502 //***************************************************************************
1504 //***************************************************************************
1505 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1506 ETL_CONSTEXPR14 optional& operator=(const optional& other)
1507 {
1508 impl_t::operator=(other);
1509
1510 return *this;
1511 }
1512
1513 //***************************************************************************
1515 //***************************************************************************
1516 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1517 ETL_CONSTEXPR20_STL optional& operator=(const optional& other)
1518 {
1519 impl_t::operator=(other);
1520
1521 return *this;
1522 }
1523#else
1524 //***************************************************************************
1526 //***************************************************************************
1527 optional& operator=(const optional& other)
1528 {
1529 impl_t::operator=(other);
1530
1531 return *this;
1532 }
1533#endif
1534
1535#if ETL_USING_CPP11
1536 //***************************************************************************
1538 //***************************************************************************
1539 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1540 ETL_CONSTEXPR14 optional& operator=(optional&& other)
1541 {
1542 impl_t::operator=(etl::move(other));
1543
1544 return *this;
1545 }
1546
1547 //***************************************************************************
1549 //***************************************************************************
1550 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1551 ETL_CONSTEXPR20_STL optional& operator=(optional&& other)
1552 {
1553 impl_t::operator=(etl::move(other));
1554
1555 return *this;
1556 }
1557#endif
1558
1559#if ETL_USING_CPP11
1560 //***************************************************************************
1562 //***************************************************************************
1563 template < typename U,
1564 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
1565 && !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
1566 && etl::is_pod<typename etl::remove_cv<T>::type>::value,
1567 int>::type = 0>
1568 ETL_CONSTEXPR14 optional& operator=(U&& value_)
1569 {
1570 impl_t::operator=(etl::forward<U>(value_));
1571
1572 return *this;
1573 }
1574
1575 //***************************************************************************
1577 //***************************************************************************
1578 template < typename U,
1579 typename etl::enable_if< etl::is_constructible<T, U&&>::value && !etl::is_same<typename etl::decay<U>::type, etl::optional<T>>::value
1580 && !etl::is_same<typename etl::decay<U>::type, etl::nullopt_t>::value
1581 && !etl::is_pod<typename etl::remove_cv<T>::type>::value,
1582 int>::type = 0>
1583 ETL_CONSTEXPR20_STL optional& operator=(U&& value_)
1584 {
1585 impl_t::operator=(etl::forward<U>(value_));
1586
1587 return *this;
1588 }
1589#else
1590 //***************************************************************************
1592 //***************************************************************************
1593 optional& operator=(const T& value_)
1594 {
1595 impl_t::operator=(value_);
1596
1597 return *this;
1598 }
1599#endif
1600
1601 //***************************************************************************
1603 //***************************************************************************
1604 ETL_CONSTEXPR20_STL
1605 iterator begin() ETL_NOEXCEPT
1606 {
1607 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1608 }
1609
1610 //***************************************************************************
1612 //***************************************************************************
1613 ETL_CONSTEXPR20_STL
1614 const_iterator begin() const ETL_NOEXCEPT
1615 {
1616 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1617 }
1618
1619 //***************************************************************************
1621 //***************************************************************************
1622 ETL_CONSTEXPR20_STL
1623 iterator end() ETL_NOEXCEPT
1624 {
1625 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1626 }
1627
1628 //***************************************************************************
1630 //***************************************************************************
1631 ETL_CONSTEXPR20_STL
1632 const_iterator end() const ETL_NOEXCEPT
1633 {
1634 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1635 }
1636 };
1637
1639
1640 //***************************************************************************
1642 //***************************************************************************
1643 template <typename T>
1644 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1645 {
1646 if (lhs.has_value() != rhs.has_value())
1647 {
1648 return false;
1649 }
1650 else if (!lhs.has_value() && !rhs.has_value())
1651 {
1652 return true;
1653 }
1654 else
1655 {
1656 return lhs.value() == rhs.value();
1657 }
1658 }
1659
1660 //***************************************************************************
1662 //***************************************************************************
1663 template <typename T>
1664 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1665 {
1666 if (lhs.has_value() != rhs.has_value())
1667 {
1668 return false;
1669 }
1670 else if (!lhs.has_value() && !rhs.has_value())
1671 {
1672 return true;
1673 }
1674 else
1675 {
1676 return lhs.value() == rhs.value();
1677 }
1678 }
1679
1680 //***************************************************************************
1682 //***************************************************************************
1683 template <typename T>
1684 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1685 {
1686 return !(lhs == rhs);
1687 }
1688
1689 //***************************************************************************
1691 //***************************************************************************
1692 template <typename T>
1693 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1694 {
1695 return !(lhs == rhs);
1696 }
1697
1698 //***************************************************************************
1700 //***************************************************************************
1701 template <typename T>
1702 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1703 {
1704 if (!rhs.has_value())
1705 {
1706 return false;
1707 }
1708 else if (!lhs.has_value())
1709 {
1710 return true;
1711 }
1712 else
1713 {
1714 return lhs.value() < rhs.value();
1715 }
1716 }
1717
1718 //***************************************************************************
1720 //***************************************************************************
1721 template <typename T>
1722 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1723 {
1724 if (!rhs.has_value())
1725 {
1726 return false;
1727 }
1728 else if (!lhs.has_value())
1729 {
1730 return true;
1731 }
1732 else
1733 {
1734 return lhs.value() < rhs.value();
1735 }
1736 }
1737
1738 //***************************************************************************
1740 //***************************************************************************
1741 template <typename T>
1742 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1743 {
1744 return !(rhs < lhs);
1745 }
1746
1747 //***************************************************************************
1749 //***************************************************************************
1750 template <typename T>
1751 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1752 {
1753 return !(rhs < lhs);
1754 }
1755
1756 //***************************************************************************
1758 //***************************************************************************
1759 template <typename T>
1760 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1761 {
1762 return (rhs < lhs);
1763 }
1764
1765 //***************************************************************************
1767 //***************************************************************************
1768 template <typename T>
1769 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1770 {
1771 return (rhs < lhs);
1772 }
1773
1774 //***************************************************************************
1776 //***************************************************************************
1777 template <typename T>
1778 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1779 {
1780 return !(lhs < rhs);
1781 }
1782
1783 //***************************************************************************
1785 //***************************************************************************
1786 template <typename T>
1787 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1788 {
1789 return !(lhs < rhs);
1790 }
1791
1792 //***************************************************************************
1794 //***************************************************************************
1795 template <typename T>
1796 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, etl::nullopt_t)
1797 {
1798 return !lhs.has_value();
1799 }
1800
1801 //***************************************************************************
1803 //***************************************************************************
1804 template <typename T>
1805 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, etl::nullopt_t)
1806 {
1807 return !lhs.has_value();
1808 }
1809
1810 //***************************************************************************
1812 //***************************************************************************
1813 template <typename T>
1814 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(etl::nullopt_t, const etl::optional<T>& rhs)
1815 {
1816 return !rhs.has_value();
1817 }
1818
1819 //***************************************************************************
1821 //***************************************************************************
1822 template <typename T>
1823 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(etl::nullopt_t, const etl::optional<T>& rhs)
1824 {
1825 return !rhs.has_value();
1826 }
1827
1828 //***************************************************************************
1830 //***************************************************************************
1831 template <typename T>
1832 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, etl::nullopt_t)
1833 {
1834 return !(lhs == etl::nullopt);
1835 }
1836
1837 //***************************************************************************
1839 //***************************************************************************
1840 template <typename T>
1841 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, etl::nullopt_t)
1842 {
1843 return !(lhs == etl::nullopt);
1844 }
1845
1846 //***************************************************************************
1848 //***************************************************************************
1849 template <typename T>
1850 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(etl::nullopt_t, const etl::optional<T>& rhs)
1851 {
1852 return !(etl::nullopt == rhs);
1853 }
1854
1855 //***************************************************************************
1857 //***************************************************************************
1858 template <typename T>
1859 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(etl::nullopt_t, const etl::optional<T>& rhs)
1860 {
1861 return !(etl::nullopt == rhs);
1862 }
1863
1864 //***************************************************************************
1866 //***************************************************************************
1867 template <typename T>
1868 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>&, etl::nullopt_t)
1869 {
1870 return false;
1871 }
1872
1873 //***************************************************************************
1875 //***************************************************************************
1876 template <typename T>
1877 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>&, etl::nullopt_t)
1878 {
1879 return false;
1880 }
1881
1882 //***************************************************************************
1884 //***************************************************************************
1885 template <typename T>
1886 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(etl::nullopt_t, const etl::optional<T>& rhs)
1887 {
1888 return rhs.has_value();
1889 }
1890
1891 //***************************************************************************
1893 //***************************************************************************
1894 template <typename T>
1895 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(etl::nullopt_t, const etl::optional<T>& rhs)
1896 {
1897 return rhs.has_value();
1898 }
1899
1900 //***************************************************************************
1902 //***************************************************************************
1903 template <typename T>
1904 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, etl::nullopt_t)
1905 {
1906 return !lhs.has_value();
1907 }
1908
1909 //***************************************************************************
1911 //***************************************************************************
1912 template <typename T>
1913 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, etl::nullopt_t)
1914 {
1915 return !lhs.has_value();
1916 }
1917
1918 //***************************************************************************
1920 //***************************************************************************
1921 template <typename T>
1922 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(etl::nullopt_t, const etl::optional<T>&)
1923 {
1924 return true;
1925 }
1926
1927 //***************************************************************************
1929 //***************************************************************************
1930 template <typename T>
1931 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(etl::nullopt_t, const etl::optional<T>&)
1932 {
1933 return true;
1934 }
1935
1936 //***************************************************************************
1938 //***************************************************************************
1939 template <typename T>
1940 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, etl::nullopt_t)
1941 {
1942 return lhs.has_value();
1943 }
1944
1945 //***************************************************************************
1947 //***************************************************************************
1948 template <typename T>
1949 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, etl::nullopt_t)
1950 {
1951 return lhs.has_value();
1952 }
1953
1954 //***************************************************************************
1956 //***************************************************************************
1957 template <typename T>
1958 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(etl::nullopt_t, const etl::optional<T>&)
1959 {
1960 return false;
1961 }
1962
1963 //***************************************************************************
1965 //***************************************************************************
1966 template <typename T>
1967 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(etl::nullopt_t, const etl::optional<T>&)
1968 {
1969 return false;
1970 }
1971
1972 //***************************************************************************
1974 //***************************************************************************
1975 template <typename T>
1976 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>&, etl::nullopt_t)
1977 {
1978 return true;
1979 }
1980
1981 //***************************************************************************
1983 //***************************************************************************
1984 template <typename T>
1985 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>&, etl::nullopt_t)
1986 {
1987 return true;
1988 }
1989
1990 //***************************************************************************
1992 //***************************************************************************
1993 template <typename T>
1994 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(etl::nullopt_t, const etl::optional<T>& rhs)
1995 {
1996 return !rhs.has_value();
1997 }
1998
1999 //***************************************************************************
2001 //***************************************************************************
2002 template <typename T>
2003 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(etl::nullopt_t, const etl::optional<T>& rhs)
2004 {
2005 return !rhs.has_value();
2006 }
2007
2008 //***************************************************************************
2010 //**************************************************************************
2011 template <typename T, typename U>
2012 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, const U& rhs)
2013 {
2014 return lhs.has_value() ? lhs.value() == rhs : false;
2015 }
2016
2017 //***************************************************************************
2019 //**************************************************************************
2020 template <typename T, typename U>
2021 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, const U& rhs)
2022 {
2023 return lhs.has_value() ? lhs.value() == rhs : false;
2024 }
2025
2026 //***************************************************************************
2028 //**************************************************************************
2029 template <typename T, typename U>
2030 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, const U& rhs)
2031 {
2032 return !(lhs == rhs);
2033 }
2034
2035 //***************************************************************************
2037 //**************************************************************************
2038 template <typename T, typename U>
2039 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, const U& rhs)
2040 {
2041 return !(lhs == rhs);
2042 }
2043
2044 //***************************************************************************
2046 //**************************************************************************
2047 template <typename T, typename U>
2048 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const U& lhs, const etl::optional<T>& rhs)
2049 {
2050 return rhs.has_value() ? rhs.value() == lhs : false;
2051 }
2052
2053 //***************************************************************************
2055 //**************************************************************************
2056 template <typename T, typename U>
2057 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const U& lhs, const etl::optional<T>& rhs)
2058 {
2059 return rhs.has_value() ? rhs.value() == lhs : false;
2060 }
2061
2062 //***************************************************************************
2064 //**************************************************************************
2065 template <typename T, typename U>
2066 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const U& lhs, const etl::optional<T>& rhs)
2067 {
2068 return !(lhs == rhs);
2069 }
2070
2071 //***************************************************************************
2073 //**************************************************************************
2074 template <typename T, typename U>
2075 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const U& lhs, const etl::optional<T>& rhs)
2076 {
2077 return !(lhs == rhs);
2078 }
2079
2080 //***************************************************************************
2082 //***************************************************************************
2083 template <typename T, typename U>
2084 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>& lhs, const U& rhs)
2085 {
2086 return lhs.has_value() ? lhs.value() < rhs : true;
2087 }
2088
2089 //***************************************************************************
2091 //***************************************************************************
2092 template <typename T, typename U>
2093 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>& lhs, const U& rhs)
2094 {
2095 return lhs.has_value() ? lhs.value() < rhs : true;
2096 }
2097
2098 //***************************************************************************
2100 //***************************************************************************
2101 template <typename T, typename U>
2102 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const U& lhs, const etl::optional<T>& rhs)
2103 {
2104 return rhs.has_value() ? lhs < rhs.value() : false;
2105 }
2106
2107 //***************************************************************************
2109 //***************************************************************************
2110 template <typename T, typename U>
2111 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const U& lhs, const etl::optional<T>& rhs)
2112 {
2113 return rhs.has_value() ? lhs < rhs.value() : false;
2114 }
2115
2116 //***************************************************************************
2118 //***************************************************************************
2119 template <typename T, typename U>
2120 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, const U& rhs)
2121 {
2122 return lhs.has_value() ? lhs.value() <= rhs : true;
2123 }
2124
2125 //***************************************************************************
2127 //***************************************************************************
2128 template <typename T, typename U>
2129 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, const U& rhs)
2130 {
2131 return lhs.has_value() ? lhs.value() <= rhs : true;
2132 }
2133
2134 //***************************************************************************
2136 //***************************************************************************
2137 template <typename T, typename U>
2138 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const U& lhs, const etl::optional<T>& rhs)
2139 {
2140 return rhs.has_value() ? lhs <= rhs.value() : false;
2141 }
2142
2143 //***************************************************************************
2145 //***************************************************************************
2146 template <typename T, typename U>
2147 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const U& lhs, const etl::optional<T>& rhs)
2148 {
2149 return rhs.has_value() ? lhs <= rhs.value() : false;
2150 }
2151
2152 //***************************************************************************
2154 //***************************************************************************
2155 template <typename T, typename U>
2156 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, const U& rhs)
2157 {
2158 return lhs.has_value() ? lhs.value() > rhs : false;
2159 }
2160
2161 //***************************************************************************
2163 //***************************************************************************
2164 template <typename T, typename U>
2165 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, const U& rhs)
2166 {
2167 return lhs.has_value() ? lhs.value() > rhs : false;
2168 }
2169
2170 //***************************************************************************
2172 //***************************************************************************
2173 template <typename T, typename U>
2174 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const U& lhs, const etl::optional<T>& rhs)
2175 {
2176 return rhs.has_value() ? lhs > rhs.value() : true;
2177 }
2178
2179 //***************************************************************************
2181 //***************************************************************************
2182 template <typename T, typename U>
2183 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const U& lhs, const etl::optional<T>& rhs)
2184 {
2185 return rhs.has_value() ? lhs > rhs.value() : true;
2186 }
2187
2188 //***************************************************************************
2190 //***************************************************************************
2191 template <typename T, typename U>
2192 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>& lhs, const U& rhs)
2193 {
2194 return lhs.has_value() ? lhs.value() >= rhs : false;
2195 }
2196
2197 //***************************************************************************
2199 //***************************************************************************
2200 template <typename T, typename U>
2201 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>& lhs, const U& rhs)
2202 {
2203 return lhs.has_value() ? lhs.value() >= rhs : false;
2204 }
2205
2206 //***************************************************************************
2208 //***************************************************************************
2209 template <typename T, typename U>
2210 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const U& lhs, const etl::optional<T>& rhs)
2211 {
2212 return rhs.has_value() ? lhs >= rhs.value() : true;
2213 }
2214
2215 //***************************************************************************
2217 //***************************************************************************
2218 template <typename T, typename U>
2219 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const U& lhs, const etl::optional<T>& rhs)
2220 {
2221 return rhs.has_value() ? lhs >= rhs.value() : true;
2222 }
2223
2224#include "private/diagnostic_pop.h"
2225
2226 //***************************************************************************
2228 //***************************************************************************
2229 template <typename T>
2231 {
2233 }
2234
2235 //***************************************************************************
2237 //***************************************************************************
2238#if ETL_CPP17_SUPPORTED
2239 template <typename T>
2240 optional(T) -> optional<T>;
2241#endif
2242} // namespace etl
2243
2244//*************************************************************************
2246//*************************************************************************
2247template <typename T>
2248ETL_CONSTEXPR20_STL void swap(etl::optional<T>& lhs, etl::optional<T>& rhs)
2249{
2250 lhs.swap(rhs);
2251}
2252
2253#undef ETL_OPTIONAL_ENABLE_CPP14
2254#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2255
2256#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14
2257#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
2258
2259#endif
Definition optional.h:57
Definition optional.h:1273
optional & operator=(const optional &other)
Assignment operator from optional.
Definition optional.h:1527
ETL_CONSTEXPR20_STL const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the optional.
Definition optional.h:1614
ETL_CONSTEXPR20_STL iterator begin() ETL_NOEXCEPT
Returns an iterator to the beginning of the optional.
Definition optional.h:1605
ETL_CONSTEXPR20_STL iterator end() ETL_NOEXCEPT
Returns an iterator to the end of the optional.
Definition optional.h:1623
optional(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:1331
optional & operator=(const T &value_)
Assignment operator from value type.
Definition optional.h:1593
optional(const T &value_)
Construct from value type.
Definition optional.h:1421
optional(const optional &other)
Copy constructor.
Definition optional.h:1360
ETL_CONSTEXPR20_STL const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the optional.
Definition optional.h:1632
optional & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:1493
ETL_CONSTEXPR20_STL const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:412
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:604
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:480
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:623
ETL_CONSTEXPR20_STL optional_impl & operator=(const T &value_)
Assignment operator from value type.
Definition optional.h:288
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:566
ETL_CONSTEXPR20_STL const T * operator->() const
Pointer operator.
Definition optional.h:315
ETL_CONSTEXPR20_STL const T & operator*() const ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:341
ETL_CONSTEXPR20_STL optional_impl & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:219
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:425
ETL_CONSTEXPR20_STL ~optional_impl()
Destructor.
Definition optional.h:210
ETL_CONSTEXPR20_STL T & operator*() ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:328
ETL_CONSTEXPR20_STL optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:149
ETL_CONSTEXPR20_STL optional_impl & operator=(const optional_impl< T > &other)
Assignment operator from optional_impl.
Definition optional.h:233
ETL_CONSTEXPR20_STL void reset()
Reset back to invalid.
Definition optional.h:491
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:585
T & emplace()
Definition optional.h:543
ETL_CONSTEXPR20_STL T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:399
ETL_CONSTEXPR20_STL T * operator->()
Pointer operator.
Definition optional.h:302
ETL_CONSTEXPR14 optional_impl & operator=(const T &value_)
Assignment operator from value type.
Definition optional.h:871
ETL_CONSTEXPR14 T * operator->()
Pointer operator.
Definition optional.h:895
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3)
Definition optional.h:1169
ETL_CONSTEXPR14 optional_impl & operator=(const optional_impl< T > &other)
Assignment operator from optional_impl.
Definition optional.h:829
T & emplace()
Definition optional.h:1108
ETL_CONSTEXPR14 const T * operator->() const
Pointer operator.
Definition optional.h:907
ETL_CONSTEXPR14 T & operator*() ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:919
ETL_CONSTEXPR14 T & value() ETL_LVALUE_REF_QUALIFIER
Get a reference to the value.
Definition optional.h:985
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:1131
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:1009
ETL_CONSTEXPR14 optional_impl(const optional_impl< T > &other)
Copy constructor.
Definition optional.h:755
ETL_CONSTEXPR14 const T & value() const ETL_LVALUE_REF_QUALIFIER
Get a const reference to the value.
Definition optional.h:997
T & emplace(const T1 &value1, const T2 &value2)
Definition optional.h:1150
ETL_CONSTEXPR14 const T & operator*() const ETL_LVALUE_REF_QUALIFIER
Dereference operator.
Definition optional.h:931
ETL_CONSTEXPR14 void reset()
Reset back to invalid.
Definition optional.h:1071
ETL_CONSTEXPR14 void swap(optional_impl &other)
Swaps this value with another.
Definition optional.h:1061
ETL_CONSTEXPR14 optional_impl(etl::nullopt_t)
Constructor with nullopt.
Definition optional.h:746
ETL_CONSTEXPR14 optional_impl()
Constructor.
Definition optional.h:738
T & emplace(const T1 &value1, const T2 &value2, const T3 &value3, const T4 &value4)
Definition optional.h:1188
ETL_CONSTEXPR14 optional_impl & operator=(etl::nullopt_t)
Assignment operator from nullopt.
Definition optional.h:816
Definition optional.h:113
#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
Definition optional.h:98
T * construct_at(T *p)
Definition memory.h:1443
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition memory.h:1511
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1081
ETL_CONSTEXPR20_STL etl::optional< typename etl::decay< T >::type > make_optional(T &value)
Make an optional.
Definition optional.h:2230
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1133
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1147
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1093
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
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:1106
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1120
ETL_CONSTEXPR20_STL void swap(etl::optional< T > &lhs, etl::optional< T > &rhs)
Swaps the values.
Definition optional.h:2248
in_place disambiguation tags.
Definition utility.h:927
remove_cv
Definition type_traits.h:325