boost_any.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Boost.Geometry
  2. // Copyright (c) 2021, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ANY_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ANY_HPP
  8. #include <utility>
  9. #include <boost/any.hpp>
  10. #include <boost/geometry/geometries/adapted/detail/any.hpp>
  11. #include <boost/geometry/core/geometry_types.hpp>
  12. #include <boost/geometry/core/tag.hpp>
  13. #include <boost/geometry/core/tags.hpp>
  14. #include <boost/geometry/core/visit.hpp>
  15. namespace boost { namespace geometry
  16. {
  17. namespace detail
  18. {
  19. struct boost_any_cast_policy
  20. {
  21. template <typename T, typename Any>
  22. static inline T * apply(Any * any_ptr)
  23. {
  24. return boost::any_cast<T>(any_ptr);
  25. }
  26. };
  27. } // namespace detail
  28. namespace traits
  29. {
  30. template <>
  31. struct tag<boost::any>
  32. {
  33. using type = dynamic_geometry_tag;
  34. };
  35. template <>
  36. struct visit<boost::any>
  37. {
  38. template <typename Function, typename Any>
  39. static void apply(Function && function, Any && any)
  40. {
  41. using types_t = typename geometry_types<util::remove_cref_t<Any>>::type;
  42. geometry::detail::visit_any
  43. <
  44. geometry::detail::boost_any_cast_policy, types_t
  45. >::template apply<0>(std::forward<Function>(function), std::forward<Any>(any));
  46. }
  47. };
  48. } // namespace traits
  49. }} // namespace boost::geometry
  50. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_ANY_HPP