1 // Copyright (C) 2014 Andrzej Krzemienski.
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/lib/optional for documentation.
9 // You are welcome to contact the author at: akrzemi1@gmail.com
12 #include "boost/optional/optional.hpp"
18 #include "boost/core/lightweight_test.hpp"
20 using boost::optional
;
24 // X is convertible to Y
25 // ADeriv is convertible to ABase
29 explicit X(int v
) : val(v
) {}
35 Y(X
const& x
) : yval(x
.val
) {}
36 friend bool operator==(Y
const& l
, Y
const& r
) { return l
.yval
== r
.yval
; }
42 explicit ABase(int v
) : val(v
) {}
43 friend bool operator==(ABase
const& l
, ABase
const& r
) { return l
.val
== r
.val
; }
48 explicit ADeriv(int v
) : ABase(v
) {}
52 template <typename T
, typename U
>
53 void test_convert_optional_U_to_optional_T_for()
55 #ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
60 BOOST_TEST(*ot1
== T(*ou
));
64 #ifndef BOOST_OPTIONAL_NO_CONVERTING_ASSIGNMENT
70 BOOST_TEST(*ot2
== T(*ou
));
75 void test_convert_optional_U_to_optional_T()
77 test_convert_optional_U_to_optional_T_for
<Y
, X
>();
78 test_convert_optional_U_to_optional_T_for
<ABase
, ADeriv
>();
79 test_convert_optional_U_to_optional_T_for
<long, short>();
80 test_convert_optional_U_to_optional_T_for
<double, float>();
83 template <typename T
, typename U
>
84 void test_convert_U_to_optional_T_for()
89 BOOST_TEST(*ot1
== T(u
));
94 BOOST_TEST(*ot2
== T(u
));
97 void test_convert_U_to_optional_T()
99 test_convert_U_to_optional_T_for
<Y
, X
>();
100 test_convert_U_to_optional_T_for
<ABase
, ADeriv
>();
101 test_convert_U_to_optional_T_for
<long, short>();
102 test_convert_U_to_optional_T_for
<double, float>();
107 test_convert_optional_U_to_optional_T();
108 test_convert_U_to_optional_T();
110 return boost::report_errors();