1 // Boost.Geometry Index
3 // Copyright (c) 2011-2015 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>
14 #include <boost/geometry/index/detail/is_indexable.hpp>
16 namespace boost { namespace geometry { namespace index { namespace detail {
19 \brief The function object extracting Indexable from Value.
21 It translates Value object to Indexable object. The default version handles Values which are Indexables.
22 This template is also specialized for std::pair<Indexable, T2>, boost::tuple<Indexable, ...>
23 and std::tuple<Indexable, ...>.
25 \tparam Value The Value type which may be translated directly to the Indexable.
26 \tparam IsIndexable If true, the const reference to Value is returned.
28 template <typename Value, bool IsIndexable = is_indexable<Value>::value>
32 (detail::is_indexable<Value>::value),
33 NOT_VALID_INDEXABLE_TYPE,
37 /*! \brief The type of result returned by function object. */
38 typedef Value const& result_type;
41 \brief Return indexable extracted from the value.
44 \return The indexable.
46 inline result_type operator()(Value const& v) const
53 \brief The function object extracting Indexable from Value.
55 This specialization translates from std::pair<Indexable, T2>.
57 \tparam Indexable The Indexable type.
58 \tparam T2 The second type.
60 template <typename Indexable, typename T2>
61 struct indexable<std::pair<Indexable, T2>, false>
64 (detail::is_indexable<Indexable>::value),
65 NOT_VALID_INDEXABLE_TYPE,
69 /*! \brief The type of result returned by function object. */
70 typedef Indexable const& result_type;
73 \brief Return indexable extracted from the value.
76 \return The indexable.
78 inline result_type operator()(std::pair<Indexable, T2> const& v) const
85 \brief The function object extracting Indexable from Value.
87 This specialization translates from boost::tuple<Indexable, ...>.
89 \tparam Indexable The Indexable type.
91 template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
92 typename T5, typename T6, typename T7, typename T8, typename T9>
93 struct indexable<boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
95 typedef boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9> value_type;
98 (detail::is_indexable<Indexable>::value),
99 NOT_VALID_INDEXABLE_TYPE,
103 /*! \brief The type of result returned by function object. */
104 typedef Indexable const& result_type;
107 \brief Return indexable extracted from the value.
110 \return The indexable.
112 inline result_type operator()(value_type const& v) const
114 return boost::get<0>(v);
118 }}}} // namespace boost::geometry::index::detail
120 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
124 namespace boost { namespace geometry { namespace index { namespace detail {
127 \brief The function object extracting Indexable from Value.
129 This specialization translates from std::tuple<Indexable, Args...>.
130 It's defined if the compiler supports tuples and variadic templates.
132 \tparam Indexable The Indexable type.
134 template <typename Indexable, typename ...Args>
135 struct indexable<std::tuple<Indexable, Args...>, false>
137 typedef std::tuple<Indexable, Args...> value_type;
139 BOOST_MPL_ASSERT_MSG(
140 (detail::is_indexable<Indexable>::value),
141 NOT_VALID_INDEXABLE_TYPE,
145 /*! \brief The type of result returned by function object. */
146 typedef Indexable const& result_type;
149 \brief Return indexable extracted from the value.
152 \return The indexable.
154 result_type operator()(value_type const& v) const
156 return std::get<0>(v);
160 }}}} // namespace boost::geometry::index::detail
162 #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
164 namespace boost { namespace geometry { namespace index {
167 \brief The function object extracting Indexable from Value.
169 It translates Value object to Indexable object. By default, it can handle Values which are Indexables,
170 std::pair<Indexable, T2>, boost::tuple<Indexable, ...> and std::tuple<Indexable, ...> if STD tuples
171 and variadic templates are supported.
173 \tparam Value The Value type which may be translated directly to the Indexable.
175 template <typename Value>
177 : detail::indexable<Value>
179 /*! \brief The type of result returned by function object. It should be const Indexable reference. */
180 typedef typename detail::indexable<Value>::result_type result_type;
183 \brief Return indexable extracted from the value.
186 \return The indexable.
188 inline result_type operator()(Value const& v) const
190 return detail::indexable<Value>::operator()(v);
194 }}} // namespace boost::geometry::index
196 #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP