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)
6 * See http://www.boost.org/libs/poly_collection for library home page.
9 #ifndef BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
10 #define BOOST_POLY_COLLECTION_TEST_ANY_TYPES_HPP
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>
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;}
39 incrementable3():n{-1}{}
40 incrementable3(int n):n{(double)n}{}
41 incrementable3& operator++(){++n;return *this;}
45 using concept_=boost::type_erasure::incrementable<>;
46 using collection=boost::any_collection<concept_>;
48 template<typename T=boost::type_erasure::_self>
49 struct convertible_to_int
51 static int apply(const T& x){return x;}
54 using t1=incrementable1;
56 using t3=incrementable3;
58 using t5=boost::type_erasure::any<
60 boost::type_erasure::copy_constructible<>,
61 boost::type_erasure::assignable<>,
71 template<typename Concept,typename Tag>
72 int operator()(const boost::type_erasure::any<Concept,Tag>& x)const
74 using boost::type_erasure::any_cast;
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);
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
90 return boost::type_erasure::call(convertible_to_int<>{},x);
94 } /* namespace any_types */