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
130 optional_impl() ETL_NOEXCEPT
131 : storage()
132 {
133 }
134
135 //***************************************************************************
137 //***************************************************************************
138 ETL_CONSTEXPR20_STL
140 : storage()
141 {
142 }
143
145
146 //***************************************************************************
148 //***************************************************************************
149 ETL_CONSTEXPR20_STL
150 optional_impl(const optional_impl& other) ETL_NOEXCEPT_IF(etl::is_nothrow_copy_constructible<T>::value)
151 {
152 if (other.has_value())
153 {
154 storage.construct(other.value());
155 }
156 }
158
159#if ETL_USING_CPP11
160 //***************************************************************************
162 //***************************************************************************
163 ETL_CONSTEXPR20_STL
164 optional_impl(optional_impl&& other) ETL_NOEXCEPT_IF(etl::is_nothrow_move_constructible<T>::value)
165 {
166 if (other.has_value())
167 {
168 storage.construct(etl::move(other.value()));
169 }
170 }
171
172 //***************************************************************************
176 //***************************************************************************
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,
180 int>::type = 0>
181 ETL_CONSTEXPR20_STL optional_impl(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
182 {
183 storage.construct(etl::forward<U>(value_));
184 }
185
186 //***************************************************************************
188 //***************************************************************************
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))
191 {
192 storage.construct(etl::forward<TArgs>(args)...);
193 }
194
195 #if ETL_HAS_INITIALIZER_LIST
196 //*******************************************
198 //*******************************************
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))
202 {
203 storage.construct(ilist, etl::forward<TArgs>(args)...);
204 }
205 #endif
206#endif
207
208 //***************************************************************************
210 //***************************************************************************
211 ETL_CONSTEXPR20_STL
212 ~optional_impl() ETL_NOEXCEPT
213 {
214 storage.destroy();
215 }
216
217 //***************************************************************************
219 //***************************************************************************
220 ETL_CONSTEXPR20_STL
222 {
223 if (has_value())
224 {
225 storage.destroy();
226 }
227
228 return *this;
229 }
230
231 //***************************************************************************
233 //***************************************************************************
234 ETL_CONSTEXPR20_STL
235 optional_impl& operator=(const optional_impl& other) ETL_NOEXCEPT_IF(etl::is_nothrow_copy_constructible<T>::value)
236 {
237 if (this != &other)
238 {
239 if (other.has_value())
240 {
241 storage.construct(other.value());
242 }
243 else
244 {
245 storage.destroy();
246 }
247 }
248
249 return *this;
250 }
251
252#if ETL_USING_CPP11
253 //***************************************************************************
255 //***************************************************************************
256 ETL_CONSTEXPR20_STL
257 optional_impl& operator=(optional_impl&& other) ETL_NOEXCEPT_IF(etl::is_nothrow_move_constructible<T>::value)
258 {
259 if (this != &other)
260 {
261 if (other.has_value())
262 {
263 storage.construct(etl::move(other.value()));
264 }
265 else
266 {
267 storage.destroy();
268 }
269 }
270
271 return *this;
272 }
273#endif
274
275 //***************************************************************************
277 //***************************************************************************
278#if ETL_USING_CPP11
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,
281 int>::type = 0>
282 ETL_CONSTEXPR20_STL optional_impl& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
283 {
284 storage.construct(etl::forward<U>(value_));
285
286 return *this;
287 }
288#else
289 ETL_CONSTEXPR20_STL
290 optional_impl& operator=(const T& value_)
291 {
292 storage.construct(value_);
293
294 return *this;
295 }
296#endif
297
298 public:
299
300 //***************************************************************************
302 //***************************************************************************
303 ETL_CONSTEXPR20_STL
305 {
306#if ETL_IS_DEBUG_BUILD
307 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
308#endif
309
310 return &storage.u.value;
311 }
312
313 //***************************************************************************
315 //***************************************************************************
316 ETL_CONSTEXPR20_STL
317 const T* operator->() const
318 {
319#if ETL_IS_DEBUG_BUILD
320 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
321#endif
322
323 return &storage.u.value;
324 }
325
326 //***************************************************************************
328 //***************************************************************************
329 ETL_CONSTEXPR20_STL
330 T& operator*() ETL_LVALUE_REF_QUALIFIER
331 {
332#if ETL_IS_DEBUG_BUILD
333 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
334#endif
335
336 return storage.u.value;
337 }
338
339 //***************************************************************************
341 //***************************************************************************
342 ETL_CONSTEXPR20_STL
343 const T& operator*() const ETL_LVALUE_REF_QUALIFIER
344 {
345#if ETL_IS_DEBUG_BUILD
346 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
347#endif
348
349 return storage.u.value;
350 }
351
352#if ETL_USING_CPP11
353 //***************************************************************************
355 //***************************************************************************
356 ETL_CONSTEXPR20_STL
357 T&& operator*() &&
358 {
359 #if ETL_IS_DEBUG_BUILD
360 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
361 #endif
362
363 return etl::move(storage.u.value);
364 }
365
366 //***************************************************************************
368 //***************************************************************************
369 ETL_CONSTEXPR20_STL
370 const T&& operator*() const&&
371 {
372 #if ETL_IS_DEBUG_BUILD
373 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
374 #endif
375
376 return etl::move(storage.u.value);
377 }
378#endif
379
380 //***************************************************************************
381 // Check whether optional contains value
382 //***************************************************************************
383 ETL_CONSTEXPR20_STL
384 bool has_value() const ETL_NOEXCEPT
385 {
386 return storage.valid;
387 }
388
389 //***************************************************************************
391 //***************************************************************************
392 ETL_CONSTEXPR20_STL ETL_EXPLICIT operator bool() const
393 {
394 return has_value();
395 }
396
397 //***************************************************************************
399 //***************************************************************************
400 ETL_CONSTEXPR20_STL
401 T& value() ETL_LVALUE_REF_QUALIFIER
402 {
403#if ETL_IS_DEBUG_BUILD
404 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
405#endif
406
407 return storage.u.value;
408 }
409
410 //***************************************************************************
412 //***************************************************************************
413 ETL_CONSTEXPR20_STL
414 const T& value() const ETL_LVALUE_REF_QUALIFIER
415 {
416#if ETL_IS_DEBUG_BUILD
417 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
418#endif
419
420 return storage.u.value;
421 }
422
423 //***************************************************************************
425 //***************************************************************************
426 ETL_CONSTEXPR20_STL
427 T value_or(const T& default_value) const ETL_LVALUE_REF_QUALIFIER
428 {
429 return has_value() ? value() : default_value;
430 }
431
432#if ETL_USING_CPP11
433 //***************************************************************************
435 //***************************************************************************
436 ETL_CONSTEXPR20_STL
437 T&& value() &&
438 {
439 #if ETL_IS_DEBUG_BUILD
440 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
441 #endif
442
443 return etl::move(storage.u.value);
444 }
445
446 //***************************************************************************
448 //***************************************************************************
449 ETL_CONSTEXPR20_STL
450 const T&& value() const&&
451 {
452 #if ETL_IS_DEBUG_BUILD
453 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
454 #endif
455
456 return etl::move(storage.u.value);
457 }
458
459 //***************************************************************************
461 //***************************************************************************
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&
464 {
465 return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
466 }
467
468 //***************************************************************************
470 //***************************************************************************
471 template <typename U>
472 ETL_CONSTEXPR20_STL etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
473 {
474 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
475 }
476#endif
477
478 //***************************************************************************
480 //***************************************************************************
481 ETL_CONSTEXPR20_STL
482 void swap(optional_impl& other) ETL_NOEXCEPT_IF(etl::is_nothrow_move_constructible<T>::value)
483 {
484 optional_impl temp(ETL_MOVE(*this));
485 *this = ETL_MOVE(other);
486 other = ETL_MOVE(temp);
487 }
488
489 //***************************************************************************
491 //***************************************************************************
492 ETL_CONSTEXPR20_STL
493 void reset() ETL_NOEXCEPT
494 {
495 storage.destroy();
496 }
497
498#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
499 //*************************************************************************
501 //*************************************************************************
502 template <typename... Args>
503 ETL_CONSTEXPR20_STL T& emplace(Args&&... args) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, Args...>::value))
504 {
505 storage.construct(etl::forward<Args>(args)...);
506
507 return storage.u.value;
508 }
509
510 #if ETL_HAS_INITIALIZER_LIST
511 //*******************************************
513 //*******************************************
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))
518 {
519 storage.construct(ilist, etl::forward<Args>(args)...);
520
521 return storage.u.value;
522 }
523 #endif
524#else
525 //*************************************************************************
528 //*************************************************************************
529 T& emplace() ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T>::value))
530 {
531 if (has_value())
532 {
533 // Destroy the old one.
534 storage.destroy();
535 }
536
537 T* p = ::new (&storage.u.value) T();
538 storage.valid = true;
539
540 return *p;
541 }
542
543 //*************************************************************************
546 //*************************************************************************
547 template <typename T1>
548 T& emplace(const T1& value1) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, T1>::value))
549 {
550 if (has_value())
551 {
552 // Destroy the old one.
553 storage.destroy();
554 }
555
556 T* p = ::new (&storage.u.value) T(value1);
557 storage.valid = true;
558
559 return *p;
560 }
561
562 //*************************************************************************
565 //*************************************************************************
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))
568 {
569 if (has_value())
570 {
571 // Destroy the old one.
572 storage.destroy();
573 }
574
575 T* p = ::new (&storage.u.value) T(value1, value2);
576 storage.valid = true;
577
578 return *p;
579 }
580
581 //*************************************************************************
584 //*************************************************************************
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))
587 {
588 if (has_value())
589 {
590 // Destroy the old one.
591 storage.destroy();
592 }
593
594 T* p = ::new (&storage.u.value) T(value1, value2, value3);
595 storage.valid = true;
596
597 return *p;
598 }
599
600 //*************************************************************************
603 //*************************************************************************
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))
607 {
608 if (has_value())
609 {
610 // Destroy the old one.
611 storage.destroy();
612 }
613
614 T* p = ::new (&storage.u.value) T(value1, value2, value3, value4);
615 storage.valid = true;
616
617 return *p;
618 }
619#endif
620
621 private:
622
623 struct dummy_t
624 {
625 };
626
627 //*************************************
628 // The storage for the optional value.
629 //*************************************
630 struct storage_type
631 {
632 typedef typename etl::remove_const<T>::type* pointer_type;
633
634 //*******************************
635 ETL_CONSTEXPR20_STL
636 storage_type()
637 : u()
638 , valid(false)
639 {
640 }
641
642 //*******************************
643 ETL_CONSTEXPR20_STL
644 void construct(const T& value_)
645 {
646 destroy();
647
648 etl::construct_at(const_cast<pointer_type>(&u.value), value_);
649 valid = true;
650 }
651
652#if ETL_USING_CPP11
653 //*******************************
654 ETL_CONSTEXPR20_STL
655 void construct(T&& value_)
656 {
657 destroy();
658
659 etl::construct_at(const_cast<pointer_type>(&u.value), etl::move(value_));
660 valid = true;
661 }
662
663 //*******************************
664 template <typename... TArgs>
665 ETL_CONSTEXPR20_STL void construct(TArgs&&... args)
666 {
667 destroy();
668
669 etl::construct_at(const_cast<pointer_type>(&u.value), etl::forward<TArgs>(args)...);
670 valid = true;
671 }
672#endif
673
674 //*******************************
675 ETL_CONSTEXPR20_STL
676 void destroy()
677 {
678 if (valid)
679 {
680 etl::destroy_at(const_cast<pointer_type>(&u.value));
681 valid = false;
682 }
683 }
684
685 //*******************************
686 union union_type
687 {
688 ETL_CONSTEXPR20_STL
689 union_type()
690 : dummy()
691 {
692 }
693
694 ETL_CONSTEXPR20_STL
695 ~union_type() {}
696
697 dummy_t dummy;
698 T value;
699 } u;
700
701 bool valid;
702 };
703
704 storage_type storage;
705 };
706
707 //*****************************************************************************
708 // Implementation for fundamental types.
709 //*****************************************************************************
710 template <typename T>
711 class optional_impl<T, true>
712 {
713 protected:
714
715 typedef T value_type;
716 typedef optional_impl<T, true> this_type;
717
718 //***************************************************************************
720 //***************************************************************************
721 ETL_CONSTEXPR14 optional_impl() ETL_NOEXCEPT
722 : storage()
723 {
724 }
725
726 //***************************************************************************
728 //***************************************************************************
729 ETL_CONSTEXPR14 optional_impl(etl::nullopt_t) ETL_NOEXCEPT
730 : storage()
731 {
732 }
733
735
736 //***************************************************************************
738 //***************************************************************************
739 ETL_CONSTEXPR14 optional_impl(const optional_impl& other) ETL_NOEXCEPT
740 {
741 if (other.has_value())
742 {
743 storage.construct(other.value());
744 }
745 }
747
748#if ETL_USING_CPP11
749 //***************************************************************************
751 //***************************************************************************
752 ETL_CONSTEXPR14 optional_impl(optional_impl&& other) ETL_NOEXCEPT
753 {
754 if (other.has_value())
755 {
756 storage.construct(etl::move(other.value()));
757 }
758 }
759
760 //***************************************************************************
762 //***************************************************************************
763 ETL_CONSTEXPR14 optional_impl(const T& value_) ETL_NOEXCEPT
764 {
765 storage.construct(value_);
766 }
767
768 //***************************************************************************
770 //***************************************************************************
771 ETL_CONSTEXPR14 optional_impl(T&& value_) ETL_NOEXCEPT
772 {
773 storage.construct(etl::move(value_));
774 }
775
776 //***************************************************************************
778 //***************************************************************************
779 template <typename... TArgs>
780 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, TArgs&&... args) ETL_NOEXCEPT
781 {
782 storage.construct(etl::forward<TArgs>(args)...);
783 }
784
785 #if ETL_HAS_INITIALIZER_LIST
786 //*******************************************
788 //*******************************************
789 template <typename U, typename... TArgs >
790 ETL_CONSTEXPR14 optional_impl(etl::in_place_t, std::initializer_list<U> ilist, TArgs&&... args) ETL_NOEXCEPT
791 {
792 storage.construct(ilist, etl::forward<TArgs>(args)...);
793 }
794 #endif
795#endif
796
797 //***************************************************************************
799 //***************************************************************************
800 ETL_CONSTEXPR14 optional_impl& operator=(etl::nullopt_t) ETL_NOEXCEPT
801 {
802 if (has_value())
803 {
804 storage.destroy();
805 }
806
807 return *this;
808 }
809
810 //***************************************************************************
812 //***************************************************************************
813 ETL_CONSTEXPR14 optional_impl& operator=(const optional_impl& other) ETL_NOEXCEPT
814 {
815 if (this != &other)
816 {
817 if (other.has_value())
818 {
819 storage.construct(other.value());
820 }
821 else
822 {
823 storage.destroy();
824 }
825 }
826
827 return *this;
828 }
829
830#if ETL_USING_CPP11
831 //***************************************************************************
833 //***************************************************************************
834 ETL_CONSTEXPR14 optional_impl& operator=(optional_impl&& other) ETL_NOEXCEPT
835 {
836 if (this != &other)
837 {
838 if (other.has_value())
839 {
840 storage.construct(etl::move(other.value()));
841 }
842 else
843 {
844 storage.destroy();
845 }
846 }
847
848 return *this;
849 }
850#endif
851
852 //***************************************************************************
854 //***************************************************************************
855 ETL_CONSTEXPR14 optional_impl& operator=(const T& value_) ETL_NOEXCEPT
856 {
857 storage.construct(value_);
858
859 return *this;
860 }
861
862#if ETL_USING_CPP11
863 //***************************************************************************
865 //***************************************************************************
866 ETL_CONSTEXPR14 optional_impl& operator=(T&& value_) ETL_NOEXCEPT
867 {
868 storage.construct(etl::move(value_));
869
870 return *this;
871 }
872#endif
873
874 public:
875
876 //***************************************************************************
878 //***************************************************************************
879 ETL_CONSTEXPR14 T* operator->()
880 {
881#if ETL_IS_DEBUG_BUILD
882 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
883#endif
884
885 return &storage.value;
886 }
887
888 //***************************************************************************
890 //***************************************************************************
891 ETL_CONSTEXPR14 const T* operator->() const
892 {
893#if ETL_IS_DEBUG_BUILD
894 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
895#endif
896
897 return &storage.value;
898 }
899
900 //***************************************************************************
902 //***************************************************************************
903 ETL_CONSTEXPR14 T& operator*() ETL_LVALUE_REF_QUALIFIER
904 {
905#if ETL_IS_DEBUG_BUILD
906 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
907#endif
908
909 return storage.value;
910 }
911
912 //***************************************************************************
914 //***************************************************************************
915 ETL_CONSTEXPR14 const T& operator*() const ETL_LVALUE_REF_QUALIFIER
916 {
917#if ETL_IS_DEBUG_BUILD
918 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
919#endif
920
921 return storage.value;
922 }
923
924#if ETL_USING_CPP11
925 //***************************************************************************
927 //***************************************************************************
928 ETL_CONSTEXPR14 T&& operator*() &&
929 {
930 #if ETL_IS_DEBUG_BUILD
931 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
932 #endif
933
934 return etl::move(storage.value);
935 }
936
937 //***************************************************************************
939 //***************************************************************************
940 ETL_CONSTEXPR14 const T&& operator*() const&&
941 {
942 #if ETL_IS_DEBUG_BUILD
943 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
944 #endif
945
946 return etl::move(storage.value);
947 }
948#endif
949
950 //***************************************************************************
951 // Check whether optional contains value
952 //***************************************************************************
953 ETL_CONSTEXPR14 bool has_value() const ETL_NOEXCEPT
954 {
955 return storage.valid;
956 }
957
958 //***************************************************************************
960 //***************************************************************************
961 ETL_CONSTEXPR14 ETL_EXPLICIT operator bool() const
962 {
963 return has_value();
964 }
965
966 //***************************************************************************
968 //***************************************************************************
969 ETL_CONSTEXPR14 T& value() ETL_LVALUE_REF_QUALIFIER
970 {
971#if ETL_IS_DEBUG_BUILD
972 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
973#endif
974
975 return storage.value;
976 }
977
978 //***************************************************************************
980 //***************************************************************************
981 ETL_CONSTEXPR14 const T& value() const ETL_LVALUE_REF_QUALIFIER
982 {
983#if ETL_IS_DEBUG_BUILD
984 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
985#endif
986
987 return storage.value;
988 }
989
990 //***************************************************************************
992 //***************************************************************************
993 ETL_CONSTEXPR14 T value_or(const T& default_value) const ETL_LVALUE_REF_QUALIFIER
994 {
995 return has_value() ? value() : default_value;
996 }
997
998#if ETL_USING_CPP11
999 //***************************************************************************
1001 //***************************************************************************
1002 ETL_CONSTEXPR14 T&& value() &&
1003 {
1004 #if ETL_IS_DEBUG_BUILD
1005 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
1006 #endif
1007
1008 return etl::move(storage.value);
1009 }
1010
1011 //***************************************************************************
1013 //***************************************************************************
1014 ETL_CONSTEXPR14 const T&& value() const&&
1015 {
1016 #if ETL_IS_DEBUG_BUILD
1017 ETL_ASSERT(has_value(), ETL_ERROR(optional_invalid));
1018 #endif
1019
1020 return etl::move(storage.value);
1021 }
1022
1023 //***************************************************************************
1025 //***************************************************************************
1026 template <typename U>
1027 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) const&
1028 {
1029 return has_value() ? value() : static_cast<T>(etl::forward<U>(default_value));
1030 }
1031
1032 //***************************************************************************
1034 //***************************************************************************
1035 template <typename U>
1036 ETL_CONSTEXPR14 etl::enable_if_t<etl::is_convertible<U, T>::value, T> value_or(U&& default_value) &&
1037 {
1038 return has_value() ? etl::move(value()) : static_cast<T>(etl::forward<U>(default_value));
1039 }
1040#endif
1041
1042 //***************************************************************************
1044 //***************************************************************************
1045 ETL_CONSTEXPR14 void swap(optional_impl& other) ETL_NOEXCEPT
1046 {
1047 optional_impl temp(*this);
1048 *this = other;
1049 other = temp;
1050 }
1051
1052 //***************************************************************************
1054 //***************************************************************************
1055 ETL_CONSTEXPR14 void reset() ETL_NOEXCEPT
1056 {
1057 storage.destroy();
1058 }
1059
1060#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_OPTIONAL_FORCE_CPP03_IMPLEMENTATION)
1061 //*************************************************************************
1064 //*************************************************************************
1065 template <typename... TArgs>
1066 ETL_CONSTEXPR14 T& emplace(TArgs&&... args) ETL_NOEXCEPT
1067 {
1068 storage.construct(etl::forward<TArgs>(args)...);
1069
1070 return storage.value;
1071 }
1072#else
1073 //*************************************************************************
1076 //*************************************************************************
1077 T& emplace() ETL_NOEXCEPT
1078 {
1079 if (has_value())
1080 {
1081 // Destroy the old one.
1082 storage.destroy();
1083 }
1084
1085 T* p = ::new (&storage.value) T();
1086 storage.valid = true;
1087
1088 return *p;
1089 }
1090
1091 //*************************************************************************
1094 //*************************************************************************
1095 template <typename T1>
1096 T& emplace(const T1& value1) ETL_NOEXCEPT
1097 {
1098 if (has_value())
1099 {
1100 // Destroy the old one.
1101 storage.destroy();
1102 }
1103
1104 T* p = ::new (&storage.value) T(value1);
1105 storage.valid = true;
1106
1107 return *p;
1108 }
1109
1110 //*************************************************************************
1113 //*************************************************************************
1114 template <typename T1, typename T2>
1115 T& emplace(const T1& value1, const T2& value2) ETL_NOEXCEPT
1116 {
1117 if (has_value())
1118 {
1119 // Destroy the old one.
1120 storage.destroy();
1121 }
1122
1123 T* p = ::new (&storage.value) T(value1, value2);
1124 storage.valid = true;
1125
1126 return *p;
1127 }
1128
1129 //*************************************************************************
1132 //*************************************************************************
1133 template <typename T1, typename T2, typename T3>
1134 T& emplace(const T1& value1, const T2& value2, const T3& value3) ETL_NOEXCEPT
1135 {
1136 if (has_value())
1137 {
1138 // Destroy the old one.
1139 storage.destroy();
1140 }
1141
1142 T* p = ::new (&storage.value) T(value1, value2, value3);
1143 storage.valid = true;
1144
1145 return *p;
1146 }
1147
1148 //*************************************************************************
1151 //*************************************************************************
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
1154 {
1155 if (has_value())
1156 {
1157 // Destroy the old one.
1158 storage.destroy();
1159 }
1160
1161 T* p = ::new (&storage.value) T(value1, value2, value3, value4);
1162 storage.valid = true;
1163
1164 return *p;
1165 }
1166#endif
1167
1168 private:
1169
1170 //*************************************
1171 // The storage for the optional value.
1172 //*************************************
1173 struct storage_type
1174 {
1175 //*******************************
1176 ETL_CONSTEXPR14 storage_type()
1177 : value()
1178 , valid(false)
1179 {
1180 }
1181
1182 //*******************************
1183 ETL_CONSTEXPR14 void construct(const T& value_)
1184 {
1185 value = value_;
1186 valid = true;
1187 }
1188
1189#if ETL_USING_CPP11
1190 //*******************************
1191 ETL_CONSTEXPR14 void construct(T&& value_)
1192 {
1193 value = value_;
1194 valid = true;
1195 }
1196
1197 //*******************************
1198 template <typename... TArgs>
1199 ETL_CONSTEXPR14 void construct(TArgs&&... args)
1200 {
1201 value = T(etl::forward<TArgs>(args)...);
1202 valid = true;
1203 }
1204#endif
1205
1206 //*******************************
1207 ETL_CONSTEXPR14 void destroy()
1208 {
1209 valid = false;
1210 }
1211
1212 T value;
1213 bool valid;
1214 };
1215
1216 storage_type storage;
1217 };
1218 } // namespace private_optional
1219
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
1222
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
1228
1229 //*****************************************************************************
1235 //*****************************************************************************
1236 template <typename T>
1237 class optional : public private_optional::optional_impl<T>
1238 {
1239 private:
1240
1242
1243 public:
1244
1245 typedef T value_type;
1246 typedef T* iterator;
1247 typedef const T* const_iterator;
1248
1249#if ETL_USING_CPP11
1250 //***************************************************************************
1252 //***************************************************************************
1253 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1254 ETL_CONSTEXPR14 optional() ETL_NOEXCEPT
1255 : impl_t()
1256 {
1257 }
1258
1259 //***************************************************************************
1261 //***************************************************************************
1262 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1263 ETL_CONSTEXPR20_STL optional() ETL_NOEXCEPT
1264 : impl_t()
1265 {
1266 }
1267#else
1268 optional() ETL_NOEXCEPT
1269 : impl_t()
1270 {
1271 }
1272#endif
1273
1274#if ETL_USING_CPP11
1275 //***************************************************************************
1277 //***************************************************************************
1278 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1279 ETL_CONSTEXPR14 optional(etl::nullopt_t) ETL_NOEXCEPT
1280 : impl_t(etl::nullopt)
1281 {
1282 }
1283
1284 //***************************************************************************
1286 //***************************************************************************
1287 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1288 ETL_CONSTEXPR20_STL optional(etl::nullopt_t) ETL_NOEXCEPT
1289 : impl_t(etl::nullopt)
1290 {
1291 }
1292#else
1293 //***************************************************************************
1295 //***************************************************************************
1297 : impl_t(etl::nullopt)
1298 {
1299 }
1300#endif
1301
1303
1304#if ETL_USING_CPP11
1305#else
1306 //***************************************************************************
1308 //***************************************************************************
1309 optional(const optional& other)
1310 : impl_t(other)
1311 {
1312 }
1313#endif
1314#include "private/diagnostic_pop.h"
1315
1316#if ETL_USING_CPP11
1317 //***************************************************************************
1321 //***************************************************************************
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,
1327 int>::type = 0>
1328 ETL_CONSTEXPR14 optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1329 : impl_t(etl::forward<U>(value_))
1330 {
1331 }
1332
1333 //***************************************************************************
1335 //***************************************************************************
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,
1341 int>::type = 0>
1342 ETL_CONSTEXPR20_STL optional(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1343 : impl_t(etl::forward<U>(value_))
1344 {
1345 }
1346#else
1347 //***************************************************************************
1349 //***************************************************************************
1350 optional(const T& value_)
1351 : impl_t(value_)
1352 {
1353 }
1354#endif
1355
1356#if ETL_USING_CPP11
1357 //***************************************************************************
1359 //***************************************************************************
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))
1362 : impl_t(etl::in_place_t{}, etl::forward<Args>(args)...)
1363 {
1364 }
1365
1366 //***************************************************************************
1368 //***************************************************************************
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)...)
1372 {
1373 }
1374
1375 #if ETL_HAS_INITIALIZER_LIST
1376 //*******************************************
1378 //*******************************************
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)...)
1383 {
1384 }
1385
1386 //*******************************************
1388 //*******************************************
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)...)
1393 {
1394 }
1395 #endif
1396#endif
1397
1398#if ETL_USING_CPP11
1399 //***************************************************************************
1401 //***************************************************************************
1402 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
1403 ETL_CONSTEXPR14 optional& operator=(etl::nullopt_t) ETL_NOEXCEPT
1404 {
1405 impl_t::operator=(etl::nullopt);
1406
1407 return *this;
1408 }
1409
1410 //***************************************************************************
1412 //***************************************************************************
1413 template <typename U = T, ETL_OPTIONAL_ENABLE_CPP20_STL>
1414 ETL_CONSTEXPR20_STL optional& operator=(etl::nullopt_t) ETL_NOEXCEPT
1415 {
1416 impl_t::operator=(etl::nullopt);
1417
1418 return *this;
1419 }
1420#else
1421 //***************************************************************************
1423 //***************************************************************************
1424 optional& operator=(etl::nullopt_t) ETL_NOEXCEPT
1425 {
1426 impl_t::operator=(etl::nullopt);
1427
1428 return *this;
1429 }
1430#endif
1431
1432#if ETL_USING_CPP11
1433#else
1434 //***************************************************************************
1436 //***************************************************************************
1437 optional& operator=(const optional& other)
1438 {
1439 impl_t::operator=(other);
1440
1441 return *this;
1442 }
1443#endif
1444
1445#if ETL_USING_CPP11
1446 //***************************************************************************
1448 //***************************************************************************
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,
1453 int>::type = 0>
1454 ETL_CONSTEXPR14 optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1455 {
1456 impl_t::operator=(etl::forward<U>(value_));
1457
1458 return *this;
1459 }
1460
1461 //***************************************************************************
1463 //***************************************************************************
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,
1468 int>::type = 0>
1469 ETL_CONSTEXPR20_STL optional& operator=(U&& value_) ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<T, U&&>::value))
1470 {
1471 impl_t::operator=(etl::forward<U>(value_));
1472
1473 return *this;
1474 }
1475#else
1476 //***************************************************************************
1478 //***************************************************************************
1479 optional& operator=(const T& value_)
1480 {
1481 impl_t::operator=(value_);
1482
1483 return *this;
1484 }
1485#endif
1486
1487 //***************************************************************************
1489 //***************************************************************************
1490 ETL_CONSTEXPR20_STL
1491 iterator begin() ETL_NOEXCEPT
1492 {
1493 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1494 }
1495
1496 //***************************************************************************
1498 //***************************************************************************
1499 ETL_CONSTEXPR20_STL
1500 const_iterator begin() const ETL_NOEXCEPT
1501 {
1502 return this->has_value() ? this->operator->() : ETL_NULLPTR;
1503 }
1504
1505 //***************************************************************************
1507 //***************************************************************************
1508 ETL_CONSTEXPR20_STL
1509 iterator end() ETL_NOEXCEPT
1510 {
1511 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1512 }
1513
1514 //***************************************************************************
1516 //***************************************************************************
1517 ETL_CONSTEXPR20_STL
1518 const_iterator end() const ETL_NOEXCEPT
1519 {
1520 return this->has_value() ? this->operator->() + 1 : ETL_NULLPTR;
1521 }
1522 };
1523
1525
1526 //***************************************************************************
1528 //***************************************************************************
1529 template <typename T>
1530 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1531 {
1532 if (lhs.has_value() != rhs.has_value())
1533 {
1534 return false;
1535 }
1536 else if (!lhs.has_value() && !rhs.has_value())
1537 {
1538 return true;
1539 }
1540 else
1541 {
1542 return lhs.value() == rhs.value();
1543 }
1544 }
1545
1546 //***************************************************************************
1548 //***************************************************************************
1549 template <typename T>
1550 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1551 {
1552 if (lhs.has_value() != rhs.has_value())
1553 {
1554 return false;
1555 }
1556 else if (!lhs.has_value() && !rhs.has_value())
1557 {
1558 return true;
1559 }
1560 else
1561 {
1562 return lhs.value() == rhs.value();
1563 }
1564 }
1565
1566 //***************************************************************************
1568 //***************************************************************************
1569 template <typename T>
1570 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1571 {
1572 return !(lhs == rhs);
1573 }
1574
1575 //***************************************************************************
1577 //***************************************************************************
1578 template <typename T>
1579 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1580 {
1581 return !(lhs == rhs);
1582 }
1583
1584 //***************************************************************************
1586 //***************************************************************************
1587 template <typename T>
1588 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1589 {
1590 if (!rhs.has_value())
1591 {
1592 return false;
1593 }
1594 else if (!lhs.has_value())
1595 {
1596 return true;
1597 }
1598 else
1599 {
1600 return lhs.value() < rhs.value();
1601 }
1602 }
1603
1604 //***************************************************************************
1606 //***************************************************************************
1607 template <typename T>
1608 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1609 {
1610 if (!rhs.has_value())
1611 {
1612 return false;
1613 }
1614 else if (!lhs.has_value())
1615 {
1616 return true;
1617 }
1618 else
1619 {
1620 return lhs.value() < rhs.value();
1621 }
1622 }
1623
1624 //***************************************************************************
1626 //***************************************************************************
1627 template <typename T>
1628 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1629 {
1630 return !(rhs < lhs);
1631 }
1632
1633 //***************************************************************************
1635 //***************************************************************************
1636 template <typename T>
1637 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1638 {
1639 return !(rhs < lhs);
1640 }
1641
1642 //***************************************************************************
1644 //***************************************************************************
1645 template <typename T>
1646 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1647 {
1648 return (rhs < lhs);
1649 }
1650
1651 //***************************************************************************
1653 //***************************************************************************
1654 template <typename T>
1655 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1656 {
1657 return (rhs < lhs);
1658 }
1659
1660 //***************************************************************************
1662 //***************************************************************************
1663 template <typename T>
1664 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1665 {
1666 return !(lhs < rhs);
1667 }
1668
1669 //***************************************************************************
1671 //***************************************************************************
1672 template <typename T>
1673 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>& lhs, const etl::optional<T>& rhs)
1674 {
1675 return !(lhs < rhs);
1676 }
1677
1678 //***************************************************************************
1680 //***************************************************************************
1681 template <typename T>
1682 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, etl::nullopt_t)
1683 {
1684 return !lhs.has_value();
1685 }
1686
1687 //***************************************************************************
1689 //***************************************************************************
1690 template <typename T>
1691 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, etl::nullopt_t)
1692 {
1693 return !lhs.has_value();
1694 }
1695
1696 //***************************************************************************
1698 //***************************************************************************
1699 template <typename T>
1700 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(etl::nullopt_t, const etl::optional<T>& rhs)
1701 {
1702 return !rhs.has_value();
1703 }
1704
1705 //***************************************************************************
1707 //***************************************************************************
1708 template <typename T>
1709 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(etl::nullopt_t, const etl::optional<T>& rhs)
1710 {
1711 return !rhs.has_value();
1712 }
1713
1714 //***************************************************************************
1716 //***************************************************************************
1717 template <typename T>
1718 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, etl::nullopt_t)
1719 {
1720 return !(lhs == etl::nullopt);
1721 }
1722
1723 //***************************************************************************
1725 //***************************************************************************
1726 template <typename T>
1727 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, etl::nullopt_t)
1728 {
1729 return !(lhs == etl::nullopt);
1730 }
1731
1732 //***************************************************************************
1734 //***************************************************************************
1735 template <typename T>
1736 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(etl::nullopt_t, const etl::optional<T>& rhs)
1737 {
1738 return !(etl::nullopt == rhs);
1739 }
1740
1741 //***************************************************************************
1743 //***************************************************************************
1744 template <typename T>
1745 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(etl::nullopt_t, const etl::optional<T>& rhs)
1746 {
1747 return !(etl::nullopt == rhs);
1748 }
1749
1750 //***************************************************************************
1752 //***************************************************************************
1753 template <typename T>
1754 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>&, etl::nullopt_t)
1755 {
1756 return false;
1757 }
1758
1759 //***************************************************************************
1761 //***************************************************************************
1762 template <typename T>
1763 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>&, etl::nullopt_t)
1764 {
1765 return false;
1766 }
1767
1768 //***************************************************************************
1770 //***************************************************************************
1771 template <typename T>
1772 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(etl::nullopt_t, const etl::optional<T>& rhs)
1773 {
1774 return rhs.has_value();
1775 }
1776
1777 //***************************************************************************
1779 //***************************************************************************
1780 template <typename T>
1781 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(etl::nullopt_t, const etl::optional<T>& rhs)
1782 {
1783 return rhs.has_value();
1784 }
1785
1786 //***************************************************************************
1788 //***************************************************************************
1789 template <typename T>
1790 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, etl::nullopt_t)
1791 {
1792 return !lhs.has_value();
1793 }
1794
1795 //***************************************************************************
1797 //***************************************************************************
1798 template <typename T>
1799 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, etl::nullopt_t)
1800 {
1801 return !lhs.has_value();
1802 }
1803
1804 //***************************************************************************
1806 //***************************************************************************
1807 template <typename T>
1808 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(etl::nullopt_t, const etl::optional<T>&)
1809 {
1810 return true;
1811 }
1812
1813 //***************************************************************************
1815 //***************************************************************************
1816 template <typename T>
1817 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(etl::nullopt_t, const etl::optional<T>&)
1818 {
1819 return true;
1820 }
1821
1822 //***************************************************************************
1824 //***************************************************************************
1825 template <typename T>
1826 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, etl::nullopt_t)
1827 {
1828 return lhs.has_value();
1829 }
1830
1831 //***************************************************************************
1833 //***************************************************************************
1834 template <typename T>
1835 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, etl::nullopt_t)
1836 {
1837 return lhs.has_value();
1838 }
1839
1840 //***************************************************************************
1842 //***************************************************************************
1843 template <typename T>
1844 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(etl::nullopt_t, const etl::optional<T>&)
1845 {
1846 return false;
1847 }
1848
1849 //***************************************************************************
1851 //***************************************************************************
1852 template <typename T>
1853 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(etl::nullopt_t, const etl::optional<T>&)
1854 {
1855 return false;
1856 }
1857
1858 //***************************************************************************
1860 //***************************************************************************
1861 template <typename T>
1862 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>&, etl::nullopt_t)
1863 {
1864 return true;
1865 }
1866
1867 //***************************************************************************
1869 //***************************************************************************
1870 template <typename T>
1871 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>&, etl::nullopt_t)
1872 {
1873 return true;
1874 }
1875
1876 //***************************************************************************
1878 //***************************************************************************
1879 template <typename T>
1880 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(etl::nullopt_t, const etl::optional<T>& rhs)
1881 {
1882 return !rhs.has_value();
1883 }
1884
1885 //***************************************************************************
1887 //***************************************************************************
1888 template <typename T>
1889 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(etl::nullopt_t, const etl::optional<T>& rhs)
1890 {
1891 return !rhs.has_value();
1892 }
1893
1894 //***************************************************************************
1896 //**************************************************************************
1897 template <typename T, typename U>
1898 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const etl::optional<T>& lhs, const U& rhs)
1899 {
1900 return lhs.has_value() ? lhs.value() == rhs : false;
1901 }
1902
1903 //***************************************************************************
1905 //**************************************************************************
1906 template <typename T, typename U>
1907 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const etl::optional<T>& lhs, const U& rhs)
1908 {
1909 return lhs.has_value() ? lhs.value() == rhs : false;
1910 }
1911
1912 //***************************************************************************
1914 //**************************************************************************
1915 template <typename T, typename U>
1916 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const etl::optional<T>& lhs, const U& rhs)
1917 {
1918 return !(lhs == rhs);
1919 }
1920
1921 //***************************************************************************
1923 //**************************************************************************
1924 template <typename T, typename U>
1925 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const etl::optional<T>& lhs, const U& rhs)
1926 {
1927 return !(lhs == rhs);
1928 }
1929
1930 //***************************************************************************
1932 //**************************************************************************
1933 template <typename T, typename U>
1934 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator==(const U& lhs, const etl::optional<T>& rhs)
1935 {
1936 return rhs.has_value() ? rhs.value() == lhs : false;
1937 }
1938
1939 //***************************************************************************
1941 //**************************************************************************
1942 template <typename T, typename U>
1943 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator==(const U& lhs, const etl::optional<T>& rhs)
1944 {
1945 return rhs.has_value() ? rhs.value() == lhs : false;
1946 }
1947
1948 //***************************************************************************
1950 //**************************************************************************
1951 template <typename T, typename U>
1952 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator!=(const U& lhs, const etl::optional<T>& rhs)
1953 {
1954 return !(lhs == rhs);
1955 }
1956
1957 //***************************************************************************
1959 //**************************************************************************
1960 template <typename T, typename U>
1961 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator!=(const U& lhs, const etl::optional<T>& rhs)
1962 {
1963 return !(lhs == rhs);
1964 }
1965
1966 //***************************************************************************
1968 //***************************************************************************
1969 template <typename T, typename U>
1970 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const etl::optional<T>& lhs, const U& rhs)
1971 {
1972 return lhs.has_value() ? lhs.value() < rhs : true;
1973 }
1974
1975 //***************************************************************************
1977 //***************************************************************************
1978 template <typename T, typename U>
1979 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const etl::optional<T>& lhs, const U& rhs)
1980 {
1981 return lhs.has_value() ? lhs.value() < rhs : true;
1982 }
1983
1984 //***************************************************************************
1986 //***************************************************************************
1987 template <typename T, typename U>
1988 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<(const U& lhs, const etl::optional<T>& rhs)
1989 {
1990 return rhs.has_value() ? lhs < rhs.value() : false;
1991 }
1992
1993 //***************************************************************************
1995 //***************************************************************************
1996 template <typename T, typename U>
1997 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<(const U& lhs, const etl::optional<T>& rhs)
1998 {
1999 return rhs.has_value() ? lhs < rhs.value() : false;
2000 }
2001
2002 //***************************************************************************
2004 //***************************************************************************
2005 template <typename T, typename U>
2006 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const etl::optional<T>& lhs, const U& rhs)
2007 {
2008 return lhs.has_value() ? lhs.value() <= rhs : true;
2009 }
2010
2011 //***************************************************************************
2013 //***************************************************************************
2014 template <typename T, typename U>
2015 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const etl::optional<T>& lhs, const U& rhs)
2016 {
2017 return lhs.has_value() ? lhs.value() <= rhs : true;
2018 }
2019
2020 //***************************************************************************
2022 //***************************************************************************
2023 template <typename T, typename U>
2024 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator<=(const U& lhs, const etl::optional<T>& rhs)
2025 {
2026 return rhs.has_value() ? lhs <= rhs.value() : false;
2027 }
2028
2029 //***************************************************************************
2031 //***************************************************************************
2032 template <typename T, typename U>
2033 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator<=(const U& lhs, const etl::optional<T>& rhs)
2034 {
2035 return rhs.has_value() ? lhs <= rhs.value() : false;
2036 }
2037
2038 //***************************************************************************
2040 //***************************************************************************
2041 template <typename T, typename U>
2042 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const etl::optional<T>& lhs, const U& rhs)
2043 {
2044 return lhs.has_value() ? lhs.value() > rhs : false;
2045 }
2046
2047 //***************************************************************************
2049 //***************************************************************************
2050 template <typename T, typename U>
2051 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const etl::optional<T>& lhs, const U& rhs)
2052 {
2053 return lhs.has_value() ? lhs.value() > rhs : false;
2054 }
2055
2056 //***************************************************************************
2058 //***************************************************************************
2059 template <typename T, typename U>
2060 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>(const U& lhs, const etl::optional<T>& rhs)
2061 {
2062 return rhs.has_value() ? lhs > rhs.value() : true;
2063 }
2064
2065 //***************************************************************************
2067 //***************************************************************************
2068 template <typename T, typename U>
2069 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>(const U& lhs, const etl::optional<T>& rhs)
2070 {
2071 return rhs.has_value() ? lhs > rhs.value() : true;
2072 }
2073
2074 //***************************************************************************
2076 //***************************************************************************
2077 template <typename T, typename U>
2078 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const etl::optional<T>& lhs, const U& rhs)
2079 {
2080 return lhs.has_value() ? lhs.value() >= rhs : false;
2081 }
2082
2083 //***************************************************************************
2085 //***************************************************************************
2086 template <typename T, typename U>
2087 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const etl::optional<T>& lhs, const U& rhs)
2088 {
2089 return lhs.has_value() ? lhs.value() >= rhs : false;
2090 }
2091
2092 //***************************************************************************
2094 //***************************************************************************
2095 template <typename T, typename U>
2096 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14 operator>=(const U& lhs, const etl::optional<T>& rhs)
2097 {
2098 return rhs.has_value() ? lhs >= rhs.value() : true;
2099 }
2100
2101 //***************************************************************************
2103 //***************************************************************************
2104 template <typename T, typename U>
2105 ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL operator>=(const U& lhs, const etl::optional<T>& rhs)
2106 {
2107 return rhs.has_value() ? lhs >= rhs.value() : true;
2108 }
2109
2110#include "private/diagnostic_pop.h"
2111
2112#if ETL_CPP11_SUPPORTED
2113 //***************************************************************************
2115 //***************************************************************************
2116 template <typename T, typename U = T, ETL_OPTIONAL_ENABLE_CPP14>
2117 ETL_CONSTEXPR14 etl::optional<typename etl::decay<T>::type> make_optional(T&& value) //
2118 ETL_NOEXCEPT_IF((etl::is_nothrow_constructible<typename etl::decay<T>::type, T&&>::value))
2119 {
2120 return etl::optional<typename etl::decay<T>::type>(etl::forward<T>(value));
2121 }
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))
2125 {
2126 return etl::optional<typename etl::decay<T>::type>(etl::forward<T>(value));
2127 }
2128
2129 //***************************************************************************
2134 //***************************************************************************
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))
2140 {
2141 return etl::optional<T>(etl::in_place_t{}, etl::forward<Args>(args)...);
2142 }
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))
2148 {
2149 return etl::optional<T>(etl::in_place_t{}, etl::forward<Args>(args)...);
2150 }
2151
2152 #if ETL_HAS_INITIALIZER_LIST
2153 //***************************************************************************
2158 //***************************************************************************
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))
2164 {
2165 return etl::optional<T>(etl::in_place_t{}, ilist, etl::forward<Args>(args)...);
2166 }
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))
2172 {
2173 return etl::optional<T>(etl::in_place_t{}, ilist, etl::forward<Args>(args)...);
2174 }
2175 #endif
2176#else
2177 //***************************************************************************
2179 //***************************************************************************
2180 template <typename T>
2182 {
2184 }
2185#endif
2186
2187 //***************************************************************************
2189 //***************************************************************************
2190#if ETL_CPP17_SUPPORTED
2191 template <typename T>
2192 optional(T) -> optional<T>;
2193#endif
2194
2195 //*************************************************************************
2197 //*************************************************************************
2198 template <typename T>
2199 ETL_CONSTEXPR20_STL void swap(etl::optional<T>& lhs, etl::optional<T>& rhs) ETL_NOEXCEPT_FROM(lhs.swap(rhs))
2200 {
2201 lhs.swap(rhs);
2202 }
2203
2204} // namespace etl
2205
2206#undef ETL_OPTIONAL_ENABLE_CPP14
2207#undef ETL_OPTIONAL_ENABLE_CPP20_STL
2208
2209#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP14
2210#undef ETL_OPTIONAL_ENABLE_CONSTEXPR_BOOL_RETURN_CPP20_STL
2211
2212#endif
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
Definition list.h:405
Definition optional.h:98
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:57
Definition optional.h:1238
const nullopt_t nullopt
Definition optional.h:77
Definition absolute.h:40
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