Embedded Template Library 1.0
Loading...
Searching...
No Matches
expected.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) 2022 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_EXPECTED_INCLUDED
32#define ETL_EXPECTED_INCLUDED
33
36#include "platform.h"
37#include "exception.h"
38#include "error_handler.h"
39#include "utility.h"
40#include "variant.h"
41#include "initializer_list.h"
42
43namespace etl
44{
45 //***************************************************************************
47 //***************************************************************************
49 {
50 public:
51
52 expected_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
54 {
55 }
56 };
57
58 //***************************************************************************
60 //***************************************************************************
62 {
63 public:
64
65 expected_invalid(string_type file_name_, numeric_type line_number_)
66 : expected_exception(ETL_ERROR_TEXT("expected:invalid", ETL_EXPECTED_FILE_ID"A"), file_name_, line_number_)
67 {
68 }
69 };
70
71 //***************************************************************************
74 //***************************************************************************
75 template <typename TError>
77 {
78 public:
79
80 typedef TError error_type;
81
82 //*******************************************
84 //*******************************************
85 ETL_CONSTEXPR unexpected(const unexpected& other)
86 : error_value(other.error_value)
87 {
88 }
89
90#if ETL_USING_CPP11
91 //*******************************************
93 //*******************************************
94 ETL_CONSTEXPR unexpected(unexpected&& other)
95 : error_value(etl::move(other.error_value))
96 {
97 }
98#endif
99
100 //*******************************************
102 //*******************************************
103 ETL_CONSTEXPR explicit unexpected(const TError& e)
104 : error_value(e)
105 {
106 }
107
108#if ETL_USING_CPP11
109 //*******************************************
111 //*******************************************
112 ETL_CONSTEXPR explicit unexpected(TError&& e)
113 : error_value(etl::forward<TError>(e))
114 {
115 }
116
117 //*******************************************
119 //*******************************************
120 template <typename... Args >
121 ETL_CONSTEXPR explicit unexpected(etl::in_place_t, Args&&... args)
122 : error_value(etl::forward<Args>(args)...)
123 {
124 }
125#endif
126
127#if ETL_HAS_INITIALIZER_LIST
128 //*******************************************
130 //*******************************************
131 template <typename U, typename... Args>
132 ETL_CONSTEXPR explicit unexpected(etl::in_place_t, std::initializer_list<U> init, Args&&... args)
133 : error_value(init, etl::forward<Args>(args)...)
134 {
135 }
136#endif
137
138 //*******************************************
140 //*******************************************
141 ETL_CONSTEXPR14
143 {
144#if ETL_USING_CPP11
145 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
146#endif
147
148 error_value = rhs.error_value;
149 return *this;
150 }
151
152#if ETL_USING_CPP11
153 //*******************************************
155 //*******************************************
156 ETL_CONSTEXPR14
158 {
159 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
160
161 error_value = etl::move(rhs.error_value);
162 return *this;
163 }
164#endif
165
166#if ETL_USING_CPP11
167 //*******************************************
169 //*******************************************
170 ETL_CONSTEXPR14 TError& error()& ETL_NOEXCEPT
171 {
172 return error_value;
173 }
174
175 //*******************************************
177 //*******************************************
178 ETL_CONSTEXPR14 const TError& error() const& ETL_NOEXCEPT
179 {
180 return error_value;
181 }
182
183 //*******************************************
185 //*******************************************
186 ETL_CONSTEXPR14 TError&& error()&& ETL_NOEXCEPT
187 {
188 return etl::move(error_value);
189 }
190
191 //*******************************************
193 //*******************************************
194 ETL_CONSTEXPR14 TError&& error() const&& ETL_NOEXCEPT
195 {
196 return etl::move(error_value);
197 }
198#else
199 //*******************************************
201 //*******************************************
202 const TError& error() const
203 {
204 return error_value;
205 }
206#endif
207
208 //*******************************************
210 //*******************************************
212 {
213 using ETL_OR_STD::swap;
214
215 swap(error_value, other.error_value);
216 }
217
218 private:
219
220 TError error_value;
221 };
222
223 //*****************************************************************************
225 //*****************************************************************************
227 {
228 ETL_CONSTEXPR14 explicit unexpect_t()
229 {
230 }
231 };
232
233#if ETL_USING_CPP17
234 inline ETL_CONSTEXPR unexpect_t unexpect{};
235#else
236 static const unexpect_t unexpect;
237#endif
238
239 //*****************************************************************************
241 //*****************************************************************************
242 template <typename TValue, typename TError>
244 {
245 public:
246
248 typedef TValue value_type;
249 typedef TError error_type;
251
252#if ETL_USING_CPP11
253 template <typename U>
255#endif
256
257 //*******************************************
259 //*******************************************
260 ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
261 : storage(etl::in_place_index_t<Value_Type>(), value_type())
262 {
263 }
264
265 //*******************************************
267 //*******************************************
268 ETL_CONSTEXPR14 expected(const value_type& value_) ETL_NOEXCEPT
270 {
271 }
272
273#if ETL_USING_CPP11
274 //*******************************************
276 //*******************************************
277 ETL_CONSTEXPR14 expected(value_type&& value_) ETL_NOEXCEPT
278 : storage(etl::in_place_index_t<Value_Type>(), etl::move(value_))
279 {
280 }
281#endif
282
283 //*******************************************
285 //*******************************************
286 ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT
287 : storage(other.storage)
288 {
289 }
290
291#if ETL_USING_CPP11
292 //*******************************************
294 //*******************************************
295 ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT
296 : storage(etl::move(other.storage))
297 {
298 }
299#endif
300
301#if ETL_USING_CPP11
302 //*******************************************
304 //*******************************************
306 ETL_CONSTEXPR14 explicit expected(const etl::unexpected<G>& ue)
307 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
308 {
309 }
310
312 ETL_CONSTEXPR14 expected(const etl::unexpected<G>& ue)
313 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
314 {
315 }
316#else
317 template <typename G>
318 explicit expected(const etl::unexpected<G>& ue)
319 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
320 {
321 }
322#endif
323
324#if ETL_USING_CPP11
325 //*******************************************
327 //*******************************************
329 ETL_CONSTEXPR14 explicit expected(etl::unexpected<G>&& ue)
330 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
331 {
332 }
333
335 ETL_CONSTEXPR14 expected(etl::unexpected<G>&& ue)
336 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
337 {
338 }
339#endif
340
341 //*******************************************
343 //*******************************************
344 ETL_CONSTEXPR14 explicit expected(etl::in_place_t) ETL_NOEXCEPT
345 : storage(value_type())
346 {
347 }
348
349#if ETL_USING_CPP11
350 //*******************************************
352 //*******************************************
353 template <typename... Args>
354 ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args)
355 : storage(etl::in_place_index_t<Value_Type>(), etl::forward<Args>(args)...)
356 {
357 }
358
359#if ETL_HAS_INITIALIZER_LIST
360 //*******************************************
362 //*******************************************
363 template <typename U, typename... Args>
364 ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list<U> il, Args&&... args)
365 : storage(etl::in_place_index_t<Value_Type>(), il, etl::forward<Args>(args)...)
366 {
367 }
368#endif
369
370 //*******************************************
372 //*******************************************
373 template <typename... Args>
374 ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, Args&&... args)
375 : storage(error_type(etl::forward<Args>(args)...))
376 {
377 }
378
379#if ETL_HAS_INITIALIZER_LIST
380 //*******************************************
382 //*******************************************
383 template <typename U, typename... Args>
384 ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, std::initializer_list<U> il, Args&&... args)
385 : storage(error_type(il, etl::forward<Args>(args)...))
386 {
387 }
388#endif
389#endif
390
391 //*******************************************
393 //*******************************************
395 {
397
398 storage = other.storage;
399
400 return *this;
401 }
402
403#if ETL_USING_CPP11
404 //*******************************************
406 //*******************************************
407 this_type& operator =(this_type&& other)
408 {
410
411 storage = etl::move(other.storage);
412
413 return *this;
414 }
415#endif
416
417 //*******************************************
419 //*******************************************
420 expected& operator =(const value_type& value)
421 {
422 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value, "Value not copy assignable");
423
424 storage.template emplace<Value_Type>(value);
425
426 return *this;
427 }
428
429#if ETL_USING_CPP11
430 //*******************************************
432 //*******************************************
433 expected& operator =(value_type&& value)
434 {
435 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value, "Value not move assignable");
436
437 storage.template emplace<Value_Type>(etl::move(value));
438
439 return *this;
440 }
441#endif
442
443 //*******************************************
445 //*******************************************
447 {
448#if ETL_USING_CPP11
449 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
450#endif
451
452 storage.template emplace<Error_Type>(ue.error());
453
454 return *this;
455 }
456
457#if ETL_USING_CPP11
458 //*******************************************
460 //*******************************************
461 expected& operator =(unexpected_type&& ue)
462 {
463 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
464
465 storage.template emplace<Error_Type>(etl::move(ue.error()));
466
467 return *this;
468 }
469#endif
470
471#if ETL_USING_CPP11
472 //*******************************************
474 //*******************************************
475 ETL_CONSTEXPR14 value_type& value()&
476 {
477 return etl::get<Value_Type>(storage);
478 }
479
480 //*******************************************
482 //*******************************************
483 ETL_CONSTEXPR14 const value_type& value() const&
484 {
485 return etl::get<Value_Type>(storage);
486 }
487
488 //*******************************************
490 //*******************************************
491 ETL_CONSTEXPR14 value_type&& value()&&
492 {
493 return etl::move(etl::get<Value_Type>(storage));
494 }
495
496 //*******************************************
498 //*******************************************
499 ETL_CONSTEXPR14 const value_type&& value() const&&
500 {
501 return etl::move(etl::get<Value_Type>(storage));
502 }
503#else
504 //*******************************************
506 //*******************************************
507 const value_type& value() const
508 {
509 return etl::get<Value_Type>(storage);
510 }
511#endif
512
513 //*******************************************
515 //*******************************************
516 ETL_NODISCARD
517 ETL_CONSTEXPR14
518 bool has_value() const ETL_NOEXCEPT
519 {
520 return (storage.index() == Value_Type);
521 }
522
523 //*******************************************
525 //*******************************************
526 ETL_NODISCARD
527 ETL_CONSTEXPR14
528 ETL_EXPLICIT
529 operator bool() const ETL_NOEXCEPT
530 {
531 return has_value();
532 }
533
534#if ETL_USING_CPP11
535 //*******************************************
537 //*******************************************
538 template <typename U>
539 ETL_NODISCARD
540 ETL_CONSTEXPR14
542 value_or(U&& default_value) const&
543 {
544 if (has_value())
545 {
546 return value();
547 }
548 else
549 {
550 return static_cast<value_type>(etl::forward<U>(default_value));
551 }
552 }
553
554 //*******************************************
556 //*******************************************
557 template <typename U>
558 ETL_NODISCARD
559 ETL_CONSTEXPR14
561 value_or(U&& default_value)&&
562 {
563 if (has_value())
564 {
565 return etl::move(value());
566 }
567 else
568 {
569 return static_cast<value_type>(etl::forward<U>(default_value));
570 }
571 }
572
573 //*******************************************
575 //*******************************************
576 ETL_NODISCARD
577 ETL_CONSTEXPR14
578 error_type& error()& ETL_NOEXCEPT
579 {
580 return etl::get<Error_Type>(storage);
581 }
582
583 //*******************************************
585 //*******************************************
586 ETL_NODISCARD
587 ETL_CONSTEXPR14
588 const error_type& error() const& ETL_NOEXCEPT
589 {
590 return etl::get<Error_Type>(storage);
591 }
592
593 //*******************************************
595 //*******************************************
596 ETL_NODISCARD
597 ETL_CONSTEXPR14
598 error_type&& error()&& ETL_NOEXCEPT
599 {
600 return etl::move(etl::get<Error_Type>(storage));
601 }
602
603 //*******************************************
605 //*******************************************
606 ETL_NODISCARD
607 ETL_CONSTEXPR14
608 const error_type&& error() const&& ETL_NOEXCEPT
609 {
610 return etl::move(etl::get<Error_Type>(storage));
611 }
612
613
614 //*******************************************
616 //*******************************************
617 void swap(this_type& other)
618 {
619 using ETL_OR_STD::swap;
620
621 swap(storage, other.storage);
622 }
623
624 //*******************************************
626 //*******************************************
627 template <typename... Args>
628 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
629 {
630 storage.template emplace<value_type>(etl::forward<Args>(args)...);
631
632 return value();
633 }
634
635 //*******************************************
637 //*******************************************
638#if ETL_HAS_INITIALIZER_LIST
639 template <typename U, typename... Args>
640 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
641 {
642 storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
643
644 return value();
645 }
646#endif
647#else
648 //*******************************************
650 //*******************************************
651 template <typename U>
652 value_type value_or(const U& default_value) const
653 {
654 if (has_value())
655 {
656 return value();
657 }
658 else
659 {
660 return default_value;
661 }
662 }
663
664 //*******************************************
666 //*******************************************
667 const error_type& error() const
668 {
669 return etl::get<Error_Type>(storage);
670 }
671#endif
672
673 //*******************************************
675 //*******************************************
676 value_type* operator ->()
677 {
678#if ETL_IS_DEBUG_BUILD
679 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
680#endif
681
682 return etl::addressof(etl::get<value_type>(storage));
683 }
684
685 //*******************************************
687 //*******************************************
688 const value_type* operator ->() const
689 {
690#if ETL_IS_DEBUG_BUILD
691 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
692#endif
693
694 return etl::addressof(etl::get<value_type>(storage));
695 }
696
697 //*******************************************
699 //*******************************************
700 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
701 {
702#if ETL_IS_DEBUG_BUILD
703 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
704#endif
705
706 return etl::get<value_type>(storage);
707 }
708
709 //*******************************************
711 //*******************************************
712 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
713 {
714#if ETL_IS_DEBUG_BUILD
715 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
716#endif
717
718 return etl::get<value_type>(storage);
719 }
720
721#if ETL_USING_CPP11
722 //*******************************************
724 //*******************************************
725 value_type&& operator *()&&
726 {
727#if ETL_IS_DEBUG_BUILD
728 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
729#endif
730
731 return etl::move(etl::get<value_type>(storage));
732 }
733
734 //*******************************************
736 //*******************************************
737 const value_type&& operator *() const&&
738 {
739#if ETL_IS_DEBUG_BUILD
740 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
741#endif
742
743 return etl::move(etl::get<value_type>(storage));
744 }
745#endif
746
747 private:
748
749 enum
750 {
751 Uninitialised,
752 Value_Type,
753 Error_Type
754 };
755
757 storage_type storage;
758 };
759
760 //*****************************************************************************
762 //*****************************************************************************
763 template<typename TError>
765 {
766 public:
767
769 typedef void value_type;
770 typedef TError error_type;
772
773 //*******************************************
775 //*******************************************
776 ETL_CONSTEXPR14
778 {
779 }
780
781 //*******************************************
783 //*******************************************
784 ETL_CONSTEXPR14
786 : storage(ue_.error())
787 {
788 }
789
790#if ETL_USING_CPP11
791 //*******************************************
793 //*******************************************
794 ETL_CONSTEXPR14
795 expected(unexpected_type&& ue_)
796 : storage(etl::move(ue_.error()))
797 {
798 }
799#endif
800
801 //*******************************************
803 //*******************************************
804 ETL_CONSTEXPR14
806 : storage(other.storage)
807 {
808 }
809
810#if ETL_USING_CPP11
811 //*******************************************
813 //*******************************************
814 ETL_CONSTEXPR14
815 expected(this_type&& other)
816 : storage(etl::move(other.storage))
817 {
818 }
819#endif
820
821 //*******************************************
823 //*******************************************
825 {
826 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Not copy assignable");
827
828 storage = other.storage;
829 return *this;
830 }
831
832#if ETL_USING_CPP11
833 //*******************************************
835 //*******************************************
836 this_type& operator =(this_type&& other)
837 {
838 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Not move assignable");
839
840 storage = etl::move(other.storage);
841 return *this;
842 }
843#endif
844
845 //*******************************************
847 //*******************************************
849 {
850#if ETL_USING_CPP11
851 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
852#endif
853
854 storage.template emplace<Error_Type>(ue.error());
855 return *this;
856 }
857
858#if ETL_USING_CPP11
859 //*******************************************
861 //*******************************************
862 expected& operator =(unexpected_type&& ue)
863 {
864 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
865
866 storage.template emplace<Error_Type>(etl::move(ue.error()));
867 return *this;
868 }
869#endif
870
871 //*******************************************
873 //*******************************************
874 ETL_NODISCARD
875 ETL_CONSTEXPR14
876 bool has_value() const ETL_NOEXCEPT
877 {
878 return (storage.index() != Error_Type);
879 }
880
881 //*******************************************
883 //*******************************************
884 ETL_NODISCARD
885 ETL_CONSTEXPR14
886 ETL_EXPLICIT
887 operator bool() const ETL_NOEXCEPT
888 {
889 return has_value();
890 }
891
892#if ETL_USING_CPP11
893 //*******************************************
896 //*******************************************
897 ETL_NODISCARD
898 ETL_CONSTEXPR14
899 error_type& error()& ETL_NOEXCEPT
900 {
901 return etl::get<Error_Type>(storage);
902 }
903
904 //*******************************************
907 //*******************************************
908 ETL_NODISCARD
909 ETL_CONSTEXPR14
910 const error_type& error() const& ETL_NOEXCEPT
911 {
912 return etl::get<Error_Type>(storage);
913 }
914
915 //*******************************************
918 //*******************************************
919 ETL_NODISCARD
920 ETL_CONSTEXPR14
921 error_type&& error() && ETL_NOEXCEPT
922 {
923 return etl::move(etl::get<Error_Type>(storage));
924 }
925
926 //*******************************************
929 //*******************************************
930 ETL_NODISCARD
931 ETL_CONSTEXPR14
932 const error_type&& error() const&& ETL_NOEXCEPT
933 {
934 return etl::move(etl::get<Error_Type>(storage));
935 }
936#else
937 //*******************************************
940 //*******************************************
941 const error_type& error() const
942 {
943 return etl::get<Error_Type>(storage);
944 }
945#endif
946
947 //*******************************************
949 //*******************************************
951 {
952 using ETL_OR_STD::swap;
953
954 swap(storage, other.storage);
955 }
956
957 private:
958
959 enum
960 {
961 Uninitialised,
962 Error_Type
963 };
964
966 };
967}
968
969//*******************************************
971//*******************************************
972template <typename TValue, typename TError, typename TValue2, typename TError2>
973ETL_CONSTEXPR14
975{
976 if (lhs.has_value() != rhs.has_value())
977 {
978 return false;
979 }
980 if (lhs.has_value())
981 {
982 return lhs.value() == rhs.value();
983 }
984 return lhs.error() == rhs.error();
985}
986
987//*******************************************
988template <typename TValue, typename TError, typename TValue2>
989ETL_CONSTEXPR14
990bool operator ==(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
991{
992 if (!lhs.has_value())
993 {
994 return false;
995 }
996 return lhs.value() == rhs;
997}
998
999//*******************************************
1000template <typename TValue, typename TError, typename TError2>
1001ETL_CONSTEXPR14
1003{
1004 if (lhs.has_value())
1005 {
1006 return false;
1007 }
1008 return lhs.error() == rhs.error();
1009}
1010
1011//*******************************************
1012template <typename TError, typename TError2>
1013ETL_CONSTEXPR14
1015{
1016 if (lhs.has_value() != rhs.has_value())
1017 {
1018 return false;
1019 }
1020 if (lhs.has_value())
1021 {
1022 return true;
1023 }
1024 return lhs.error() == rhs.error();
1025}
1026
1027//*******************************************
1028template <typename TError, typename TError2>
1029ETL_CONSTEXPR14
1031{
1032 if (lhs.has_value())
1033 {
1034 return false;
1035 }
1036 return lhs.error() == rhs.error();
1037}
1038
1039//*******************************************
1040template <typename TError, typename TError2>
1041ETL_CONSTEXPR14
1043{
1044 return lhs.error() == rhs.error();
1045}
1046
1047//*******************************************
1048template <typename TValue, typename TError, typename TValue2, typename TError2>
1049ETL_CONSTEXPR14
1050bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::expected<TValue2, TError2>& rhs)
1051{
1052 return !(lhs == rhs);
1053}
1054
1055//*******************************************
1056template <typename TValue, typename TError, typename TValue2>
1057ETL_CONSTEXPR14
1058bool operator !=(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
1059{
1060 return !(lhs == rhs);
1061}
1062
1063//*******************************************
1064template <typename TValue, typename TError, typename TError2>
1065ETL_CONSTEXPR14
1066bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::unexpected<TError2>& rhs)
1067{
1068 return !(lhs == rhs);
1069}
1070
1071//*******************************************
1072template <typename TError, typename TError2>
1073ETL_CONSTEXPR14
1074bool operator !=(const etl::expected<void, TError>& lhs, const etl::expected<void, TError2>& rhs)
1075{
1076 return !(lhs == rhs);
1077}
1078
1079//*******************************************
1080template <typename TError, typename TError2>
1081ETL_CONSTEXPR14
1082bool operator !=(const etl::expected<void, TError>& lhs, const etl::unexpected<TError2>& rhs)
1083{
1084 return !(lhs == rhs);
1085}
1086
1087//*******************************************
1088template <typename TError, typename TError2>
1089ETL_CONSTEXPR14
1090bool operator !=(const etl::unexpected<TError>& lhs, const etl::unexpected<TError2>& rhs)
1091{
1092 return !(lhs == rhs);
1093}
1094
1095//*******************************************
1097//*******************************************
1098template <typename TValue, typename TError>
1099ETL_CONSTEXPR14
1101{
1102 lhs.swap(rhs);
1103}
1104
1105//*******************************************
1107//*******************************************
1108template <typename TError>
1109ETL_CONSTEXPR14
1111{
1112 lhs.swap(rhs);
1113}
1114
1115#endif
Specialisation for void value type.
Definition expected.h:765
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:777
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const ETL_NOEXCEPT
Returns true if expected has a value.
Definition expected.h:876
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:785
void swap(this_type &other)
Swap with another etl::expected.
Definition expected.h:950
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:805
const error_type & error() const
Definition expected.h:941
Base exception for et::expected.
Definition expected.h:49
expected_invalid
Definition expected.h:62
Expected type.
Definition expected.h:244
ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
Default constructor.
Definition expected.h:260
ETL_CONSTEXPR14 expected(const value_type &value_) ETL_NOEXCEPT
Constructor.
Definition expected.h:268
this_type & operator=(const this_type &other)
Copy assign from etl::expected.
Definition expected.h:394
ETL_CONSTEXPR14 expected(etl::in_place_t) ETL_NOEXCEPT
Construct with default value type.
Definition expected.h:344
ETL_CONSTEXPR14 expected(const expected &other) ETL_NOEXCEPT
Copy constructor.
Definition expected.h:286
const value_type & value() const
Get the value.
Definition expected.h:507
Definition expected.h:77
const TError & error() const
Get the error.
Definition expected.h:202
void swap(etl::unexpected< TError > &other)
Swap with another etl::unexpected.
Definition expected.h:211
ETL_CONSTEXPR unexpected(const unexpected &other)
Copy constructor.
Definition expected.h:85
ETL_CONSTEXPR unexpected(const TError &e)
Construct from an lvalue.
Definition expected.h:103
ETL_CONSTEXPR14 etl::unexpected< TError > & operator=(const etl::unexpected< TError > &rhs)
Assign from etl::unexpected.
Definition expected.h:142
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:974
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
size_t index() const
Gets the index of the type currently stored or UNSUPPORTED_TYPE_ID.
Definition variant_legacy.h:734
Definition variant_legacy.h:146
bitset_ext
Definition absolute.h:38
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:1085
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
Definition utility.h:638
in_place disambiguation tags.
Definition utility.h:617
Definition type_traits_generator.h:2161
Definition type_traits_generator.h:2168
unexpect_t
Definition expected.h:227