1 // Boost.Geometry Index
3 // Copyright (c) 2011-2017 Adam Wulkiewicz, Lodz, Poland.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
10 #define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
12 #include <boost/mpl/assert.hpp>
13 #include <boost/tuple/tuple.hpp>
15 #include <boost/geometry/index/detail/is_indexable.hpp>
17 namespace boost { namespace geometry { namespace index { namespace detail {
20 \brief The function object extracting Indexable from Value.
22 It translates Value object to Indexable object. The default version handles Values which are Indexables.
23 This template is also specialized for std::pair<Indexable, T2>, boost::tuple<Indexable, ...>
24 and std::tuple<Indexable, ...>.
26 \tparam Value The Value type which may be translated directly to the Indexable.
27 \tparam IsIndexable If true, the const reference to Value is returned.
29 template <typename Value, bool IsIndexable = is_indexable<Value>::value>
33 (detail::is_indexable<Value>::value),
34 NOT_VALID_INDEXABLE_TYPE,
38 /*! \brief The type of result returned by function object. */
39 typedef Value const& result_type;
42 \brief Return indexable extracted from the value.
45 \return The indexable.
47 inline result_type operator()(Value const& v) const
54 \brief The function object extracting Indexable from Value.
56 This specialization translates from std::pair<Indexable, T2>.
58 \tparam Indexable The Indexable type.
59 \tparam T2 The second type.
61 template <typename Indexable, typename T2>
62 struct indexable<std::pair<Indexable, T2>, false>
65 (detail::is_indexable<Indexable>::value),
66 NOT_VALID_INDEXABLE_TYPE,
70 /*! \brief The type of result returned by function object. */
71 typedef Indexable const& result_type;
74 \brief Return indexable extracted from the value.
77 \return The indexable.
79 inline result_type operator()(std::pair<Indexable, T2> const& v) const
86 \brief The function object extracting Indexable from Value.
88 This specialization translates from boost::tuple<Indexable, ...>.
90 \tparam Indexable The Indexable type.
92 template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
93 typename T5, typename T6, typename T7, typename T8, typename T9>
94 struct indexable<boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
96 typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
99 (detail::is_indexable<Indexable>::value),
100 NOT_VALID_INDEXABLE_TYPE,
104 /*! \brief The type of result returned by function object. */
105 typedef Indexable const& result_type;
108 \brief Return indexable extracted from the value.
111 \return The indexable.
113 inline result_type operator()(value_type const& v) const
115 return boost::get<0>(v);
119 }}}} // namespace boost::geometry::index::detail
121 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
125 namespace boost { namespace geometry { namespace index { namespace detail {
128 \brief The function object extracting Indexable from Value.
130 This specialization translates from std::tuple<Indexable, Args...>.
131 It's defined if the compiler supports tuples and variadic templates.
133 \tparam Indexable The Indexable type.
135 template <typename Indexable, typename ...Args>
136 struct indexable<std::tuple<Indexable, Args...>, false>
138 typedef std::tuple<Indexable, Args...> value_type;
140 BOOST_MPL_ASSERT_MSG(
141 (detail::is_indexable<Indexable>::value),
142 NOT_VALID_INDEXABLE_TYPE,
146 /*! \brief The type of result returned by function object. */
147 typedef Indexable const& result_type;
150 \brief Return indexable extracted from the value.
153 \return The indexable.
155 result_type operator()(value_type const& v) const
157 return std::get<0>(v);
161 }}}} // namespace boost::geometry::index::detail
163 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
165 namespace boost { namespace geometry { namespace index {
168 \brief The function object extracting Indexable from Value.
170 It translates Value object to Indexable object. By default, it can handle Values which are Indexables,
171 std::pair<Indexable, T2>, boost::tuple<Indexable, ...> and std::tuple<Indexable, ...> if STD tuples
172 and variadic templates are supported.
174 \tparam Value The Value type which may be translated directly to the Indexable.
176 template <typename Value>
178 : detail::indexable<Value>
180 /*! \brief The type of result returned by function object. It should be const Indexable reference. */
181 typedef typename detail::indexable<Value>::result_type result_type;
184 \brief Return indexable extracted from the value.
187 \return The indexable.
189 inline result_type operator()(Value const& v) const
191 return detail::indexable<Value>::operator()(v);
195 }}} // namespace boost::geometry::index
197 #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP