File indexing completed on 2025-01-18 09:35:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
0019 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_VARIANT_HPP
0020
0021
0022 #include <boost/variant/apply_visitor.hpp>
0023 #include <boost/variant/static_visitor.hpp>
0024 #include <boost/variant/variant.hpp>
0025
0026
0027 #include <boost/geometry/core/geometry_types.hpp>
0028 #include <boost/geometry/core/point_type.hpp>
0029 #include <boost/geometry/core/tag.hpp>
0030 #include <boost/geometry/core/tags.hpp>
0031 #include <boost/geometry/core/visit.hpp>
0032 #include <boost/geometry/util/sequence.hpp>
0033
0034
0035 namespace boost { namespace geometry
0036 {
0037
0038 namespace detail
0039 {
0040
0041 template <typename Seq, typename ResultSeq = util::type_sequence<>>
0042 struct boost_variant_types;
0043
0044 template <typename T, typename ...Ts, typename ...Rs>
0045 struct boost_variant_types<util::type_sequence<T, Ts...>, util::type_sequence<Rs...>>
0046 {
0047 using type = typename boost_variant_types<util::type_sequence<Ts...>, util::type_sequence<Rs..., T>>::type;
0048 };
0049
0050 template <typename ...Ts, typename ...Rs>
0051 struct boost_variant_types<util::type_sequence<boost::detail::variant::void_, Ts...>, util::type_sequence<Rs...>>
0052 {
0053 using type = util::type_sequence<Rs...>;
0054 };
0055
0056 template <typename ...Rs>
0057 struct boost_variant_types<util::type_sequence<>, util::type_sequence<Rs...>>
0058 {
0059 using type = util::type_sequence<Rs...>;
0060 };
0061
0062
0063 }
0064
0065
0066
0067 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
0068 struct point_type<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
0069 : point_type
0070 <
0071 typename util::pack_front
0072 <
0073 BOOST_VARIANT_ENUM_PARAMS(T)
0074 >::type
0075 >
0076 {};
0077
0078
0079 namespace traits
0080 {
0081
0082 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
0083 struct tag<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
0084 {
0085 using type = dynamic_geometry_tag;
0086 };
0087
0088 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
0089 struct visit<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
0090 {
0091 template <typename Function>
0092 struct visitor
0093 : boost::static_visitor<>
0094 {
0095 visitor(Function function)
0096 : m_function(function)
0097 {}
0098
0099 template <typename Geometry>
0100 void operator()(Geometry && geometry)
0101 {
0102 m_function(std::forward<Geometry>(geometry));
0103 }
0104
0105 Function m_function;
0106 };
0107
0108 template <typename Function, typename Variant>
0109 static void apply(Function function, Variant && variant)
0110 {
0111 visitor<Function> visitor(function);
0112 boost::apply_visitor(visitor, std::forward<Variant>(variant));
0113 }
0114 };
0115
0116 template <BOOST_VARIANT_ENUM_PARAMS(typename T), BOOST_VARIANT_ENUM_PARAMS(typename U)>
0117 struct visit<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>>
0118 {
0119 template <typename Function>
0120 struct visitor
0121 : boost::static_visitor<>
0122 {
0123 visitor(Function function)
0124 : m_function(function)
0125 {}
0126
0127 template <typename Geometry1, typename Geometry2>
0128 void operator()(Geometry1 && geometry1, Geometry2 && geometry2)
0129 {
0130 m_function(std::forward<Geometry1>(geometry1),
0131 std::forward<Geometry2>(geometry2));
0132 }
0133
0134 Function m_function;
0135 };
0136
0137 template <typename Function, typename Variant1, typename Variant2>
0138 static void apply(Function function, Variant1 && variant1, Variant2 && variant2)
0139 {
0140 visitor<Function> visitor(function);
0141 boost::apply_visitor(visitor,
0142 std::forward<Variant1>(variant1),
0143 std::forward<Variant2>(variant2));
0144 }
0145 };
0146
0147
0148 #ifdef BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES
0149
0150 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
0151 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
0152 {
0153 using type = typename geometry::detail::boost_variant_types
0154 <
0155 util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>
0156 >::type;
0157 };
0158
0159 #else
0160
0161 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
0162 struct geometry_types<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>>
0163 {
0164 using type = util::type_sequence<BOOST_VARIANT_ENUM_PARAMS(T)>;
0165 };
0166
0167 #endif
0168
0169 }
0170
0171
0172 }}
0173
0174
0175 #endif