]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright (C) 2021 Andrzej Krzemienski. |
2 | // | |
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) | |
6 | // | |
7 | // See http://www.boost.org/lib/optional for documentation. | |
8 | // | |
9 | // You are welcome to contact the author at: | |
10 | // akrzemi1@gmail.com | |
11 | ||
12 | #include "boost/optional/optional.hpp" | |
13 | ||
14 | #include "boost/core/lightweight_test.hpp" | |
15 | #include "boost/none.hpp" | |
16 | ||
17 | //#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR | |
18 | ||
19 | using boost::optional; | |
20 | ||
21 | struct implicit_bool_conv | |
22 | { | |
23 | operator bool() const { return false; } | |
24 | }; | |
25 | ||
26 | struct explicit_bool_conv | |
27 | { | |
28 | bool operator!() const BOOST_NOEXCEPT { return false; } | |
29 | BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() | |
30 | }; | |
31 | ||
32 | template <typename To, typename From> | |
33 | void test_convert_assign() | |
34 | { | |
35 | optional<To> oi; | |
36 | oi = From(); | |
37 | BOOST_TEST(oi); | |
38 | } | |
39 | ||
40 | void test_no_bad_assignment() | |
41 | { | |
42 | #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) | |
43 | // this means that type trait `boost::is_assignable` works. | |
44 | BOOST_STATIC_ASSERT((boost::is_assignable<optional<bool>&, bool>::value)); | |
45 | BOOST_STATIC_ASSERT((boost::is_assignable<optional<bool>&, implicit_bool_conv>::value)); | |
46 | BOOST_STATIC_ASSERT((! boost::is_assignable<optional<bool>&, explicit_bool_conv>::value)); | |
47 | #endif | |
48 | } | |
49 | ||
50 | int main() | |
51 | { | |
52 | test_convert_assign<int, short>(); | |
53 | test_convert_assign<bool, implicit_bool_conv>(); | |
54 | test_no_bad_assignment(); | |
55 | ||
56 | return boost::report_errors(); | |
57 | } |