/*============================================================================= 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_ITERATOR_ADVANCE_HPP #define SPROUT_ITERATOR_ADVANCE_HPP #include #include #include #include namespace sprout { namespace detail { template inline SPROUT_CXX14_CONSTEXPR void advance_impl(InputIterator& it, Distance n, std::input_iterator_tag*) { SPROUT_ASSERT(sprout::math::greater_equal(n, 0)); for (; 0 < n; --n) { ++it; } } template inline SPROUT_CXX14_CONSTEXPR void advance_impl(BidirectionalIterator& it, Distance n, std::bidirectional_iterator_tag*) { if (n > 0) { for (; 0 < n; --n) { ++it; } } else { for (; n < 0; ++n) { --it; } } } template inline SPROUT_CXX14_CONSTEXPR void advance_impl(RandomAccessIterator& it, Distance n, std::random_access_iterator_tag*) { it += n; } } // namespace detail // // advance // template::difference_type> inline SPROUT_CXX14_CONSTEXPR void advance(Iterator& it, Distance n = 1) { typedef typename std::iterator_traits::iterator_category* category; sprout::detail::advance_impl(it, n, category()); } } // namespace sprout #endif // #ifndef SPROUT_ITERATOR_ADVANCE_HPP