]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/variant/test/variant_over_joint_view_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / variant / test / variant_over_joint_view_test.cpp
CommitLineData
b32b8144
FG
1// Copyright (c) 2017
2// Mikhail Maximov
3//
4// Distributed under the Boost Software License, Version 1.0. (See
5// accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// The test is base on https://svn.boost.org/trac/boost/ticket/8554
9// variant was not able to extract types from mpl::joint_view
10
11#include <string>
12
13#include "boost/config.hpp"
92f5a8d4 14#include "boost/core/lightweight_test.hpp"
b32b8144
FG
15
16#include "boost/variant.hpp"
17#include "boost/mpl/joint_view.hpp"
18#include "boost/mpl/insert_range.hpp"
19#include "boost/mpl/set.hpp"
20
21template<class T, class Variant>
22void check_exception_on_get(Variant& v) {
23 try {
24 boost::get<T>(v);
92f5a8d4 25 BOOST_ERROR("Expected exception boost::bad_get, but got nothing.");
b32b8144 26 } catch (boost::bad_get&) { //okay it is expected behaviour
92f5a8d4 27 } catch (...) { BOOST_ERROR("Expected exception boost::bad_get, but got something else."); }
b32b8144
FG
28}
29
30void test_joint_view() {
31 typedef boost::variant<int> v1;
32 typedef boost::variant<std::string> v2;
33 typedef boost::make_variant_over<boost::mpl::joint_view<v1::types, v2::types>::type>::type v3;
34
35 v1 a = 1;
36 v2 b = "2";
37 v3 c = a;
92f5a8d4
TL
38 BOOST_TEST(boost::get<int>(c) == 1);
39 BOOST_TEST(c.which() == 0);
b32b8144 40 v3 d = b;
92f5a8d4
TL
41 BOOST_TEST(boost::get<std::string>(d) == "2");
42 BOOST_TEST(d.which() == 1);
b32b8144
FG
43 check_exception_on_get<std::string>(c);
44 check_exception_on_get<int>(d);
45}
46
47void test_set() {
48 typedef boost::mpl::set2< std::string, int > types;
49 typedef boost::make_variant_over< types >::type v;
50
51 v a = 1;
92f5a8d4 52 BOOST_TEST(boost::get<int>(a) == 1);
b32b8144
FG
53 check_exception_on_get<std::string>(a);
54 a = "2";
92f5a8d4 55 BOOST_TEST(boost::get<std::string>(a) == "2");
b32b8144
FG
56 check_exception_on_get<int>(a);
57}
58
92f5a8d4 59int main()
b32b8144
FG
60{
61 test_joint_view();
62 test_set();
92f5a8d4
TL
63 return boost::report_errors();
64}