@@ -45,80 +45,47 @@ struct ImplicitAny {
4545template <class To , class From >
4646constexpr bool implicit_conversion (optional<To>&& opt, const From& v) {
4747 using O = optional<To>;
48- static_assert (test_convertible<O, From>(), " " );
49- static_assert (!test_convertible<O, void *>(), " " );
50- static_assert (!test_convertible<O, From, int >(), " " );
51- return opt && *opt == static_cast <To>(v);
48+ assert ((test_convertible<O, From>()));
49+ assert (!(test_convertible<O, void *>()));
50+ assert (!(test_convertible<O, From, int >()));
51+ assert (opt);
52+ assert (*opt == static_cast <To>(v));
53+
54+ return true ;
5255}
5356
5457template <class To , class Input , class Expect >
5558constexpr bool explicit_conversion (Input&& in, const Expect& v) {
5659 using O = optional<To>;
57- static_assert (std::is_constructible<O, Input>::value, " " );
58- static_assert (!std::is_convertible<Input, O>::value, " " );
59- static_assert (!std::is_constructible<O, void *>::value, " " );
60- static_assert (!std::is_constructible<O, Input, int >::value, " " );
60+ assert ((std::is_constructible<O, Input>::value));
61+ assert (!(std::is_convertible<Input, O>::value));
62+ assert (!(std::is_constructible<O, void *>::value));
63+ assert (!(std::is_constructible<O, Input, int >::value));
64+
6165 optional<To> opt (std::forward<Input>(in));
6266 optional<To> opt2{std::forward<Input>(in)};
63- return opt && *opt == static_cast <To>(v) && (opt2 && *opt2 == static_cast <To>(v));
67+ assert (opt);
68+ assert (opt2);
69+ assert (*opt == static_cast <To>(v));
70+ assert (*opt2 == static_cast <To>(v));
71+
72+ return true ;
6473}
6574
6675void test_implicit () {
67- {
68- static_assert (implicit_conversion<long long >(42 , 42 ), " " );
69- }
70- {
71- static_assert (implicit_conversion<long double >(3.14 , 3.14 ), " " );
72- }
73- {
74- int x = 42 ;
75- optional<void * const > o (&x);
76- assert (*o == &x);
77- }
78- {
79- using T = TrivialTestTypes::TestType;
80- static_assert (implicit_conversion<T>(42 , 42 ), " " );
81- }
82- {
83- using T = TestTypes::TestType;
84- assert (implicit_conversion<T>(3 , T (3 )));
85- }
8676 {
8777 using T = TestTypes::TestType;
8878 optional<T> opt ({3 });
8979 assert (opt && *opt == static_cast <T>(3 ));
9080 }
81+
9182 {
92- using O = optional<ImplicitAny>;
93- static_assert (!test_convertible<O, std::in_place_t >(), " " );
94- static_assert (!test_convertible<O, std::in_place_t &>(), " " );
95- static_assert (!test_convertible<O, const std::in_place_t &>(), " " );
96- static_assert (!test_convertible<O, std::in_place_t &&>(), " " );
97- static_assert (!test_convertible<O, const std::in_place_t &&>(), " " );
98- }
99- #ifndef TEST_HAS_NO_EXCEPTIONS
100- {
101- try {
102- using T = ImplicitThrow;
103- optional<T> t = 42 ;
104- assert (false );
105- ((void )t);
106- } catch (int ) {
107- }
83+ using T = TestTypes::TestType;
84+ assert ((implicit_conversion<T>(3 , T (3 ))));
10885 }
109- #endif
11086}
11187
11288void test_explicit () {
113- {
114- using T = ExplicitTrivialTestTypes::TestType;
115- static_assert (explicit_conversion<T>(42 , 42 ), " " );
116- }
117- {
118- using T = ExplicitConstexprTestTypes::TestType;
119- static_assert (explicit_conversion<T>(42 , 42 ), " " );
120- static_assert (!std::is_convertible<int , T>::value, " " );
121- }
12289 {
12390 using T = ExplicitTestTypes::TestType;
12491 T::reset ();
@@ -137,7 +104,20 @@ void test_explicit() {
137104 }
138105 assert (T::alive == 0 );
139106 }
107+ }
108+
109+ TEST_CONSTEXPR_CXX26 void test_throwing () {
140110#ifndef TEST_HAS_NO_EXCEPTIONS
111+ {
112+ try {
113+ using T = ImplicitThrow;
114+ optional<T> t = 42 ;
115+ assert (false );
116+ ((void )t);
117+ } catch (int ) {
118+ }
119+ }
120+
141121 {
142122 try {
143123 using T = ExplicitThrow;
@@ -149,9 +129,68 @@ void test_explicit() {
149129#endif
150130}
151131
132+ constexpr bool test () {
133+ {
134+ assert ((implicit_conversion<long long >(42 , 42 )));
135+ }
136+
137+ {
138+ assert ((implicit_conversion<long double >(3.14 , 3.14 )));
139+ }
140+
141+ {
142+ int x = 42 ;
143+ optional<void * const > o (&x);
144+ assert (*o == &x);
145+ }
146+
147+ {
148+ using T = TrivialTestTypes::TestType;
149+ assert ((implicit_conversion<T>(42 , 42 )));
150+ }
151+
152+ {
153+ using O = optional<ImplicitAny>;
154+ assert (!(test_convertible<O, std::in_place_t >()));
155+ assert (!(test_convertible<O, std::in_place_t &>()));
156+ assert (!(test_convertible<O, const std::in_place_t &>()));
157+ assert (!(test_convertible<O, std::in_place_t &&>()));
158+ assert (!(test_convertible<O, const std::in_place_t &&>()));
159+ }
160+
161+ {
162+ using T = ExplicitTrivialTestTypes::TestType;
163+ assert ((explicit_conversion<T>(42 , 42 )));
164+ }
165+
166+ {
167+ using T = ExplicitConstexprTestTypes::TestType;
168+ assert (explicit_conversion<T>(42 , 42 ));
169+ assert (!(std::is_convertible<int , T>::value));
170+ }
171+
172+ #if TEST_STD_VER >= 26 && 0
173+ test_throwing ();
174+ #endif
175+
176+ return true ;
177+ }
178+
152179int main (int , char **) {
153- test_implicit ();
154- test_explicit ();
180+ test ();
181+ static_assert (test ());
182+
183+ {
184+ test_implicit ();
185+ }
186+
187+ {
188+ test_explicit ();
189+ }
190+
191+ {
192+ test_throwing ();
193+ }
155194
156195 return 0 ;
157196}
0 commit comments