Add DynamicGeometry adaptation for std::variant.

This commit is contained in:
Adam Wulkiewicz 2021-05-28 18:36:32 +02:00
parent d690364aa0
commit 6e71295d64
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,80 @@
// Boost.Geometry
// Copyright (c) 2021, Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
#ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_VARIANT_HPP
#define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_VARIANT_HPP
#include <boost/config.hpp>
#ifndef BOOST_NO_CXX17_HDR_VARIANT
#include <utility>
#include <variant>
#include <boost/geometry/core/geometry_types.hpp>
#include <boost/geometry/core/tag.hpp>
#include <boost/geometry/core/tags.hpp>
#include <boost/geometry/core/visit.hpp>
#include <boost/geometry/util/sequence.hpp>
namespace boost { namespace geometry
{
namespace traits
{
template <typename ...Ts>
struct tag<std::variant<Ts...>>
{
typedef dynamic_geometry_tag type;
};
template <typename ...Ts>
struct visit<std::variant<Ts...>>
{
template <typename Function, typename Variant>
static void apply(Function && function, Variant && variant)
{
std::visit(std::forward<Function>(function),
std::forward<Variant>(variant));
}
};
template <typename ...Ts, typename ...Us>
struct visit<std::variant<Ts...>, std::variant<Us...>>
{
template <typename Function, typename Variant1, typename Variant2>
static void apply(Function && function, Variant1 && variant1, Variant2 && variant2)
{
std::visit(std::forward<Function>(function),
std::forward<Variant1>(variant1),
std::forward<Variant2>(variant2));
}
};
template <typename ...Ts>
struct geometry_types<std::variant<Ts...>>
{
typedef util::type_sequence<Ts...> type;
};
} // namespace traits
}} // namespace boost::geometry
#endif // BOOST_NO_CXX17_HDR_VARIANT
#endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_VARIANT_HPP

View File

@ -15,6 +15,7 @@
#include <boost/geometry/geometries/adapted/boost_any.hpp>
#include <boost/geometry/geometries/adapted/boost_variant.hpp>
#include <boost/geometry/geometries/adapted/boost_variant2.hpp>
#include <boost/geometry/geometries/adapted/std_variant.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/util/type_traits.hpp>
@ -199,5 +200,9 @@ int test_main(int, char* [])
test_all<boost::variant<point_t, linestring_t, polygon_t>>();
test_all<boost::variant2::variant<point_t, linestring_t, polygon_t>>();
#ifndef BOOST_NO_CXX17_HDR_VARIANT
test_all<std::variant<point_t, linestring_t, polygon_t>>();
#endif
return 0;
}