Chris@16: // Boost.Geometry Index Chris@16: // Chris@101: // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland. Chris@16: // Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_INDEX_INDEXABLE_HPP Chris@16: #define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP Chris@16: Chris@16: #include Chris@16: Chris@101: namespace boost { namespace geometry { namespace index { namespace detail { Chris@16: Chris@16: template Chris@16: struct is_indexable_impl { static const bool value = false; }; Chris@16: Chris@16: template Chris@16: struct is_indexable_impl { static const bool value = true; }; Chris@16: Chris@16: template Chris@16: struct is_indexable_impl { static const bool value = true; }; Chris@16: Chris@101: template Chris@101: struct is_indexable_impl { static const bool value = true; }; Chris@101: Chris@16: template Chris@16: struct is_indexable Chris@16: { Chris@16: static const bool value = Chris@101: is_indexable_impl Chris@101: < Chris@101: Indexable, Chris@101: typename geometry::tag::type Chris@101: >::value; Chris@16: }; Chris@16: Chris@16: /*! Chris@16: \brief The function object extracting Indexable from Value. Chris@16: Chris@16: It translates Value object to Indexable object. The default version handles Values which are Indexables. Chris@101: This template is also specialized for std::pair, boost::tuple Chris@101: and std::tuple. Chris@16: Chris@16: \tparam Value The Value type which may be translated directly to the Indexable. Chris@101: \tparam IsIndexable If true, the const reference to Value is returned. Chris@16: */ Chris@101: template ::value> Chris@16: struct indexable Chris@16: { Chris@16: BOOST_MPL_ASSERT_MSG( Chris@16: (detail::is_indexable::value), Chris@16: NOT_VALID_INDEXABLE_TYPE, Chris@16: (Value) Chris@16: ); Chris@101: Chris@16: /*! \brief The type of result returned by function object. */ Chris@16: typedef Value const& result_type; Chris@16: Chris@16: /*! Chris@16: \brief Return indexable extracted from the value. Chris@16: Chris@16: \param v The value. Chris@16: \return The indexable. Chris@16: */ Chris@101: inline result_type operator()(Value const& v) const Chris@16: { Chris@16: return v; Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: \brief The function object extracting Indexable from Value. Chris@16: Chris@16: This specialization translates from std::pair. Chris@16: Chris@16: \tparam Indexable The Indexable type. Chris@16: \tparam T2 The second type. Chris@16: */ Chris@16: template Chris@101: struct indexable, false> Chris@16: { Chris@16: BOOST_MPL_ASSERT_MSG( Chris@16: (detail::is_indexable::value), Chris@16: NOT_VALID_INDEXABLE_TYPE, Chris@16: (Indexable) Chris@16: ); Chris@16: Chris@16: /*! \brief The type of result returned by function object. */ Chris@16: typedef Indexable const& result_type; Chris@16: Chris@16: /*! Chris@16: \brief Return indexable extracted from the value. Chris@16: Chris@16: \param v The value. Chris@16: \return The indexable. Chris@16: */ Chris@101: inline result_type operator()(std::pair const& v) const Chris@16: { Chris@16: return v.first; Chris@16: } Chris@16: }; Chris@16: Chris@16: /*! Chris@16: \brief The function object extracting Indexable from Value. Chris@16: Chris@16: This specialization translates from boost::tuple. Chris@16: Chris@16: \tparam Indexable The Indexable type. Chris@16: */ Chris@16: template Chris@101: struct indexable, false> Chris@16: { Chris@16: typedef boost::tuple value_type; Chris@16: Chris@16: BOOST_MPL_ASSERT_MSG( Chris@16: (detail::is_indexable::value), Chris@16: NOT_VALID_INDEXABLE_TYPE, Chris@16: (Indexable) Chris@16: ); Chris@16: Chris@16: /*! \brief The type of result returned by function object. */ Chris@16: typedef Indexable const& result_type; Chris@16: Chris@16: /*! Chris@16: \brief Return indexable extracted from the value. Chris@16: Chris@16: \param v The value. Chris@16: \return The indexable. Chris@16: */ Chris@101: inline result_type operator()(value_type const& v) const Chris@16: { Chris@16: return boost::get<0>(v); Chris@16: } Chris@16: }; Chris@16: Chris@101: }}}} // namespace boost::geometry::index::detail Chris@16: Chris@16: #if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@16: #include Chris@16: Chris@101: namespace boost { namespace geometry { namespace index { namespace detail { Chris@16: Chris@16: /*! Chris@16: \brief The function object extracting Indexable from Value. Chris@16: Chris@16: This specialization translates from std::tuple. Chris@16: It's defined if the compiler supports tuples and variadic templates. Chris@16: Chris@16: \tparam Indexable The Indexable type. Chris@16: */ Chris@16: template Chris@101: struct indexable, false> Chris@16: { Chris@16: typedef std::tuple value_type; Chris@16: Chris@16: BOOST_MPL_ASSERT_MSG( Chris@16: (detail::is_indexable::value), Chris@16: NOT_VALID_INDEXABLE_TYPE, Chris@16: (Indexable) Chris@16: ); Chris@16: Chris@16: /*! \brief The type of result returned by function object. */ Chris@16: typedef Indexable const& result_type; Chris@16: Chris@16: /*! Chris@16: \brief Return indexable extracted from the value. Chris@16: Chris@16: \param v The value. Chris@16: \return The indexable. Chris@16: */ Chris@16: result_type operator()(value_type const& v) const Chris@16: { Chris@16: return std::get<0>(v); Chris@16: } Chris@16: }; Chris@16: Chris@101: }}}} // namespace boost::geometry::index::detail Chris@16: Chris@16: #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@101: namespace boost { namespace geometry { namespace index { Chris@101: Chris@101: /*! Chris@101: \brief The function object extracting Indexable from Value. Chris@101: Chris@101: It translates Value object to Indexable object. By default, it can handle Values which are Indexables, Chris@101: std::pair, boost::tuple and std::tuple if STD tuples Chris@101: and variadic templates are supported. Chris@101: Chris@101: \tparam Value The Value type which may be translated directly to the Indexable. Chris@101: */ Chris@101: template Chris@101: struct indexable Chris@101: : detail::indexable Chris@101: { Chris@101: /*! \brief The type of result returned by function object. It should be const Indexable reference. */ Chris@101: typedef typename detail::indexable::result_type result_type; Chris@101: Chris@101: /*! Chris@101: \brief Return indexable extracted from the value. Chris@101: Chris@101: \param v The value. Chris@101: \return The indexable. Chris@101: */ Chris@101: inline result_type operator()(Value const& v) const Chris@101: { Chris@101: return detail::indexable::operator()(v); Chris@101: } Chris@101: }; Chris@101: Chris@101: }}} // namespace boost::geometry::index Chris@101: Chris@16: #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP