std_any.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_STD_ANY_HPP
  7. #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ANY_HPP
  8. #include <boost/config.hpp>
  9. #ifndef BOOST_NO_CXX17_HDR_ANY
  10. #include <any>
  11. #include <utility>
  12. #include <boost/geometry/geometries/adapted/detail/any.hpp>
  13. #include <boost/geometry/core/geometry_types.hpp>
  14. #include <boost/geometry/core/tag.hpp>
  15. #include <boost/geometry/core/tags.hpp>
  16. #include <boost/geometry/core/visit.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. namespace detail
  20. {
  21. struct std_any_cast_policy
  22. {
  23. template <typename T, typename Any>
  24. static inline T * apply(Any * any_ptr)
  25. {
  26. return std::any_cast<T>(any_ptr);
  27. }
  28. };
  29. } // namespace detail
  30. namespace traits
  31. {
  32. template <>
  33. struct tag<std::any>
  34. {
  35. using type = dynamic_geometry_tag;
  36. };
  37. template <>
  38. struct visit<std::any>
  39. {
  40. template <typename Function, typename Any>
  41. static void apply(Function && function, Any && any)
  42. {
  43. using types_t = typename geometry_types<util::remove_cref_t<Any>>::type;
  44. geometry::detail::visit_any
  45. <
  46. geometry::detail::std_any_cast_policy, types_t
  47. >::template apply<0>(std::forward<Function>(function), std::forward<Any>(any));
  48. }
  49. };
  50. } // namespace traits
  51. }} // namespace boost::geometry
  52. #endif // BOOST_NO_CXX17_HDR_ANY
  53. #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_STD_ANY_HPP