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