/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to 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) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ALGORITHM_REVERSE_HPP #define RANGES_V3_ALGORITHM_REVERSE_HPP #include #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-algorithms /// @{ /// \cond namespace detail { template void reverse_impl(I first, I last, detail::bidirectional_iterator_tag_) { while(first != last) { if(first == --last) break; ranges::iter_swap(first, last); ++first; } } template void reverse_impl(I first, I last, detail::random_access_iterator_tag_) { if(first != last) for(; first < --last; ++first) ranges::iter_swap(first, last); } } // namespace detail /// \endcond RANGES_BEGIN_NIEBLOID(reverse) /// \brief function template \c reverse template auto RANGES_FUN_NIEBLOID(reverse)(I first, S end_) // ->CPP_ret(I)( // requires bidirectional_iterator && sentinel_for && permutable) { I last = ranges::next(first, end_); detail::reverse_impl(first, last, iterator_tag_of{}); return last; } /// \overload template> auto RANGES_FUN_NIEBLOID(reverse)(Rng && rng) // ->CPP_ret(safe_iterator_t)( // requires bidirectional_range && permutable) { return (*this)(begin(rng), end(rng)); } RANGES_END_NIEBLOID(reverse) namespace cpp20 { using ranges::reverse; } /// @} } // namespace ranges #endif // include guard