Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:27

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2021, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0006 
0007 // Licensed under the Boost Software License version 1.0.
0008 // http://www.boost.org/users/license.html
0009 
0010 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_DETAIL_ANY_HPP
0011 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_DETAIL_ANY_HPP
0012 
0013 
0014 #include <utility>
0015 
0016 #include <boost/geometry/util/sequence.hpp>
0017 #include <boost/geometry/util/type_traits_std.hpp>
0018 
0019 
0020 namespace boost { namespace geometry
0021 {
0022 
0023 namespace detail
0024 {
0025 
0026 template
0027 <
0028     typename CastPolicy,
0029     typename TypeSequence,
0030     std::size_t N = util::sequence_size<TypeSequence>::value
0031 >
0032 struct visit_any
0033 {
0034     static const std::size_t M = N / 2;
0035 
0036     template <std::size_t Offset, typename Function, typename Any>
0037     static bool apply(Function && function, Any && any)
0038     {
0039         return visit_any<CastPolicy, TypeSequence, M>::template apply<Offset>(
0040                     std::forward<Function>(function), std::forward<Any>(any))
0041             || visit_any<CastPolicy, TypeSequence, N - M>::template apply<Offset + M>(
0042                     std::forward<Function>(function), std::forward<Any>(any));
0043     }
0044 };
0045 
0046 template <typename CastPolicy, typename TypeSequence>
0047 struct visit_any<CastPolicy, TypeSequence, 1>
0048 {
0049     template <std::size_t Offset, typename Function, typename Any>
0050     static bool apply(Function && function, Any && any)
0051     {
0052         using elem_t = typename util::sequence_element<Offset, TypeSequence>::type;
0053         using geom_t = util::transcribe_const_t<std::remove_reference_t<Any>, elem_t>;
0054         geom_t * g = CastPolicy::template apply<geom_t>(&any);
0055         if (g != nullptr)
0056         {
0057             using geom_ref_t = std::conditional_t
0058                 <
0059                     std::is_rvalue_reference<decltype(any)>::value,
0060                     geom_t&&, geom_t&
0061                 >;
0062             function(static_cast<geom_ref_t>(*g));
0063             return true;
0064         }
0065         else
0066         {
0067             return false;
0068         }
0069     }
0070 };
0071 
0072 template <typename CastPolicy, typename TypeSequence>
0073 struct visit_any<CastPolicy, TypeSequence, 0>
0074 {
0075     template <std::size_t Offset, typename Function, typename Any>
0076     static bool apply(Function &&, Any &&)
0077     {
0078         return false;
0079     }
0080 };
0081 
0082 } // namespace detail
0083 
0084 }} // namespace boost::geometry
0085 
0086 
0087 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_DETAIL_ANY_HPP