]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/geometries/adapted/boost_variant.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / geometries / adapted / boost_variant.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // This file was modified by Oracle on 2018-2021.
8 // Modifications copyright (c) 2018-2021, Oracle and/or its affiliates.
9 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13
14 // Use, modification and distribution is subject to the Boost Software License,
15 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
16 // http://www.boost.org/LICENSE_1_0.txt)
17
18 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
19 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
20
21
22 #include <boost/variant/apply_visitor.hpp>
23 #include <boost/variant/static_visitor.hpp>
24 #include <boost/variant/variant.hpp>
25 //#include <boost/variant/variant_fwd.hpp>
26
27 #include <boost/geometry/core/geometry_types.hpp>
28 #include <boost/geometry/core/point_type.hpp>
29 #include <boost/geometry/core/tag.hpp>
30 #include <boost/geometry/core/tags.hpp>
31 #include <boost/geometry/core/visit.hpp>
32 #include <boost/geometry/util/sequence.hpp>
33
34
35 namespace boost { namespace geometry
36 {
37
38 namespace detail
39 {
40
41 template <typename Seq, typename ResultSeq = util::type_sequence<>>
42 struct boost_variant_types;
43
44 template <typename T, typename ...Ts, typename ...Rs>
45 struct boost_variant_types<util::type_sequence<T, Ts...>, util::type_sequence<Rs...>>
46 {
47 using type = typename boost_variant_types<util::type_sequence<Ts...>, util::type_sequence<Rs..., T>>::type;
48 };
49
50 template <typename ...Ts, typename ...Rs>
51 struct boost_variant_types<util::type_sequence<boost::detail::variant::void_, Ts...>, util::type_sequence<Rs...>>
52 {
53 using type = util::type_sequence<Rs...>;
54 };
55
56 template <typename ...Rs>
57 struct boost_variant_types<util::type_sequence<>, util::type_sequence<Rs...>>
58 {
59 using type = util::type_sequence<Rs...>;
60 };
61
62
63 } // namespace detail
64
65
66 // TODO: This is not used anywhere in the header files. Only in tests.
67 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
68 struct point_type<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
69 : point_type
70 <
71 typename util::pack_front
72 <
73 BOOST_VARIANT_ENUM_PARAMS(T)
74 >::type
75 >
76 {};
77
78
79 namespace traits
80 {
81
82 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
83 struct tag<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
84 {
85 using type = dynamic_geometry_tag;
86 };
87
88 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
89 struct visit<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
90 {
91 template <typename Function>
92 struct visitor
93 : boost::static_visitor<>
94 {
95 visitor(Function function)
96 : m_function(function)
97 {}
98
99 template <typename Geometry>
100 void operator()(Geometry && geometry)
101 {
102 m_function(std::forward<Geometry>(geometry));
103 }
104
105 Function m_function;
106 };
107
108 template <typename Function, typename Variant>
109 static void apply(Function function, Variant && variant)
110 {
111 visitor<Function> visitor(function);
112 boost::apply_visitor(visitor, std::forward<Variant>(variant));
113 }
114 };
115
116 template <BOOST_VARIANT_ENUM_PARAMS(typename T), BOOST_VARIANT_ENUM_PARAMS(typename U)>
117 struct visit<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>>
118 {
119 template <typename Function>
120 struct visitor
121 : boost::static_visitor<>
122 {
123 visitor(Function function)
124 : m_function(function)
125 {}
126
127 template <typename Geometry1, typename Geometry2>
128 void operator()(Geometry1 && geometry1, Geometry2 && geometry2)
129 {
130 m_function(std::forward<Geometry1>(geometry1),
131 std::forward<Geometry2>(geometry2));
132 }
133
134 Function m_function;
135 };
136
137 template <typename Function, typename Variant1, typename Variant2>
138 static void apply(Function function, Variant1 && variant1, Variant2 && variant2)
139 {
140 visitor<Function> visitor(function);
141 boost::apply_visitor(visitor,
142 std::forward<Variant1>(variant1),
143 std::forward<Variant2>(variant2));
144 }
145 };
146
147
148 #ifdef BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
149
150 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
151 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
152 {
153 using type = typename geometry::detail::boost_variant_types
154 <
155 util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>
156 >::type;
157 };
158
159 #else // BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
160
161 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
162 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
163 {
164 using type = util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>;
165 };
166
167 #endif // BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
168
169 } // namespace traits
170
171
172 }} // namespace boost::geometry
173
174
175 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP