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