Chris@16: // Boost.Geometry Index Chris@16: // Chris@16: // Copyright (c) 2011-2013 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@16: namespace boost { namespace geometry { namespace index { Chris@16: Chris@16: 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@16: template Chris@16: struct is_indexable Chris@16: { Chris@16: static const bool value = Chris@16: is_indexable_impl::type>::value; Chris@16: }; Chris@16: Chris@16: } // namespace detail 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@16: This template is also specialized for std::pair and boost::tuple. Chris@16: Chris@16: \tparam Value The Value type which may be translated directly to the Indexable. Chris@16: */ Chris@16: template 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@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@16: 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@16: struct indexable< std::pair > 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()(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@16: struct indexable< boost::tuple > 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@16: result_type operator()(value_type const& v) const Chris@16: { Chris@16: return boost::get<0>(v); Chris@16: } Chris@16: }; Chris@16: Chris@16: }}} // namespace boost::geometry::index 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@16: namespace boost { namespace geometry { namespace index { 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@16: struct indexable< std::tuple > 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@16: }}} // namespace boost::geometry::index Chris@16: Chris@16: #endif // !defined(BOOST_NO_CXX11_HDR_TUPLE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) Chris@16: Chris@16: #endif // BOOST_GEOMETRY_INDEX_INDEXABLE_HPP