/*============================================================================= Copyright (c) 2011-2017 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_AT_HPP #define SPROUT_CONTAINER_DETAIL_RANGE_AT_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout_adl { sprout::not_found_via_adl range_at(...); } // namespace sprout_adl namespace sprout { namespace detail { template struct has_mem_at_test { public: template< typename U = T, typename = typename sprout::identity().at(std::declval::size_type>()))>::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_at : public Base_ {}; #else template struct has_mem_at : public sprout::identity::test(0))>::type {}; #endif template struct is_substitutable_const_at : public sprout::bool_constant< sprout::is_const_reference_cast_convertible< typename sprout::container_traits::reference, typename sprout::container_traits::reference >::value && ( sprout::detail::has_mem_at::value || sprout::detail::has_mem_subscript::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_at::value, typename sprout::container_traits::reference >::type range_at_impl(Container& cont, typename sprout::container_traits::size_type i) { typedef typename sprout::container_traits::reference type; return sprout::const_reference_cast(sprout::at(sprout::as_const(cont), i)); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_at::value && sprout::detail::has_mem_at::value , typename sprout::container_traits::reference >::type range_at_impl(Container& cont, typename sprout::container_traits::size_type i) { return cont.at(i); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_at::value && !sprout::detail::has_mem_at::value && sprout::detail::has_mem_subscript::value , typename sprout::container_traits::reference >::type range_at_impl(Container& cont, typename sprout::container_traits::size_type i) { return cont[sprout::range_index_check(cont, i)]; } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_at::value && !sprout::detail::has_mem_at::value && !sprout::detail::has_mem_subscript::value , typename sprout::container_traits::reference >::type range_at_impl(Container& cont, typename sprout::container_traits::size_type i) { return *sprout::next(sprout::begin(cont), sprout::range_index_check(cont, i)); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::has_mem_at::value, typename sprout::container_traits::reference >::type range_at_impl(Container const& cont, typename sprout::container_traits::size_type i) { return cont.at(i); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_at::value && sprout::detail::has_mem_subscript::value , typename sprout::container_traits::reference >::type range_at_impl(Container const& cont, typename sprout::container_traits::size_type i) { return cont[sprout::range_index_check(cont, i)]; } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_at::value && !sprout::detail::has_mem_subscript::value , typename sprout::container_traits::reference >::type range_at_impl(Container const& cont, typename sprout::container_traits::size_type i) { return *sprout::next(sprout::begin(cont), sprout::range_index_check(cont, i)); } } // namespace detail } // namespace sprout namespace sprout_container_range_detail { template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference range_at(Container& cont, typename sprout::container_traits::size_type i) { return sprout::detail::range_at_impl(cont, i); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::reference range_at(Container const& cont, typename sprout::container_traits::size_type i) { return sprout::detail::range_at_impl(cont, i); } } // namespace sprout_container_range_detail #endif // #ifndef SPROUT_CONTAINER_DETAIL_RANGE_AT_HPP