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 //***************************************************************************
57
58 //***************************************************************************
60 //***************************************************************************
62 {
63 public:
64
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 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
145
146 error_value = rhs.error_value;
147 return *this;
148 }
149
150#if ETL_USING_CPP11
151 //*******************************************
153 //*******************************************
154 ETL_CONSTEXPR14
156 {
157 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
158
159 error_value = etl::move(rhs.error_value);
160 return *this;
161 }
162#endif
163
164#if ETL_USING_CPP11
165 //*******************************************
167 //*******************************************
168 ETL_CONSTEXPR14 TError& error()& ETL_NOEXCEPT
169 {
170 return error_value;
171 }
172
173 //*******************************************
175 //*******************************************
176 ETL_CONSTEXPR14 const TError& error() const& ETL_NOEXCEPT
177 {
178 return error_value;
179 }
180
181 //*******************************************
183 //*******************************************
184 ETL_CONSTEXPR14 TError&& error()&& ETL_NOEXCEPT
185 {
186 return etl::move(error_value);
187 }
188
189 //*******************************************
191 //*******************************************
192 ETL_CONSTEXPR14 TError&& error() const&& ETL_NOEXCEPT
193 {
194 return etl::move(error_value);
195 }
196#else
197 //*******************************************
199 //*******************************************
200 const TError& error() const
201 {
202 return error_value;
203 }
204#endif
205
206 //*******************************************
208 //*******************************************
210 {
211 using ETL_OR_STD::swap;
212
213 swap(error_value, other.error_value);
214 }
215
216 private:
217
218 TError error_value;
219 };
220
221 //*****************************************************************************
223 //*****************************************************************************
225 {
226 ETL_CONSTEXPR14 explicit unexpect_t()
227 {
228 }
229 };
230
231#if ETL_USING_CPP17
232 inline ETL_CONSTEXPR unexpect_t unexpect{};
233#else
234 static const unexpect_t unexpect;
235#endif
236
237 //*****************************************************************************
239 //*****************************************************************************
240 template <typename TValue, typename TError>
242 {
243 public:
244
246 typedef TValue value_type;
247 typedef TError error_type;
249
250#if ETL_USING_CPP11
251 template <typename U>
253#endif
254
255 //*******************************************
257 //*******************************************
258 ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
259 : storage(etl::in_place_index_t<Value_Type>(), value_type())
260 {
261 }
262
263 //*******************************************
265 //*******************************************
266 ETL_CONSTEXPR14 expected(const value_type& value_) ETL_NOEXCEPT
268 {
269 }
270
271#if ETL_USING_CPP11
272 //*******************************************
274 //*******************************************
275 ETL_CONSTEXPR14 expected(value_type&& value_) ETL_NOEXCEPT
276 : storage(etl::in_place_index_t<Value_Type>(), etl::move(value_))
277 {
278 }
279#endif
280
281 //*******************************************
283 //*******************************************
284 ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT
285 : storage(other.storage)
286 {
287 }
288
289#if ETL_USING_CPP11
290 //*******************************************
292 //*******************************************
293 ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT
294 : storage(etl::move(other.storage))
295 {
296 }
297#endif
298
299#if ETL_USING_CPP11
300 //*******************************************
302 //*******************************************
303 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value, bool>::type = false>
304 ETL_CONSTEXPR14 explicit expected(const etl::unexpected<G>& ue)
305 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
306 {
307 }
308
309 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value, bool>::type = false>
310 ETL_CONSTEXPR14 expected(const etl::unexpected<G>& ue)
311 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
312 {
313 }
314#else
315 template <typename G>
316 explicit expected(const etl::unexpected<G>& ue)
317 : storage(etl::in_place_index_t<Error_Type>(), ue.error())
318 {
319 }
320#endif
321
322#if ETL_USING_CPP11
323 //*******************************************
325 //*******************************************
326 template <typename G, typename etl::enable_if<!etl::is_convertible<const G&, TError>::value, bool>::type = false>
327 ETL_CONSTEXPR14 explicit expected(etl::unexpected<G>&& ue)
328 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
329 {
330 }
331
332 template <typename G, typename etl::enable_if<etl::is_convertible<const G&, TError>::value, bool>::type = false>
333 ETL_CONSTEXPR14 expected(etl::unexpected<G>&& ue)
334 : storage(etl::in_place_index_t<Error_Type>(), etl::move(ue.error()))
335 {
336 }
337#endif
338
339 //*******************************************
341 //*******************************************
342 ETL_CONSTEXPR14 explicit expected(etl::in_place_t) ETL_NOEXCEPT
343 : storage(value_type())
344 {
345 }
346
347#if ETL_USING_CPP11
348 //*******************************************
350 //*******************************************
351 template <typename... Args>
352 ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args)
353 : storage(etl::forward<Args>(args)...)
354 {
355 }
356
357#if ETL_HAS_INITIALIZER_LIST
358 //*******************************************
360 //*******************************************
361 template <typename U, typename... Args>
362 ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list<U> il, Args&&... args)
363 : storage(il, etl::forward<Args>(args)...)
364 {
365 }
366#endif
367
368 //*******************************************
370 //*******************************************
371 template <typename... Args>
372 ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, Args&&... args)
373 : storage(error_type(etl::forward<Args>(args)...))
374 {
375 }
376
377#if ETL_HAS_INITIALIZER_LIST
378 //*******************************************
380 //*******************************************
381 template <typename U, typename... Args>
382 ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, std::initializer_list<U> il, Args&&... args)
383 : storage(error_type(il, etl::forward<Args>(args)...))
384 {
385 }
386#endif
387#endif
388
389 //*******************************************
391 //*******************************************
393 {
395
396 storage = other.storage;
397
398 return *this;
399 }
400
401#if ETL_USING_CPP11
402 //*******************************************
404 //*******************************************
405 this_type& operator =(this_type&& other)
406 {
408
409 storage = etl::move(other.storage);
410
411 return *this;
412 }
413#endif
414
415 //*******************************************
417 //*******************************************
419 {
420 ETL_STATIC_ASSERT(etl::is_copy_constructible<TValue>::value, "Value not copy assignable");
421
422 storage.template emplace<Value_Type>(value);
423
424 return *this;
425 }
426
427#if ETL_USING_CPP11
428 //*******************************************
430 //*******************************************
431 expected& operator =(value_type&& value)
432 {
433 ETL_STATIC_ASSERT(etl::is_move_constructible<TValue>::value, "Value not move assignable");
434
435 storage.template emplace<Value_Type>(etl::move(value));
436
437 return *this;
438 }
439#endif
440
441 //*******************************************
443 //*******************************************
445 {
446 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
447
448 storage.template emplace<Error_Type>(ue.error());
449
450 return *this;
451 }
452
453#if ETL_USING_CPP11
454 //*******************************************
456 //*******************************************
457 expected& operator =(unexpected_type&& ue)
458 {
459 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
460
461 storage.template emplace<Error_Type>(etl::move(ue.error()));
462
463 return *this;
464 }
465#endif
466
467#if ETL_USING_CPP11
468 //*******************************************
470 //*******************************************
471 ETL_CONSTEXPR14 value_type& value()&
472 {
473 return etl::get<Value_Type>(storage);
474 }
475
476 //*******************************************
478 //*******************************************
479 ETL_CONSTEXPR14 const value_type& value() const&
480 {
481 return etl::get<Value_Type>(storage);
482 }
483
484 //*******************************************
486 //*******************************************
487 ETL_CONSTEXPR14 value_type&& value()&&
488 {
489 return etl::move(etl::get<Value_Type>(storage));
490 }
491
492 //*******************************************
494 //*******************************************
495 ETL_CONSTEXPR14 const value_type&& value() const&&
496 {
497 return etl::move(etl::get<Value_Type>(storage));
498 }
499#else
500 //*******************************************
502 //*******************************************
504 {
505 return etl::get<Value_Type>(storage);
506 }
507#endif
508
509 //*******************************************
511 //*******************************************
512 ETL_NODISCARD
513 ETL_CONSTEXPR14
514 bool has_value() const
515 {
516 return (storage.index() == Value_Type);
517 }
518
519 //*******************************************
521 //*******************************************
522 ETL_NODISCARD
523 ETL_CONSTEXPR14
524 operator bool() const
525 {
526 return has_value();
527 }
528
529#if ETL_USING_CPP11
530 //*******************************************
532 //*******************************************
533 template <typename U>
534 ETL_NODISCARD
535 ETL_CONSTEXPR14
537 value_or(U&& default_value) const&
538 {
539 if (has_value())
540 {
541 return value();
542 }
543 else
544 {
545 return static_cast<value_type>(etl::forward<U>(default_value));
546 }
547 }
548
549 //*******************************************
551 //*******************************************
552 template <typename U>
553 ETL_NODISCARD
554 ETL_CONSTEXPR14
556 value_or(U&& default_value)&&
557 {
558 if (has_value())
559 {
560 return etl::move(value());
561 }
562 else
563 {
564 return static_cast<value_type>(etl::forward<U>(default_value));
565 }
566 }
567
568 //*******************************************
570 //*******************************************
571 ETL_NODISCARD
572 ETL_CONSTEXPR14
573 error_type& error()& ETL_NOEXCEPT
574 {
575 return etl::get<Error_Type>(storage);
576 }
577
578 //*******************************************
580 //*******************************************
581 ETL_NODISCARD
582 ETL_CONSTEXPR14
583 const error_type& error() const& ETL_NOEXCEPT
584 {
585 return etl::get<Error_Type>(storage);
586 }
587
588 //*******************************************
590 //*******************************************
591 ETL_NODISCARD
592 ETL_CONSTEXPR14
593 error_type&& error()&& ETL_NOEXCEPT
594 {
595 return etl::move(etl::get<Error_Type>(storage));
596 }
597
598 //*******************************************
600 //*******************************************
601 ETL_NODISCARD
602 ETL_CONSTEXPR14
603 const error_type&& error() const&& ETL_NOEXCEPT
604 {
605 return etl::move(etl::get<Error_Type>(storage));
606 }
607
608
609 //*******************************************
611 //*******************************************
612 void swap(this_type& other)
613 {
614 using ETL_OR_STD::swap;
615
616 swap(storage, other.storage);
617 }
618
619 //*******************************************
621 //*******************************************
622 template <typename... Args>
623 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
624 {
625 storage.template emplace<value_type>(etl::forward<Args>(args)...);
626
627 return value();
628 }
629
630 //*******************************************
632 //*******************************************
633#if ETL_HAS_INITIALIZER_LIST
634 template <typename U, typename... Args>
635 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
636 {
637 storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
638
639 return value();
640 }
641#endif
642#else
643 //*******************************************
645 //*******************************************
646 template <typename U>
647 value_type value_or(const U& default_value) const
648 {
649 if (has_value())
650 {
651 return value();
652 }
653 else
654 {
655 return default_value;
656 }
657 }
658
659 //*******************************************
661 //*******************************************
662 error_type& error() const
663 {
664 return etl::get<Error_Type>(storage);
665 }
666#endif
667
668 //*******************************************
670 //*******************************************
671 value_type* operator ->()
672 {
673#if ETL_IS_DEBUG_BUILD
674 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
675#endif
676
677 return etl::addressof(etl::get<value_type>(storage));
678 }
679
680 //*******************************************
682 //*******************************************
683 const value_type* operator ->() const
684 {
685#if ETL_IS_DEBUG_BUILD
686 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
687#endif
688
689 return etl::addressof(etl::get<value_type>(storage));
690 }
691
692 //*******************************************
694 //*******************************************
695 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
696 {
697#if ETL_IS_DEBUG_BUILD
698 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
699#endif
700
701 return etl::get<value_type>(storage);
702 }
703
704 //*******************************************
706 //*******************************************
707 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
708 {
709#if ETL_IS_DEBUG_BUILD
710 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
711#endif
712
713 return etl::get<value_type>(storage);
714 }
715
716#if ETL_USING_CPP11
717 //*******************************************
719 //*******************************************
720 value_type&& operator *()&&
721 {
722#if ETL_IS_DEBUG_BUILD
723 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
724#endif
725
726 return etl::move(etl::get<value_type>(storage));
727 }
728
729 //*******************************************
731 //*******************************************
732 const value_type&& operator *() const&&
733 {
734#if ETL_IS_DEBUG_BUILD
735 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
736#endif
737
738 return etl::move(etl::get<value_type>(storage));
739 }
740#endif
741
742 private:
743
744 enum
745 {
746 Uninitialised,
747 Value_Type,
748 Error_Type
749 };
750
752 storage_type storage;
753 };
754
755 //*****************************************************************************
757 //*****************************************************************************
758 template<typename TError>
760 {
761 public:
762
764 typedef void value_type;
765 typedef TError error_type;
767
768 //*******************************************
770 //*******************************************
771 ETL_CONSTEXPR14
773 {
774 }
775
776 //*******************************************
778 //*******************************************
779 ETL_CONSTEXPR14
781 : storage(ue_.error())
782 {
783 }
784
785#if ETL_USING_CPP11
786 //*******************************************
788 //*******************************************
789 ETL_CONSTEXPR14
790 expected(unexpected_type&& ue_)
791 : storage(etl::move(ue_.error()))
792 {
793 }
794#endif
795
796 //*******************************************
798 //*******************************************
799 ETL_CONSTEXPR14
801 : storage(other.storage)
802 {
803 }
804
805#if ETL_USING_CPP11
806 //*******************************************
808 //*******************************************
809 ETL_CONSTEXPR14
810 expected(this_type&& other)
811 : storage(etl::move(other.storage))
812 {
813 }
814#endif
815
816 //*******************************************
818 //*******************************************
820 {
821 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Not copy assignable");
822
823 storage = other.storage;
824 return *this;
825 }
826
827#if ETL_USING_CPP11
828 //*******************************************
830 //*******************************************
831 this_type& operator =(this_type&& other)
832 {
833 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Not move assignable");
834
835 storage = etl::move(other.storage);
836 return *this;
837 }
838#endif
839
840 //*******************************************
842 //*******************************************
844 {
845 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
846
847 storage.template emplace<Error_Type>(ue.error());
848 return *this;
849 }
850
851#if ETL_USING_CPP11
852 //*******************************************
854 //*******************************************
855 expected& operator =(unexpected_type&& ue)
856 {
857 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
858
859 storage.template emplace<Error_Type>(etl::move(ue.error()));
860 return *this;
861 }
862#endif
863
864 //*******************************************
866 //*******************************************
867 ETL_NODISCARD
868 ETL_CONSTEXPR14
869 bool has_value() const
870 {
871 return (storage.index() != Error_Type);
872 }
873
874 //*******************************************
876 //*******************************************
877 ETL_NODISCARD
878 ETL_CONSTEXPR14
879 operator bool() const
880 {
881 return has_value();
882 }
883
884#if ETL_USING_CPP11
885 //*******************************************
888 //*******************************************
889 ETL_NODISCARD
890 ETL_CONSTEXPR14
891 error_type& error()& ETL_NOEXCEPT
892 {
893 return etl::get<Error_Type>(storage);
894 }
895
896 //*******************************************
899 //*******************************************
900 ETL_NODISCARD
901 ETL_CONSTEXPR14
902 const error_type& error() const& ETL_NOEXCEPT
903 {
904 return etl::get<Error_Type>(storage);
905 }
906
907 //*******************************************
910 //*******************************************
911 ETL_NODISCARD
912 ETL_CONSTEXPR14
913 error_type&& error() && ETL_NOEXCEPT
914 {
915 return etl::move(etl::get<Error_Type>(storage));
916 }
917
918 //*******************************************
921 //*******************************************
922 ETL_NODISCARD
923 ETL_CONSTEXPR14
924 const error_type&& error() const&& ETL_NOEXCEPT
925 {
926 return etl::move(etl::get<Error_Type>(storage));
927 }
928#else
929 //*******************************************
932 //*******************************************
933 error_type& error() const
934 {
935 return etl::get<Error_Type>(storage);
936 }
937#endif
938
939 //*******************************************
941 //*******************************************
943 {
944 using ETL_OR_STD::swap;
945
946 swap(storage, other.storage);
947 }
948
949 private:
950
951 enum
952 {
953 Uninitialised,
954 Error_Type
955 };
956
958 };
959}
960
961//*******************************************
963//*******************************************
964template <typename TValue, typename TError, typename TValue2, typename TError2>
965ETL_CONSTEXPR14
967{
968 if (lhs.has_value() != rhs.has_value())
969 {
970 return false;
971 }
972 if (lhs.has_value())
973 {
974 return lhs.value() == rhs.value();
975 }
976 return lhs.error() == rhs.error();
977}
978
979//*******************************************
980template <typename TValue, typename TError, typename TValue2>
981ETL_CONSTEXPR14
982bool operator ==(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
983{
984 if (!lhs.has_value())
985 {
986 return false;
987 }
988 return lhs.value() == rhs;
989}
990
991//*******************************************
992template <typename TValue, typename TError, typename TError2>
993ETL_CONSTEXPR14
995{
996 if (lhs.has_value())
997 {
998 return false;
999 }
1000 return lhs.error() == rhs.error();
1001}
1002
1003//*******************************************
1004template <typename TError, typename TError2>
1005ETL_CONSTEXPR14
1007{
1008 if (lhs.has_value() != rhs.has_value())
1009 {
1010 return false;
1011 }
1012 if (lhs.has_value())
1013 {
1014 return true;
1015 }
1016 return lhs.error() == rhs.error();
1017}
1018
1019//*******************************************
1020template <typename TError, typename TError2>
1021ETL_CONSTEXPR14
1023{
1024 if (lhs.has_value())
1025 {
1026 return false;
1027 }
1028 return lhs.error() == rhs.error();
1029}
1030
1031//*******************************************
1032template <typename TError, typename TError2>
1033ETL_CONSTEXPR14
1035{
1036 return lhs.error() == rhs.error();
1037}
1038
1039//*******************************************
1040template <typename TValue, typename TError, typename TValue2, typename TError2>
1041ETL_CONSTEXPR14
1042bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::expected<TValue2, TError2>& rhs)
1043{
1044 return !(lhs == rhs);
1045}
1046
1047//*******************************************
1048template <typename TValue, typename TError, typename TValue2>
1049ETL_CONSTEXPR14
1050bool operator !=(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
1051{
1052 return !(lhs == rhs);
1053}
1054
1055//*******************************************
1056template <typename TValue, typename TError, typename TError2>
1057ETL_CONSTEXPR14
1058bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::unexpected<TError2>& rhs)
1059{
1060 return !(lhs == rhs);
1061}
1062
1063//*******************************************
1064template <typename TError, typename TError2>
1065ETL_CONSTEXPR14
1066bool operator !=(const etl::expected<void, TError>& lhs, const etl::expected<void, 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::unexpected<TError2>& rhs)
1075{
1076 return !(lhs == rhs);
1077}
1078
1079//*******************************************
1080template <typename TError, typename TError2>
1081ETL_CONSTEXPR14
1082bool operator !=(const etl::unexpected<TError>& lhs, const etl::unexpected<TError2>& rhs)
1083{
1084 return !(lhs == rhs);
1085}
1086
1087//*******************************************
1089//*******************************************
1090template <typename TValue, typename TError>
1091ETL_CONSTEXPR14
1093{
1094 lhs.swap(rhs);
1095}
1096
1097//*******************************************
1099//*******************************************
1100template <typename TError>
1101ETL_CONSTEXPR14
1103{
1104 lhs.swap(rhs);
1105}
1106
1107#endif
1108
Specialisation for void value type.
Definition expected.h:760
error_type & error() const
Definition expected.h:933
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:772
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const
Returns true if expected has a value.
Definition expected.h:869
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:780
void swap(this_type &other)
Swap with another etl::expected.
Definition expected.h:942
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:800
Base exception for et::expected.
Definition expected.h:49
expected_invalid
Definition expected.h:62
Expected type.
Definition expected.h:242
ETL_CONSTEXPR14 expected() ETL_NOEXCEPT
Default constructor.
Definition expected.h:258
ETL_CONSTEXPR14 expected(const value_type &value_) ETL_NOEXCEPT
Constructor.
Definition expected.h:266
this_type & operator=(const this_type &other)
Copy assign from etl::expected.
Definition expected.h:392
ETL_CONSTEXPR14 expected(etl::in_place_t) ETL_NOEXCEPT
Construct with default value type.
Definition expected.h:342
value_type & value() const
Get the value.
Definition expected.h:503
ETL_CONSTEXPR14 expected(const expected &other) ETL_NOEXCEPT
Copy constructor.
Definition expected.h:284
Definition expected.h:77
const TError & error() const
Get the error.
Definition expected.h:200
void swap(etl::unexpected< TError > &other)
Swap with another etl::unexpected.
Definition expected.h:209
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:966
#define ETL_ASSERT(b, e)
Definition error_handler.h:316
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:722
bitset_ext
Definition absolute.h:38
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:630
Definition utility.h:593
in_place disambiguation tags.
Definition utility.h:572
Definition type_traits_generator.h:2072
Definition type_traits_generator.h:2079
pair holds two objects of arbitrary type
Definition utility.h:164
unexpect_t
Definition expected.h:225