1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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
11 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
12 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
18 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
19 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
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>
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>
35 namespace boost { namespace geometry
41 template <typename Seq, typename ResultSeq = util::type_sequence<>>
42 struct boost_variant_types;
44 template <typename T, typename ...Ts, typename ...Rs>
45 struct boost_variant_types<util::type_sequence<T, Ts...>, util::type_sequence<Rs...>>
47 using type = typename boost_variant_types<util::type_sequence<Ts...>, util::type_sequence<Rs..., T>>::type;
50 template <typename ...Ts, typename ...Rs>
51 struct boost_variant_types<util::type_sequence<boost::detail::variant::void_, Ts...>, util::type_sequence<Rs...>>
53 using type = util::type_sequence<Rs...>;
56 template <typename ...Rs>
57 struct boost_variant_types<util::type_sequence<>, util::type_sequence<Rs...>>
59 using type = util::type_sequence<Rs...>;
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)> >
71 typename util::pack_front
73 BOOST_VARIANT_ENUM_PARAMS(T)
82 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
83 struct tag<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
85 using type = dynamic_geometry_tag;
88 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
89 struct visit<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
91 template <typename Function>
93 : boost::static_visitor<>
95 visitor(Function function)
96 : m_function(function)
99 template <typename Geometry>
100 void operator()(Geometry && geometry)
102 m_function(std::forward<Geometry>(geometry));
108 template <typename Function, typename Variant>
109 static void apply(Function function, Variant && variant)
111 visitor<Function> visitor(function);
112 boost::apply_visitor(visitor, std::forward<Variant>(variant));
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)>>
119 template <typename Function>
121 : boost::static_visitor<>
123 visitor(Function function)
124 : m_function(function)
127 template <typename Geometry1, typename Geometry2>
128 void operator()(Geometry1 && geometry1, Geometry2 && geometry2)
130 m_function(std::forward<Geometry1>(geometry1),
131 std::forward<Geometry2>(geometry2));
137 template <typename Function, typename Variant1, typename Variant2>
138 static void apply(Function function, Variant1 && variant1, Variant2 && variant2)
140 visitor<Function> visitor(function);
141 boost::apply_visitor(visitor,
142 std::forward<Variant1>(variant1),
143 std::forward<Variant2>(variant2));
148 #ifdef BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
150 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
151 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
153 using type = typename geometry::detail::boost_variant_types
155 util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>
159 #else // BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
161 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
162 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
164 using type = util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>;
167 #endif // BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
169 } // namespace traits
172 }} // namespace boost::geometry
175 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP