]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/poly_collection/test/any_types.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / poly_collection / test / any_types.hpp
1 /* Copyright 2016-2017 Joaquin M Lopez Munoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * See http://www.boost.org/libs/poly_collection for library home page.
7 */
8
9 #ifndef BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
10 #define BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/mpl/vector/vector10.hpp>
17 #include <boost/poly_collection/any_collection.hpp>
18 #include <boost/type_erasure/any_cast.hpp>
19 #include <boost/type_erasure/builtin.hpp>
20 #include <boost/type_erasure/call.hpp>
21 #include <boost/type_erasure/operators.hpp>
22
23 namespace any_types{
24
25 struct incrementable1
26 {
27 incrementable1(int n):n{n}{}
28 incrementable1(incrementable1&&)=default;
29 incrementable1(const incrementable1&)=delete;
30 incrementable1& operator=(incrementable1&&)=default;
31 incrementable1& operator=(const incrementable1&)=delete;
32 bool operator==(const incrementable1& x)const{return n==x.n;}
33 incrementable1& operator++(){++n;return *this;}
34 int n;
35 };
36
37 struct incrementable3
38 {
39 incrementable3():n{-1}{}
40 incrementable3(int n):n{(double)n}{}
41 incrementable3& operator++(){++n;return *this;}
42 double n;
43 };
44
45 using concept_=boost::type_erasure::incrementable<>;
46 using collection=boost::any_collection<concept_>;
47
48 template<typename T=boost::type_erasure::_self>
49 struct convertible_to_int
50 {
51 static int apply(const T& x){return x;}
52 };
53
54 using t1=incrementable1;
55 using t2=double;
56 using t3=incrementable3;
57 using t4=int;
58 using t5=boost::type_erasure::any<
59 boost::mpl::vector4<
60 boost::type_erasure::copy_constructible<>,
61 boost::type_erasure::assignable<>,
62 concept_,
63 convertible_to_int<>
64 >
65 >;
66
67 struct to_int
68 {
69 to_int(){};
70
71 template<typename Concept,typename Tag>
72 int operator()(const boost::type_erasure::any<Concept,Tag>& x)const
73 {
74 using boost::type_erasure::any_cast;
75
76 if(auto p=any_cast<t1*>(&x))return (*this)(*p);
77 if(auto p=any_cast<t2*>(&x))return (*this)(*p);
78 if(auto p=any_cast<t3*>(&x))return (*this)(*p);
79 if(auto p=any_cast<t4*>(&x))return (*this)(*p);
80 if(auto p=any_cast<t5*>(&x))return (*this)(*p);
81 else return 0;
82 }
83
84 int operator()(const t1& x)const{return x.n;}
85 int operator()(const t2& x)const{return static_cast<int>(x);};
86 int operator()(const t3& x)const{return static_cast<int>(x.n);}
87 int operator()(const t4& x)const{return x;}
88 int operator()(const t5& x)const
89 {
90 return boost::type_erasure::call(convertible_to_int<>{},x);
91 }
92 };
93
94 } /* namespace any_types */
95
96 #endif