/*============================================================================= Copyright (c) 2011-2016 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under 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 SPROUT_CONTAINER_DETAIL_RANGE_INDEX_OF_HPP #define SPROUT_CONTAINER_DETAIL_RANGE_INDEX_OF_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout_adl { sprout::not_found_via_adl range_index_of(...); } // namespace sprout_adl namespace sprout { namespace detail { template struct has_mem_index_of_test { public: template< typename U = T, typename = typename sprout::identity().index_of(std::declval::iterator>()))>::type > static sprout::true_type test(int); static sprout::false_type test(...); }; #if defined(_MSC_VER) && (_MSC_VER > 1900) template::test(0))>::type> struct has_mem_index_of : public Base_ {}; #else template struct has_mem_index_of : public sprout::identity::test(0))>::type {}; #endif template struct is_substitutable_const_index_of : public sprout::bool_constant< sprout::is_const_iterator_cast_convertible< typename sprout::container_traits::iterator, typename sprout::container_traits::iterator >::value && ( sprout::detail::has_mem_index_of::value || sprout::detail::has_mem_begin::value || sprout::detail::has_adl_begin_without_sprout::value ) > {}; template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::is_substitutable_const_index_of::value, typename sprout::container_traits::size_type >::type range_index_of_impl(Container& cont, typename sprout::container_traits::iterator p) { typedef typename sprout::container_traits::iterator type; return sprout::index_of(sprout::as_const(cont), sprout::const_iterator_cast(p)); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_index_of::value && sprout::detail::has_mem_index_of::value , typename sprout::container_traits::size_type >::type range_index_of_impl(Container& cont, typename sprout::container_traits::iterator p) { return cont.index_of(p); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_index_of::value && !sprout::detail::has_mem_index_of::value , typename sprout::container_traits::size_type >::type range_index_of_impl(Container& cont, typename sprout::container_traits::iterator p) { return sprout::distance(sprout::begin(cont), p); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::has_mem_index_of::value, typename sprout::container_traits::size_type >::type range_index_of_impl(Container const& cont, typename sprout::container_traits::iterator p) { return cont.index_of(p); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_index_of::value, typename sprout::container_traits::size_type >::type range_index_of_impl(Container const& cont, typename sprout::container_traits::iterator p) { return sprout::distance(sprout::begin(cont), p); } } // namespace detail } // namespace sprout namespace sprout_container_range_detail { template inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type range_index_of(Container& cont, typename sprout::container_traits::iterator p) { return sprout::detail::range_index_of_impl(cont, p); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::size_type range_index_of(Container const& cont, typename sprout::container_traits::iterator p) { return sprout::detail::range_index_of_impl(cont, p); } } // namespace sprout_container_range_detail #endif // #ifndef SPROUT_CONTAINER_DETAIL_RANGE_INDEX_OF_HPP