]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/poly_collection/test/any_types.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / poly_collection / test / any_types.hpp
CommitLineData
11fdf7f2 1/* Copyright 2016-2018 Joaquin M Lopez Munoz.
b32b8144
FG
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
23namespace any_types{
24
25struct 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
37struct incrementable3
38{
39 incrementable3():n{-1}{}
40 incrementable3(int n):n{(double)n}{}
41 incrementable3& operator++(){++n;return *this;}
42 double n;
43};
44
45using concept_=boost::type_erasure::incrementable<>;
46using collection=boost::any_collection<concept_>;
47
48template<typename T=boost::type_erasure::_self>
49struct convertible_to_int
50{
51 static int apply(const T& x){return x;}
52};
53
54using t1=incrementable1;
55using t2=double;
56using t3=incrementable3;
57using t4=int;
58using 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
67struct to_int
68{
b32b8144
FG
69 template<typename Concept,typename Tag>
70 int operator()(const boost::type_erasure::any<Concept,Tag>& x)const
71 {
72 using boost::type_erasure::any_cast;
73
74 if(auto p=any_cast<t1*>(&x))return (*this)(*p);
75 if(auto p=any_cast<t2*>(&x))return (*this)(*p);
76 if(auto p=any_cast<t3*>(&x))return (*this)(*p);
77 if(auto p=any_cast<t4*>(&x))return (*this)(*p);
78 if(auto p=any_cast<t5*>(&x))return (*this)(*p);
79 else return 0;
80 }
81
82 int operator()(const t1& x)const{return x.n;}
83 int operator()(const t2& x)const{return static_cast<int>(x);};
84 int operator()(const t3& x)const{return static_cast<int>(x.n);}
85 int operator()(const t4& x)const{return x;}
86 int operator()(const t5& x)const
87 {
88 return boost::type_erasure::call(convertible_to_int<>{},x);
89 }
90};
91
92} /* namespace any_types */
93
94#endif