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::in_place_index_t<Value_Type>(), 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(etl::in_place_index_t<Value_Type>(), 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 ETL_NOEXCEPT
515 {
516 return (storage.index() == Value_Type);
517 }
518
519 //*******************************************
521 //*******************************************
522 ETL_NODISCARD
523 ETL_CONSTEXPR14
524 ETL_EXPLICIT
525 operator bool() const ETL_NOEXCEPT
526 {
527 return has_value();
528 }
529
530#if ETL_USING_CPP11
531 //*******************************************
533 //*******************************************
534 template <typename U>
535 ETL_NODISCARD
536 ETL_CONSTEXPR14
538 value_or(U&& default_value) const&
539 {
540 if (has_value())
541 {
542 return value();
543 }
544 else
545 {
546 return static_cast<value_type>(etl::forward<U>(default_value));
547 }
548 }
549
550 //*******************************************
552 //*******************************************
553 template <typename U>
554 ETL_NODISCARD
555 ETL_CONSTEXPR14
557 value_or(U&& default_value)&&
558 {
559 if (has_value())
560 {
561 return etl::move(value());
562 }
563 else
564 {
565 return static_cast<value_type>(etl::forward<U>(default_value));
566 }
567 }
568
569 //*******************************************
571 //*******************************************
572 ETL_NODISCARD
573 ETL_CONSTEXPR14
574 error_type& error()& ETL_NOEXCEPT
575 {
576 return etl::get<Error_Type>(storage);
577 }
578
579 //*******************************************
581 //*******************************************
582 ETL_NODISCARD
583 ETL_CONSTEXPR14
584 const error_type& error() const& ETL_NOEXCEPT
585 {
586 return etl::get<Error_Type>(storage);
587 }
588
589 //*******************************************
591 //*******************************************
592 ETL_NODISCARD
593 ETL_CONSTEXPR14
594 error_type&& error()&& ETL_NOEXCEPT
595 {
596 return etl::move(etl::get<Error_Type>(storage));
597 }
598
599 //*******************************************
601 //*******************************************
602 ETL_NODISCARD
603 ETL_CONSTEXPR14
604 const error_type&& error() const&& ETL_NOEXCEPT
605 {
606 return etl::move(etl::get<Error_Type>(storage));
607 }
608
609
610 //*******************************************
612 //*******************************************
613 void swap(this_type& other)
614 {
615 using ETL_OR_STD::swap;
616
617 swap(storage, other.storage);
618 }
619
620 //*******************************************
622 //*******************************************
623 template <typename... Args>
624 ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT
625 {
626 storage.template emplace<value_type>(etl::forward<Args>(args)...);
627
628 return value();
629 }
630
631 //*******************************************
633 //*******************************************
634#if ETL_HAS_INITIALIZER_LIST
635 template <typename U, typename... Args>
636 ETL_CONSTEXPR14 value_type& emplace(std::initializer_list<U> il, Args&&... args) ETL_NOEXCEPT
637 {
638 storage.template emplace<value_type>(il, etl::forward<Args>(args)...);
639
640 return value();
641 }
642#endif
643#else
644 //*******************************************
646 //*******************************************
647 template <typename U>
648 value_type value_or(const U& default_value) const
649 {
650 if (has_value())
651 {
652 return value();
653 }
654 else
655 {
656 return default_value;
657 }
658 }
659
660 //*******************************************
662 //*******************************************
663 error_type& error() const
664 {
665 return etl::get<Error_Type>(storage);
666 }
667#endif
668
669 //*******************************************
671 //*******************************************
672 value_type* operator ->()
673 {
674#if ETL_IS_DEBUG_BUILD
675 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
676#endif
677
678 return etl::addressof(etl::get<value_type>(storage));
679 }
680
681 //*******************************************
683 //*******************************************
684 const value_type* operator ->() const
685 {
686#if ETL_IS_DEBUG_BUILD
687 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
688#endif
689
690 return etl::addressof(etl::get<value_type>(storage));
691 }
692
693 //*******************************************
695 //*******************************************
696 value_type& operator *() ETL_LVALUE_REF_QUALIFIER
697 {
698#if ETL_IS_DEBUG_BUILD
699 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
700#endif
701
702 return etl::get<value_type>(storage);
703 }
704
705 //*******************************************
707 //*******************************************
708 const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
709 {
710#if ETL_IS_DEBUG_BUILD
711 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
712#endif
713
714 return etl::get<value_type>(storage);
715 }
716
717#if ETL_USING_CPP11
718 //*******************************************
720 //*******************************************
721 value_type&& operator *()&&
722 {
723#if ETL_IS_DEBUG_BUILD
724 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
725#endif
726
727 return etl::move(etl::get<value_type>(storage));
728 }
729
730 //*******************************************
732 //*******************************************
733 const value_type&& operator *() const&&
734 {
735#if ETL_IS_DEBUG_BUILD
736 ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
737#endif
738
739 return etl::move(etl::get<value_type>(storage));
740 }
741#endif
742
743 private:
744
745 enum
746 {
747 Uninitialised,
748 Value_Type,
749 Error_Type
750 };
751
753 storage_type storage;
754 };
755
756 //*****************************************************************************
758 //*****************************************************************************
759 template<typename TError>
761 {
762 public:
763
765 typedef void value_type;
766 typedef TError error_type;
768
769 //*******************************************
771 //*******************************************
772 ETL_CONSTEXPR14
774 {
775 }
776
777 //*******************************************
779 //*******************************************
780 ETL_CONSTEXPR14
782 : storage(ue_.error())
783 {
784 }
785
786#if ETL_USING_CPP11
787 //*******************************************
789 //*******************************************
790 ETL_CONSTEXPR14
791 expected(unexpected_type&& ue_)
792 : storage(etl::move(ue_.error()))
793 {
794 }
795#endif
796
797 //*******************************************
799 //*******************************************
800 ETL_CONSTEXPR14
802 : storage(other.storage)
803 {
804 }
805
806#if ETL_USING_CPP11
807 //*******************************************
809 //*******************************************
810 ETL_CONSTEXPR14
811 expected(this_type&& other)
812 : storage(etl::move(other.storage))
813 {
814 }
815#endif
816
817 //*******************************************
819 //*******************************************
821 {
822 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Not copy assignable");
823
824 storage = other.storage;
825 return *this;
826 }
827
828#if ETL_USING_CPP11
829 //*******************************************
831 //*******************************************
832 this_type& operator =(this_type&& other)
833 {
834 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Not move assignable");
835
836 storage = etl::move(other.storage);
837 return *this;
838 }
839#endif
840
841 //*******************************************
843 //*******************************************
845 {
846 ETL_STATIC_ASSERT(etl::is_copy_constructible<TError>::value, "Error not copy assignable");
847
848 storage.template emplace<Error_Type>(ue.error());
849 return *this;
850 }
851
852#if ETL_USING_CPP11
853 //*******************************************
855 //*******************************************
856 expected& operator =(unexpected_type&& ue)
857 {
858 ETL_STATIC_ASSERT(etl::is_move_constructible<TError>::value, "Error not move assignable");
859
860 storage.template emplace<Error_Type>(etl::move(ue.error()));
861 return *this;
862 }
863#endif
864
865 //*******************************************
867 //*******************************************
868 ETL_NODISCARD
869 ETL_CONSTEXPR14
870 bool has_value() const ETL_NOEXCEPT
871 {
872 return (storage.index() != Error_Type);
873 }
874
875 //*******************************************
877 //*******************************************
878 ETL_NODISCARD
879 ETL_CONSTEXPR14
880 ETL_EXPLICIT
881 operator bool() const ETL_NOEXCEPT
882 {
883 return has_value();
884 }
885
886#if ETL_USING_CPP11
887 //*******************************************
890 //*******************************************
891 ETL_NODISCARD
892 ETL_CONSTEXPR14
893 error_type& error()& ETL_NOEXCEPT
894 {
895 return etl::get<Error_Type>(storage);
896 }
897
898 //*******************************************
901 //*******************************************
902 ETL_NODISCARD
903 ETL_CONSTEXPR14
904 const error_type& error() const& ETL_NOEXCEPT
905 {
906 return etl::get<Error_Type>(storage);
907 }
908
909 //*******************************************
912 //*******************************************
913 ETL_NODISCARD
914 ETL_CONSTEXPR14
915 error_type&& error() && ETL_NOEXCEPT
916 {
917 return etl::move(etl::get<Error_Type>(storage));
918 }
919
920 //*******************************************
923 //*******************************************
924 ETL_NODISCARD
925 ETL_CONSTEXPR14
926 const error_type&& error() const&& ETL_NOEXCEPT
927 {
928 return etl::move(etl::get<Error_Type>(storage));
929 }
930#else
931 //*******************************************
934 //*******************************************
935 error_type& error() const
936 {
937 return etl::get<Error_Type>(storage);
938 }
939#endif
940
941 //*******************************************
943 //*******************************************
945 {
946 using ETL_OR_STD::swap;
947
948 swap(storage, other.storage);
949 }
950
951 private:
952
953 enum
954 {
955 Uninitialised,
956 Error_Type
957 };
958
960 };
961}
962
963//*******************************************
965//*******************************************
966template <typename TValue, typename TError, typename TValue2, typename TError2>
967ETL_CONSTEXPR14
969{
970 if (lhs.has_value() != rhs.has_value())
971 {
972 return false;
973 }
974 if (lhs.has_value())
975 {
976 return lhs.value() == rhs.value();
977 }
978 return lhs.error() == rhs.error();
979}
980
981//*******************************************
982template <typename TValue, typename TError, typename TValue2>
983ETL_CONSTEXPR14
984bool operator ==(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
985{
986 if (!lhs.has_value())
987 {
988 return false;
989 }
990 return lhs.value() == rhs;
991}
992
993//*******************************************
994template <typename TValue, typename TError, typename TError2>
995ETL_CONSTEXPR14
997{
998 if (lhs.has_value())
999 {
1000 return false;
1001 }
1002 return lhs.error() == rhs.error();
1003}
1004
1005//*******************************************
1006template <typename TError, typename TError2>
1007ETL_CONSTEXPR14
1009{
1010 if (lhs.has_value() != rhs.has_value())
1011 {
1012 return false;
1013 }
1014 if (lhs.has_value())
1015 {
1016 return true;
1017 }
1018 return lhs.error() == rhs.error();
1019}
1020
1021//*******************************************
1022template <typename TError, typename TError2>
1023ETL_CONSTEXPR14
1025{
1026 if (lhs.has_value())
1027 {
1028 return false;
1029 }
1030 return lhs.error() == rhs.error();
1031}
1032
1033//*******************************************
1034template <typename TError, typename TError2>
1035ETL_CONSTEXPR14
1037{
1038 return lhs.error() == rhs.error();
1039}
1040
1041//*******************************************
1042template <typename TValue, typename TError, typename TValue2, typename TError2>
1043ETL_CONSTEXPR14
1044bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::expected<TValue2, TError2>& rhs)
1045{
1046 return !(lhs == rhs);
1047}
1048
1049//*******************************************
1050template <typename TValue, typename TError, typename TValue2>
1051ETL_CONSTEXPR14
1052bool operator !=(const etl::expected<TValue, TError>& lhs, const TValue2& rhs)
1053{
1054 return !(lhs == rhs);
1055}
1056
1057//*******************************************
1058template <typename TValue, typename TError, typename TError2>
1059ETL_CONSTEXPR14
1060bool operator !=(const etl::expected<TValue, TError>& lhs, const etl::unexpected<TError2>& rhs)
1061{
1062 return !(lhs == rhs);
1063}
1064
1065//*******************************************
1066template <typename TError, typename TError2>
1067ETL_CONSTEXPR14
1068bool operator !=(const etl::expected<void, TError>& lhs, const etl::expected<void, TError2>& rhs)
1069{
1070 return !(lhs == rhs);
1071}
1072
1073//*******************************************
1074template <typename TError, typename TError2>
1075ETL_CONSTEXPR14
1076bool operator !=(const etl::expected<void, TError>& lhs, const etl::unexpected<TError2>& rhs)
1077{
1078 return !(lhs == rhs);
1079}
1080
1081//*******************************************
1082template <typename TError, typename TError2>
1083ETL_CONSTEXPR14
1084bool operator !=(const etl::unexpected<TError>& lhs, const etl::unexpected<TError2>& rhs)
1085{
1086 return !(lhs == rhs);
1087}
1088
1089//*******************************************
1091//*******************************************
1092template <typename TValue, typename TError>
1093ETL_CONSTEXPR14
1095{
1096 lhs.swap(rhs);
1097}
1098
1099//*******************************************
1101//*******************************************
1102template <typename TError>
1103ETL_CONSTEXPR14
1105{
1106 lhs.swap(rhs);
1107}
1108
1109#endif
1110
Specialisation for void value type.
Definition expected.h:761
error_type & error() const
Definition expected.h:935
ETL_CONSTEXPR14 expected()
Default constructor.
Definition expected.h:773
ETL_NODISCARD ETL_CONSTEXPR14 bool has_value() const ETL_NOEXCEPT
Returns true if expected has a value.
Definition expected.h:870
ETL_CONSTEXPR14 expected(const unexpected_type &ue_)
Copy construct from unexpected.
Definition expected.h:781
void swap(this_type &other)
Swap with another etl::expected.
Definition expected.h:944
ETL_CONSTEXPR14 expected(const this_type &other)
Copy construct.
Definition expected.h:801
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:968
#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:735
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:2067
Definition type_traits_generator.h:2074
pair holds two objects of arbitrary type
Definition utility.h:164
unexpect_t
Definition expected.h:225