]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/poly_collection/test/function_types.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / poly_collection / test / function_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_FUNCTION_TYPES_HPP
10 #define BOOST_POLY_COLLECTION_TEST_FUNCTION_TYPES_HPP
11
12 #if defined(_MSC_VER)
13 #pragma once
14 #endif
15
16 #include <boost/poly_collection/function_collection.hpp>
17 #include <typeinfo>
18
19 namespace function_types{
20
21 struct function1 final
22 {
23 function1(int n):n{n}{}
24 function1(function1&&)=default;
25 function1(const function1&)=delete;
26 function1& operator=(function1&&)=default;
27 function1& operator=(const function1&)=delete;
28 int operator()(int)const{return n;}
29 friend bool operator==(
30 const function1& x,const function1& y){return x.n==y.n;}
31 int n;
32 };
33
34 struct function2
35 {
36 function2(int n):n{n}{}
37 int operator()(int x)const{return x*n;}
38 bool operator==(const function2& x)const{return n==x.n;}
39 int n;
40 };
41
42 struct function3
43 {
44 function3():n{-1}{}
45 function3(int n):n{n}{}
46 int operator()(int x)const{return x*x*n;}
47 int n;
48 };
49
50 struct function4:function3
51 {
52 using function3::function3;
53 int operator()(int x)const{return -(this->function3::operator()(x));}
54 bool operator==(const function4& x)const{return n==x.n;}
55 };
56
57 struct function5
58 {
59 function5(int n):n{n}{}
60 int operator()(int x)const{return x*x*x*n;}
61 int n;
62 };
63
64 struct int_alias /* brings this namespace into ADL for operator== below */
65 {
66 int_alias(int n):n{n}{}
67 operator int()const{return n;}
68 int n;
69 };
70
71 using signature=int_alias(int);
72 using collection=boost::function_collection<signature>;
73
74 using t1=function1;
75 using t2=function2;
76 using t3=function3;
77 using t4=function4;
78 using t5=function5;
79
80 inline bool operator==(
81 const collection::value_type& x,const collection::value_type& y)
82 {
83 const std::type_info& xi=x.target_type();
84 const std::type_info& yi=y.target_type();
85 if(xi==yi){
86 if(xi==typeid(t1))return (*x.target<t1>())==(*y.target<t1>());
87 if(xi==typeid(t2))return (*x.target<t2>()).operator==(*y.target<t2>());
88 if(xi==typeid(t4))return (*x.target<t4>()).operator==(*y.target<t4>());
89 }
90 return false;
91 }
92
93 inline bool operator==(const collection::value_type& x,const t1& y)
94 {
95 const std::type_info& xi=x.target_type();
96 if(xi==typeid(t1))return (*x.target<t1>())==y;
97 return false;
98 }
99
100 inline bool operator==(const t1& x,const collection::value_type& y)
101 {
102 return y==x;
103 }
104
105 inline bool operator==(const collection::value_type& x,const t2& y)
106 {
107 const std::type_info& xi=x.target_type();
108 if(xi==typeid(t2))return (*x.target<t2>())==y;
109 return false;
110 }
111
112 inline bool operator==(const t2& x,const collection::value_type& y)
113 {
114 return y==x;
115 }
116
117 inline bool operator==(const collection::value_type& x,const t4& y)
118 {
119 const std::type_info& xi=x.target_type();
120 if(xi==typeid(t4))return (*x.target<t4>())==y;
121 return false;
122 }
123
124 inline bool operator==(const t4& x,const collection::value_type& y)
125 {
126 return y==x;
127 }
128
129 inline bool operator==(const t1&,const t2&){return false;}
130 inline bool operator==(const t1&,const t4&){return false;}
131 inline bool operator==(const t2&,const t1&){return false;}
132 inline bool operator==(const t2&,const t4&){return false;}
133 inline bool operator==(const t4&,const t1&){return false;}
134 inline bool operator==(const t4&,const t2&){return false;}
135
136 struct to_int
137 {
138 to_int(){};
139
140 template<typename F>
141 int operator()(const F& f)const{return f(1);}
142 };
143
144 } /* namespace function_types */
145
146 #endif