/*============================================================================= 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_BEGIN_HPP #define SPROUT_CONTAINER_DETAIL_RANGE_BEGIN_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout_adl { sprout::not_found_via_adl begin(...); sprout::not_found_via_adl range_begin(...); } // namespace sprout_adl namespace sprout_container_range_detail { using sprout_adl::begin; template struct has_adl_begin_test { public: template< typename U = T, typename R = typename sprout::identity()))>::type > static sprout::is_found_via_adl test(int); static sprout::false_type test(...); }; template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_adl_begin(Container& cont) { return begin(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_adl_begin(Container const& cont) { return begin(cont); } } // namespace sprout_container_range_detail namespace sprout { namespace detail { #if defined(_MSC_VER) && (_MSC_VER > 1900) template::test(0))>::type> struct has_adl_begin : public Base_ {}; #else template struct has_adl_begin : public sprout::identity::test(0))>::type {}; #endif template::value> struct has_adl_begin_without_sprout : public sprout::false_type {}; template struct has_adl_begin_without_sprout : public sprout::detail::has_adl_begin {}; template struct has_mem_begin_test { public: template< typename U = T, typename = typename sprout::identity().begin())>::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_begin : public Base_ {}; #else template struct has_mem_begin : public sprout::identity::test(0))>::type {}; #endif template struct is_substitutable_const_begin : 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_begin::value || sprout::detail::has_adl_begin_without_sprout::value ) > {}; template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::is_substitutable_const_begin::value, typename sprout::container_traits::iterator >::type range_begin_impl(Container& cont) { typedef typename sprout::container_traits::iterator type; return sprout::const_iterator_cast(sprout::begin(sprout::as_const(cont))); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_begin::value && sprout::detail::has_mem_begin::value , typename sprout::container_traits::iterator >::type range_begin_impl(Container& cont) { return cont.begin(); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_begin::value && !sprout::detail::has_mem_begin::value && sprout::detail::has_adl_begin_without_sprout::value , typename sprout::container_traits::iterator >::type range_begin_impl(Container& cont) { return sprout_container_range_detail::range_adl_begin(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_begin::value && !sprout::detail::has_mem_begin::value && !sprout::detail::has_adl_begin_without_sprout::value , typename sprout::container_traits::iterator >::type range_begin_impl(Container& cont) { return std::begin(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::has_mem_begin::value, typename sprout::container_traits::iterator >::type range_begin_impl(Container const& cont) { return cont.begin(); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_begin::value && sprout::detail::has_adl_begin_without_sprout::value , typename sprout::container_traits::iterator >::type range_begin_impl(Container const& cont) { return sprout_container_range_detail::range_adl_begin(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_begin::value && !sprout::detail::has_adl_begin_without_sprout::value , typename sprout::container_traits::iterator >::type range_begin_impl(Container const& cont) { return std::begin(cont); } } // namespace detail } // namespace sprout namespace sprout_container_range_detail { template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container& cont) { return sprout::detail::range_begin_impl(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_begin(Container const& cont) { return sprout::detail::range_begin_impl(cont); } } // namespace sprout_container_range_detail #endif // #ifndef SPROUT_CONTAINER_DETAIL_RANGE_BEGIN_HPP