/*============================================================================= 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_END_HPP #define SPROUT_CONTAINER_DETAIL_RANGE_END_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout_adl { sprout::not_found_via_adl end(...); sprout::not_found_via_adl range_end(...); } // namespace sprout_adl namespace sprout_container_range_detail { using sprout_adl::end; template struct has_adl_end_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_end(Container& cont) { return end(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_adl_end(Container const& cont) { return end(cont); } } // namespace sprout_container_range_detail namespace sprout { namespace detail { #if defined(_MSC_VER) && (_MSC_VER > 1900) template::test(0))>::type> struct has_adl_end : public Base_ {}; #else template struct has_adl_end : public sprout::identity::test(0))>::type {}; #endif template::value> struct has_adl_end_without_sprout : public sprout::false_type {}; template struct has_adl_end_without_sprout : public sprout::detail::has_adl_end {}; template struct has_mem_end_test { public: template< typename U = T, typename = typename sprout::identity().end())>::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_end : public Base_ {}; #else template struct has_mem_end : public sprout::identity::test(0))>::type {}; #endif template struct is_substitutable_const_end : 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_end::value || sprout::detail::has_adl_end_without_sprout::value ) > {}; template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::is_substitutable_const_end::value, typename sprout::container_traits::iterator >::type range_end_impl(Container& cont) { typedef typename sprout::container_traits::iterator type; return sprout::const_iterator_cast(sprout::end(sprout::as_const(cont))); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_end::value && sprout::detail::has_mem_end::value , typename sprout::container_traits::iterator >::type range_end_impl(Container& cont) { return cont.end(); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_end::value && !sprout::detail::has_mem_end::value && sprout::detail::has_adl_end_without_sprout::value , typename sprout::container_traits::iterator >::type range_end_impl(Container& cont) { return sprout_container_range_detail::range_adl_end(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::is_substitutable_const_end::value && !sprout::detail::has_mem_end::value && !sprout::detail::has_adl_end_without_sprout::value , typename sprout::container_traits::iterator >::type range_end_impl(Container& cont) { return std::end(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::detail::has_mem_end::value, typename sprout::container_traits::iterator >::type range_end_impl(Container const& cont) { return cont.end(); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_end::value && sprout::detail::has_adl_end_without_sprout::value , typename sprout::container_traits::iterator >::type range_end_impl(Container const& cont) { return sprout_container_range_detail::range_adl_end(cont); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::detail::has_mem_end::value && !sprout::detail::has_adl_end_without_sprout::value , typename sprout::container_traits::iterator >::type range_end_impl(Container const& cont) { return std::end(cont); } } // namespace detail } // namespace sprout namespace sprout_container_range_detail { template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container& cont) { return sprout::detail::range_end_impl(cont); } template inline SPROUT_CONSTEXPR typename sprout::container_traits::iterator range_end(Container const& cont) { return sprout::detail::range_end_impl(cont); } } // namespace sprout_container_range_detail #endif // #ifndef SPROUT_CONTAINER_DETAIL_RANGE_END_HPP