]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/outcome/test/tests/issue0061.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / outcome / test / tests / issue0061.cpp
CommitLineData
92f5a8d4 1/* Unit testing for outcomes
1e59de90 2(C) 2013-2022 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
92f5a8d4
TL
3
4
5Boost Software License - Version 1.0 - August 17th, 2003
6
7Permission is hereby granted, free of charge, to any person or organization
8obtaining a copy of the software and accompanying documentation covered by
9this license (the "Software") to use, reproduce, display, distribute,
10execute, and transmit the Software, and to prepare derivative works of the
11Software, and to permit third-parties to whom the Software is furnished to
12do so, all subject to the following:
13
14The copyright notices in the Software and this entire statement, including
15the above license grant, this restriction and the following disclaimer,
16must be included in all copies of the Software, in whole or in part, and
17all derivative works of the Software, unless such copies or derivative
18works are solely in the form of machine-executable object code generated by
19a source language processor.
20
21THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27DEALINGS IN THE SOFTWARE.
28*/
29
1e59de90 30#include <boost/outcome.hpp>
92f5a8d4
TL
31#include <boost/test/unit_test.hpp>
32#include <boost/test/unit_test_monitor.hpp>
33
34BOOST_OUTCOME_AUTO_TEST_CASE(issues_0061_result, "result<T1, E1> does not compare to incompatible result<T2, E2>")
35{
36 using namespace BOOST_OUTCOME_V2_NAMESPACE;
37 struct udt1
38 {
39 const char *_v{nullptr};
40 udt1() = default;
41 constexpr udt1(const char *v) noexcept : _v(v) {} // NOLINT
42 udt1(udt1 &&o) = delete;
43 udt1(const udt1 &) = delete;
44 udt1 &operator=(udt1 &&o) = delete;
45 udt1 &operator=(const udt1 &) = delete;
46 ~udt1() = default;
47 constexpr const char *operator*() const noexcept { return _v; }
48 };
49 struct udt2
50 {
51 const char *_v{nullptr};
52 udt2() = default;
53 constexpr explicit udt2(const char *v) noexcept : _v(v) {}
54 udt2(udt2 &&o) = delete;
55 udt2(const udt2 &) = delete;
56 udt2 &operator=(udt2 &&o) = delete;
57 udt2 &operator=(const udt2 &) = delete;
58 ~udt2() = default;
59 constexpr const char *operator*() const noexcept { return _v; }
60 bool operator==(const udt1 &o) const noexcept { return _v == *o; }
61 bool operator!=(const udt1 &o) const noexcept { return _v != *o; }
62 };
63 using result1 = result<int, udt1>;
64 using result2 = result<int, udt2>;
65
66 result1 a(5);
67 result2 b(5);
68 BOOST_CHECK(b == a); // udt2 will compare to udt1
69 BOOST_CHECK(!(b != a)); // udt2 will compare to udt1
70
71 result<void> c = success();
72 result<void> d = success();
73 BOOST_CHECK(c == d);
74 BOOST_CHECK(!(c != d));
75
76 BOOST_CHECK(a == success());
77 BOOST_CHECK(success() == a);
78 BOOST_CHECK(b != failure("foo"));
79 BOOST_CHECK(failure("foo") != b);
80}
81
82BOOST_OUTCOME_AUTO_TEST_CASE(issues_0061_outcome, "outcome<T1, E1, P1> does not compare to incompatible outcome<T2, E2, P2>")
83{
84 using namespace BOOST_OUTCOME_V2_NAMESPACE;
85 struct udt1
86 {
87 const char *_v{nullptr};
88 udt1() = default;
89 constexpr udt1(const char *v) noexcept : _v(v) {} // NOLINT
90 udt1(udt1 &&o) = delete;
91 udt1(const udt1 &) = delete;
92 udt1 &operator=(udt1 &&o) = delete;
93 udt1 &operator=(const udt1 &) = delete;
94 ~udt1() = default;
95 constexpr const char *operator*() const noexcept { return _v; }
96 };
97 struct udt2
98 {
99 const char *_v{nullptr};
100 udt2() = default;
101 constexpr explicit udt2(const char *v) noexcept : _v(v) {}
102 udt2(udt2 &&o) = delete;
103 udt2(const udt2 &) = delete;
104 udt2 &operator=(udt2 &&o) = delete;
105 udt2 &operator=(const udt2 &) = delete;
106 ~udt2() = default;
107 constexpr const char *operator*() const noexcept { return _v; }
108 bool operator==(const udt1 &o) const noexcept { return _v == *o; }
109 bool operator!=(const udt1 &o) const noexcept { return _v != *o; }
110 };
111 using outcome1 = outcome<int, udt1>;
112 using outcome2 = outcome<int, udt2>;
113
114 outcome1 a(5), _a(6);
115 outcome2 b(5);
116 BOOST_CHECK(b == a); // udt2 will compare to udt1
117 BOOST_CHECK(!(b != a)); // udt2 will compare to udt1
118
119 outcome<void> c = success();
120 outcome<void> d = success();
121 BOOST_CHECK(c == d);
122 BOOST_CHECK(!(c != d));
123
124 BOOST_CHECK(a == success());
125 BOOST_CHECK(success() == a);
126 BOOST_CHECK(b != failure("foo"));
127 BOOST_CHECK(failure("foo") != b);
128}