Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:50:40

0001 // Boost.Geometry Index
0002 //
0003 // Copyright (c) 2011-2019 Adam Wulkiewicz, Lodz, Poland.
0004 //
0005 // This file was modified by Oracle on 2020.
0006 // Modifications copyright (c) 2020 Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 //
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
0014 #define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
0015 
0016 #include <boost/tuple/tuple.hpp>
0017 
0018 #include <boost/geometry/core/static_assert.hpp>
0019 
0020 #include <boost/geometry/index/detail/is_indexable.hpp>
0021 
0022 #include <boost/geometry/util/type_traits.hpp>
0023 
0024 #include <tuple>
0025 
0026 namespace boost { namespace geometry { namespace index { namespace detail
0027 {
0028 
0029 template <typename From, typename To>
0030 struct is_referencable
0031     : std::is_same
0032         <
0033             typename util::remove_cref<From>::type,
0034             typename util::remove_cref<To>::type
0035         >
0036 {};
0037 
0038 template <typename Indexable, typename V>
0039 inline Indexable const& indexable_prevent_any_type(V const& )
0040 {
0041     BOOST_GEOMETRY_STATIC_ASSERT_FALSE("Unexpected type.", V);
0042     return Indexable();
0043 }
0044 
0045 /*!
0046 \brief The function object extracting Indexable from Value.
0047 
0048 It translates Value object to Indexable object. The default version handles Values which are Indexables.
0049 This template is also specialized for std::pair<Indexable, T2>, boost::tuple<Indexable, ...>
0050 and std::tuple<Indexable, ...>.
0051 
0052 \tparam Value       The Value type which may be translated directly to the Indexable.
0053 \tparam IsIndexable If true, the const reference to Value is returned.
0054 */
0055 template <typename Value, bool IsIndexable = is_indexable<Value>::value>
0056 struct indexable
0057 {
0058     BOOST_GEOMETRY_STATIC_ASSERT(
0059         (detail::is_indexable<Value>::value),
0060         "Value has to be an Indexable.",
0061         Value);
0062 
0063     /*! \brief The type of result returned by function object. */
0064     typedef Value const& result_type;
0065 
0066     /*!
0067     \brief Return indexable extracted from the value.
0068 
0069     \param v The value.
0070     \return The indexable.
0071     */
0072     inline result_type operator()(Value const& v) const
0073     {
0074         return v;
0075     }
0076 
0077     /*!
0078     \brief Prevent reference to temporary for types convertible to Value.
0079     */
0080     template <typename V>
0081     inline result_type operator()(V const& v) const
0082     {
0083         return indexable_prevent_any_type<Value>(v);
0084     }
0085 };
0086 
0087 /*!
0088 \brief The function object extracting Indexable from Value.
0089 
0090 This specialization translates from std::pair<Indexable, T2>.
0091 
0092 \tparam Indexable       The Indexable type.
0093 \tparam Second          The second type.
0094 */
0095 template <typename Indexable, typename Second>
0096 struct indexable<std::pair<Indexable, Second>, false>
0097 {
0098     typedef std::pair<Indexable, Second> value_type;
0099 
0100     BOOST_GEOMETRY_STATIC_ASSERT(
0101         (detail::is_indexable<Indexable>::value),
0102         "The first type of std::pair has to be an Indexable.",
0103         Indexable);
0104 
0105     /*! \brief The type of result returned by function object. */
0106     typedef Indexable const& result_type;
0107 
0108     /*!
0109     \brief Return indexable extracted from the value.
0110 
0111     \param v The value.
0112     \return The indexable.
0113     */
0114     inline result_type operator()(value_type const& v) const
0115     {
0116         return v.first;
0117     }
0118 
0119     /*!
0120     \brief Return indexable extracted from compatible type different than value_type.
0121 
0122     \param v The value.
0123     \return The indexable.
0124     */
0125     template <typename I, typename S>
0126     inline result_type operator()(std::pair<I, S> const& v) const
0127     {
0128         BOOST_GEOMETRY_STATIC_ASSERT(
0129             (is_referencable<I, result_type>::value),
0130             "Unexpected type.",
0131             std::pair<I, S>);
0132         return v.first;
0133     }
0134 
0135     /*!
0136     \brief Prevent reference to temporary for types convertible to Value.
0137     */
0138     template <typename V>
0139     inline result_type operator()(V const& v) const
0140     {
0141         return indexable_prevent_any_type<Indexable>(v);
0142     }
0143 };
0144 
0145 /*!
0146 \brief The function object extracting Indexable from Value.
0147 
0148 This specialization translates from boost::tuple<Indexable, ...>
0149   or boost::tuples::cons<Indexable, ...>.
0150 
0151 \tparam Value       The Value type.
0152 \tparam Indexable   The Indexable type.
0153 */
0154 template <typename Value, typename Indexable>
0155 struct indexable_boost_tuple
0156 {
0157     typedef Value value_type;
0158 
0159     BOOST_GEOMETRY_STATIC_ASSERT(
0160         (detail::is_indexable<Indexable>::value),
0161         "The first type of boost::tuple has to be an Indexable.",
0162         Indexable);
0163 
0164     /*! \brief The type of result returned by function object. */
0165     typedef Indexable const& result_type;
0166 
0167     /*!
0168     \brief Return indexable extracted from the value.
0169 
0170     \param v The value.
0171     \return The indexable.
0172     */
0173     inline result_type operator()(value_type const& v) const
0174     {
0175         return boost::get<0>(v);
0176     }
0177 
0178     /*!
0179     \brief Return indexable extracted from compatible type different than value_type.
0180 
0181     \param v The value.
0182     \return The indexable.
0183     */
0184     template <typename I, typename U1, typename U2, typename U3, typename U4,
0185               typename U5, typename U6, typename U7, typename U8, typename U9>
0186     inline result_type operator()(boost::tuple<I, U1, U2, U3, U4, U5, U6, U7, U8, U9> const& v) const
0187     {
0188         BOOST_GEOMETRY_STATIC_ASSERT(
0189             (is_referencable<I, result_type>::value),
0190             "Unexpected type.",
0191             boost::tuple<I, U1, U2, U3, U4, U5, U6, U7, U8, U9>);
0192         return boost::get<0>(v);
0193     }
0194 
0195     /*!
0196     \brief Return indexable extracted from compatible type different than value_type.
0197 
0198     \param v The value.
0199     \return The indexable.
0200     */
0201     template <typename I, typename T>
0202     inline result_type operator()(boost::tuples::cons<I, T> const& v) const
0203     {
0204         BOOST_GEOMETRY_STATIC_ASSERT(
0205             (is_referencable<I, result_type>::value),
0206             "Unexpected type.",
0207             boost::tuples::cons<I, T>);
0208         return boost::get<0>(v);
0209     }
0210 
0211     /*!
0212     \brief Prevent reference to temporary for types convertible to Value.
0213     */
0214     template <typename V>
0215     inline result_type operator()(V const& v) const
0216     {
0217         return indexable_prevent_any_type<Indexable>(v);
0218     }
0219 };
0220 
0221 /*!
0222 \brief The function object extracting Indexable from Value.
0223 
0224 This specialization translates from boost::tuple<Indexable, ...>.
0225 
0226 \tparam Indexable   The Indexable type.
0227 */
0228 template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
0229           typename T5, typename T6, typename T7, typename T8, typename T9>
0230 struct indexable<boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
0231     : indexable_boost_tuple
0232         <
0233             boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
0234             Indexable
0235         >
0236 {};
0237 
0238 /*!
0239 \brief The function object extracting Indexable from Value.
0240 
0241 This specialization translates from boost::tuples::cons<Indexable, ...>.
0242 
0243 \tparam Indexable   The Indexable type.
0244 */
0245 template <typename Indexable, typename Tail>
0246 struct indexable<boost::tuples::cons<Indexable, Tail>, false>
0247     : indexable_boost_tuple
0248         <
0249             boost::tuples::cons<Indexable, Tail>,
0250             Indexable
0251         >
0252 {};
0253 
0254 }}}} // namespace boost::geometry::index::detail
0255 
0256 namespace boost { namespace geometry { namespace index { namespace detail {
0257 
0258 /*!
0259 \brief The function object extracting Indexable from Value.
0260 
0261 This specialization translates from std::tuple<Indexable, Args...>.
0262 It's defined if the compiler supports tuples and variadic templates.
0263 
0264 \tparam Indexable   The Indexable type.
0265 */
0266 template <typename Indexable, typename ...Args>
0267 struct indexable<std::tuple<Indexable, Args...>, false>
0268 {
0269     typedef std::tuple<Indexable, Args...> value_type;
0270 
0271     BOOST_GEOMETRY_STATIC_ASSERT(
0272         (detail::is_indexable<Indexable>::value),
0273         "The first type of std::tuple has to be an Indexable.",
0274         Indexable);
0275 
0276     /*! \brief The type of result returned by function object. */
0277     typedef Indexable const& result_type;
0278 
0279     /*!
0280     \brief Return indexable extracted from the value.
0281 
0282     \param v The value.
0283     \return The indexable.
0284     */
0285     result_type operator()(value_type const& v) const
0286     {
0287         return std::get<0>(v);
0288     }
0289 
0290     /*!
0291     \brief Return indexable extracted from compatible type different than value_type.
0292 
0293     \param v The value.
0294     \return The indexable.
0295     */
0296     template <typename I, typename ...A>
0297     inline result_type operator()(std::tuple<I, A...> const& v) const
0298     {
0299         BOOST_GEOMETRY_STATIC_ASSERT(
0300             (is_referencable<I, result_type>::value),
0301             "Unexpected type.",
0302             std::tuple<I, A...>);
0303         return std::get<0>(v);
0304     }
0305 
0306     /*!
0307     \brief Prevent reference to temporary for types convertible to Value.
0308     */
0309     template <typename V>
0310     inline result_type operator()(V const& v) const
0311     {
0312         return indexable_prevent_any_type<Indexable>(v);
0313     }
0314 };
0315 
0316 }}}} // namespace boost::geometry::index::detail
0317 
0318 
0319 namespace boost { namespace geometry { namespace index {
0320 
0321 /*!
0322 \brief The function object extracting Indexable from Value.
0323 
0324 It translates Value object to Indexable object. By default, it can handle Values which are Indexables,
0325 std::pair<Indexable, T2>, boost::tuple<Indexable, ...> and std::tuple<Indexable, ...> if STD tuples
0326 and variadic templates are supported.
0327 
0328 \tparam Value       The Value type which may be translated directly to the Indexable.
0329 */
0330 template <typename Value>
0331 struct indexable
0332     : detail::indexable<Value>
0333 {
0334     /*! \brief The type of result returned by function object. It should be const Indexable reference. */
0335     typedef typename detail::indexable<Value>::result_type result_type;
0336 
0337     /*!
0338     \brief Return indexable extracted from the value.
0339 
0340     \param v The value.
0341     \return The indexable.
0342     */
0343     inline result_type operator()(Value const& v) const
0344     {
0345         return detail::indexable<Value>::operator()(v);
0346     }
0347 
0348     /*!
0349     \brief Return indexable extracted from the value. Overload for types
0350            compatible with Value but different yet holding referencable
0351            Indexable, e.g. tuple containing a reference.
0352 
0353     \param v The value.
0354     \return The indexable.
0355     */
0356     template <typename V>
0357     inline result_type operator()(V const& v) const
0358     {
0359         return detail::indexable<Value>::operator()(v);
0360     }
0361 };
0362 
0363 }}} // namespace boost::geometry::index
0364 
0365 #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP