annotate DEPENDENCIES/generic/include/boost/geometry/index/detail/tuples.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Geometry Index
Chris@16 2 //
Chris@16 3 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
Chris@16 4 //
Chris@16 5 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8
Chris@16 9 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_TUPLES_HPP
Chris@16 10 #define BOOST_GEOMETRY_INDEX_DETAIL_TUPLES_HPP
Chris@16 11
Chris@16 12 #include <boost/tuple/tuple.hpp>
Chris@16 13 #include <boost/type_traits/is_same.hpp>
Chris@16 14
Chris@16 15 // TODO move this to index/tuples and separate algorithms
Chris@16 16
Chris@16 17 namespace boost { namespace geometry { namespace index { namespace detail {
Chris@16 18
Chris@16 19 namespace tuples {
Chris@16 20
Chris@16 21 // find_index
Chris@16 22
Chris@16 23 namespace detail {
Chris@16 24
Chris@16 25 template <typename Tuple, typename El, size_t N>
Chris@16 26 struct find_index;
Chris@16 27
Chris@16 28 template <typename Tuple, typename El, size_t N, typename CurrentEl>
Chris@16 29 struct find_index_impl
Chris@16 30 {
Chris@16 31 static const size_t value = find_index<Tuple, El, N - 1>::value;
Chris@16 32 };
Chris@16 33
Chris@16 34 template <typename Tuple, typename El, size_t N>
Chris@16 35 struct find_index_impl<Tuple, El, N, El>
Chris@16 36 {
Chris@16 37 static const size_t value = N - 1;
Chris@16 38 };
Chris@16 39
Chris@16 40 template <typename Tuple, typename El, typename CurrentEl>
Chris@16 41 struct find_index_impl<Tuple, El, 1, CurrentEl>
Chris@16 42 {
Chris@16 43 BOOST_MPL_ASSERT_MSG(
Chris@16 44 (false),
Chris@16 45 ELEMENT_NOT_FOUND,
Chris@16 46 (find_index_impl));
Chris@16 47 };
Chris@16 48
Chris@16 49 template <typename Tuple, typename El>
Chris@16 50 struct find_index_impl<Tuple, El, 1, El>
Chris@16 51 {
Chris@16 52 static const size_t value = 0;
Chris@16 53 };
Chris@16 54
Chris@16 55 template <typename Tuple, typename El, size_t N>
Chris@16 56 struct find_index
Chris@16 57 {
Chris@16 58 static const size_t value =
Chris@16 59 find_index_impl<
Chris@16 60 Tuple,
Chris@16 61 El,
Chris@16 62 N,
Chris@16 63 typename boost::tuples::element<N - 1, Tuple>::type
Chris@16 64 >::value;
Chris@16 65 };
Chris@16 66
Chris@16 67 } // namespace detail
Chris@16 68
Chris@16 69 template <typename Tuple, typename El>
Chris@16 70 struct find_index
Chris@16 71 {
Chris@16 72 static const size_t value =
Chris@16 73 detail::find_index<
Chris@16 74 Tuple,
Chris@16 75 El,
Chris@16 76 boost::tuples::length<Tuple>::value
Chris@16 77 >::value;
Chris@16 78 };
Chris@16 79
Chris@16 80 // has
Chris@16 81
Chris@16 82 namespace detail {
Chris@16 83
Chris@16 84 template <typename Tuple, typename El, size_t N>
Chris@16 85 struct has
Chris@16 86 {
Chris@16 87 static const bool value
Chris@16 88 = boost::is_same<
Chris@16 89 typename boost::tuples::element<N - 1, Tuple>::type,
Chris@16 90 El
Chris@16 91 >::value
Chris@16 92 || has<Tuple, El, N - 1>::value;
Chris@16 93 };
Chris@16 94
Chris@16 95 template <typename Tuple, typename El>
Chris@16 96 struct has<Tuple, El, 1>
Chris@16 97 {
Chris@16 98 static const bool value
Chris@16 99 = boost::is_same<
Chris@16 100 typename boost::tuples::element<0, Tuple>::type,
Chris@16 101 El
Chris@16 102 >::value;
Chris@16 103 };
Chris@16 104
Chris@16 105 } // namespace detail
Chris@16 106
Chris@16 107 template <typename Tuple, typename El>
Chris@16 108 struct has
Chris@16 109 {
Chris@16 110 static const bool value
Chris@16 111 = detail::has<
Chris@16 112 Tuple,
Chris@16 113 El,
Chris@16 114 boost::tuples::length<Tuple>::value
Chris@16 115 >::value;
Chris@16 116 };
Chris@16 117
Chris@16 118 // add
Chris@16 119
Chris@16 120 template <typename Tuple, typename El>
Chris@16 121 struct add
Chris@16 122 {
Chris@16 123 BOOST_MPL_ASSERT_MSG(
Chris@16 124 (false),
Chris@16 125 NOT_IMPLEMENTED_FOR_THIS_TUPLE_TYPE,
Chris@16 126 (add));
Chris@16 127 };
Chris@16 128
Chris@16 129 template <typename T1, typename T>
Chris@16 130 struct add<boost::tuple<T1>, T>
Chris@16 131 {
Chris@16 132 typedef boost::tuple<T1, T> type;
Chris@16 133 };
Chris@16 134
Chris@16 135 template <typename T1, typename T2, typename T>
Chris@16 136 struct add<boost::tuple<T1, T2>, T>
Chris@16 137 {
Chris@16 138 typedef boost::tuple<T1, T2, T> type;
Chris@16 139 };
Chris@16 140
Chris@16 141 // add_if
Chris@16 142
Chris@16 143 template <typename Tuple, typename El, bool Cond>
Chris@16 144 struct add_if
Chris@16 145 {
Chris@16 146 typedef Tuple type;
Chris@16 147 };
Chris@16 148
Chris@16 149 template <typename Tuple, typename El>
Chris@16 150 struct add_if<Tuple, El, true>
Chris@16 151 {
Chris@16 152 typedef typename add<Tuple, El>::type type;
Chris@16 153 };
Chris@16 154
Chris@16 155 // add_unique
Chris@16 156
Chris@16 157 template <typename Tuple, typename El>
Chris@16 158 struct add_unique
Chris@16 159 {
Chris@16 160 typedef typename add_if<
Chris@16 161 Tuple,
Chris@16 162 El,
Chris@16 163 !has<Tuple, El>::value
Chris@16 164 >::type type;
Chris@16 165 };
Chris@16 166
Chris@101 167 template <typename Tuple,
Chris@101 168 typename T,
Chris@101 169 size_t I = 0,
Chris@101 170 size_t N = boost::tuples::length<Tuple>::value>
Chris@101 171 struct push_back
Chris@16 172 {
Chris@16 173 typedef
Chris@16 174 boost::tuples::cons<
Chris@16 175 typename boost::tuples::element<I, Tuple>::type,
Chris@101 176 typename push_back<Tuple, T, I+1, N>::type
Chris@16 177 > type;
Chris@16 178
Chris@16 179 static type apply(Tuple const& tup, T const& t)
Chris@16 180 {
Chris@16 181 return
Chris@16 182 type(
Chris@16 183 boost::get<I>(tup),
Chris@101 184 push_back<Tuple, T, I+1, N>::apply(tup, t)
Chris@16 185 );
Chris@16 186 }
Chris@16 187 };
Chris@16 188
Chris@16 189 template <typename Tuple, typename T, size_t N>
Chris@101 190 struct push_back<Tuple, T, N, N>
Chris@16 191 {
Chris@16 192 typedef boost::tuples::cons<T, boost::tuples::null_type> type;
Chris@16 193
Chris@16 194 static type apply(Tuple const&, T const& t)
Chris@16 195 {
Chris@16 196 return type(t, boost::tuples::null_type());
Chris@16 197 }
Chris@16 198 };
Chris@16 199
Chris@16 200 } // namespace tuples
Chris@16 201
Chris@16 202 }}}} // namespace boost::geometry::index::detail
Chris@16 203
Chris@16 204 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_TAGS_HPP