1 /* Copyright 2016-2018 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)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_TEST_FUNCTION_TYPES_HPP
10 #define BOOST_POLY_COLLECTION_TEST_FUNCTION_TYPES_HPP
16 #include <boost/poly_collection/function_collection.hpp>
19 namespace function_types{
21 struct function1 final
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;}
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;}
45 function3(int n):n{n}{}
46 int operator()(int x)const{return x*x*n;}
50 struct function4:function3
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;}
59 function5(int n):n{n}{}
60 int operator()(int x)const{return x*x*x*n;}
64 struct int_alias /* brings this namespace into ADL for operator== below */
66 int_alias(int n):n{n}{}
67 operator int()const{return n;}
71 using signature=int_alias(int);
72 using collection=boost::function_collection<signature>;
80 inline bool operator==(
81 const collection::value_type& x,const collection::value_type& y)
83 const std::type_info& xi=x.target_type();
84 const std::type_info& yi=y.target_type();
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>());
93 inline bool operator==(const collection::value_type& x,const t1& y)
95 const std::type_info& xi=x.target_type();
96 if(xi==typeid(t1))return (*x.target<t1>())==y;
100 inline bool operator==(const t1& x,const collection::value_type& y)
105 inline bool operator==(const collection::value_type& x,const t2& y)
107 const std::type_info& xi=x.target_type();
108 if(xi==typeid(t2))return (*x.target<t2>())==y;
112 inline bool operator==(const t2& x,const collection::value_type& y)
117 inline bool operator==(const collection::value_type& x,const t4& y)
119 const std::type_info& xi=x.target_type();
120 if(xi==typeid(t4))return (*x.target<t4>())==y;
124 inline bool operator==(const t4& x,const collection::value_type& y)
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;}
139 int operator()(const F& f)const{return f(1);}
142 } /* namespace function_types */