1 | // Copyright 2017, 2021 Peter Dimov. |
2 | // Distributed under the Boost Software License, Version 1.0. |
3 | // https://www.boost.org/LICENSE_1_0.txt |
4 | |
5 | #include <boost/system/result.hpp> |
6 | #include <boost/core/lightweight_test.hpp> |
7 | #include <boost/core/lightweight_test_trait.hpp> |
8 | |
9 | using namespace boost::system; |
10 | |
11 | struct X |
12 | { |
13 | }; |
14 | |
15 | struct Y |
16 | { |
17 | Y( int ); |
18 | }; |
19 | |
20 | int main() |
21 | { |
22 | { |
23 | result<int> r; |
24 | |
25 | BOOST_TEST( r.has_value() ); |
26 | BOOST_TEST( !r.has_error() ); |
27 | |
28 | BOOST_TEST_EQ( r.value(), 0 ); |
29 | } |
30 | |
31 | { |
32 | result<int> r{}; |
33 | |
34 | BOOST_TEST( r.has_value() ); |
35 | BOOST_TEST( !r.has_error() ); |
36 | |
37 | BOOST_TEST_EQ( r.value(), 0 ); |
38 | } |
39 | |
40 | { |
41 | result<int> r = {}; |
42 | |
43 | BOOST_TEST( r.has_value() ); |
44 | BOOST_TEST( !r.has_error() ); |
45 | |
46 | BOOST_TEST_EQ( r.value(), 0 ); |
47 | } |
48 | |
49 | { |
50 | result<X> r; |
51 | |
52 | BOOST_TEST( r.has_value() ); |
53 | BOOST_TEST( !r.has_error() ); |
54 | } |
55 | |
56 | { |
57 | result<X> r{}; |
58 | |
59 | BOOST_TEST( r.has_value() ); |
60 | BOOST_TEST( !r.has_error() ); |
61 | } |
62 | |
63 | { |
64 | result<X> r = {}; |
65 | |
66 | BOOST_TEST( r.has_value() ); |
67 | BOOST_TEST( !r.has_error() ); |
68 | } |
69 | |
70 | { |
71 | result<void> r; |
72 | |
73 | BOOST_TEST( r.has_value() ); |
74 | BOOST_TEST( !r.has_error() ); |
75 | } |
76 | |
77 | { |
78 | result<void> r{}; |
79 | |
80 | BOOST_TEST( r.has_value() ); |
81 | BOOST_TEST( !r.has_error() ); |
82 | } |
83 | |
84 | { |
85 | result<void> r = {}; |
86 | |
87 | BOOST_TEST( r.has_value() ); |
88 | BOOST_TEST( !r.has_error() ); |
89 | } |
90 | |
91 | { |
92 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int>>)); |
93 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int, int>>)); |
94 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X>>)); |
95 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X, int>>)); |
96 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void>>)); |
97 | BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void, int>>)); |
98 | |
99 | BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y>>)); |
100 | BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y, int>>)); |
101 | |
102 | BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<int&>>)); |
103 | BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<int&, int>>)); |
104 | } |
105 | |
106 | return boost::report_errors(); |
107 | } |
108 | |