File indexing completed on 2025-12-15 09:50:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
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
0047
0048
0049
0050
0051
0052
0053
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
0064 typedef Value const& result_type;
0065
0066
0067
0068
0069
0070
0071
0072 inline result_type operator()(Value const& v) const
0073 {
0074 return v;
0075 }
0076
0077
0078
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
0089
0090
0091
0092
0093
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
0106 typedef Indexable const& result_type;
0107
0108
0109
0110
0111
0112
0113
0114 inline result_type operator()(value_type const& v) const
0115 {
0116 return v.first;
0117 }
0118
0119
0120
0121
0122
0123
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
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
0147
0148
0149
0150
0151
0152
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
0165 typedef Indexable const& result_type;
0166
0167
0168
0169
0170
0171
0172
0173 inline result_type operator()(value_type const& v) const
0174 {
0175 return boost::get<0>(v);
0176 }
0177
0178
0179
0180
0181
0182
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
0197
0198
0199
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
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
0223
0224
0225
0226
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
0240
0241
0242
0243
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 }}}}
0255
0256 namespace boost { namespace geometry { namespace index { namespace detail {
0257
0258
0259
0260
0261
0262
0263
0264
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
0277 typedef Indexable const& result_type;
0278
0279
0280
0281
0282
0283
0284
0285 result_type operator()(value_type const& v) const
0286 {
0287 return std::get<0>(v);
0288 }
0289
0290
0291
0292
0293
0294
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
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 }}}}
0317
0318
0319 namespace boost { namespace geometry { namespace index {
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330 template <typename Value>
0331 struct indexable
0332 : detail::indexable<Value>
0333 {
0334
0335 typedef typename detail::indexable<Value>::result_type result_type;
0336
0337
0338
0339
0340
0341
0342
0343 inline result_type operator()(Value const& v) const
0344 {
0345 return detail::indexable<Value>::operator()(v);
0346 }
0347
0348
0349
0350
0351
0352
0353
0354
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 }}}
0364
0365 #endif