Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:55

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_ALGORITHM_REVERSE_HPP
0014 #define RANGES_V3_ALGORITHM_REVERSE_HPP
0015 
0016 #include <range/v3/range_fwd.hpp>
0017 
0018 #include <range/v3/iterator/concepts.hpp>
0019 #include <range/v3/iterator/operations.hpp>
0020 #include <range/v3/iterator/traits.hpp>
0021 #include <range/v3/range/access.hpp>
0022 #include <range/v3/range/concepts.hpp>
0023 #include <range/v3/range/dangling.hpp>
0024 #include <range/v3/range/traits.hpp>
0025 #include <range/v3/utility/static_const.hpp>
0026 #include <range/v3/utility/swap.hpp>
0027 
0028 #include <range/v3/detail/prologue.hpp>
0029 
0030 namespace ranges
0031 {
0032     /// \addtogroup group-algorithms
0033     /// @{
0034 
0035     /// \cond
0036     namespace detail
0037     {
0038         template<typename I>
0039         constexpr void reverse_impl(I first, I last, std::bidirectional_iterator_tag)
0040         {
0041             while(first != last)
0042             {
0043                 if(first == --last)
0044                     break;
0045                 ranges::iter_swap(first, last);
0046                 ++first;
0047             }
0048         }
0049 
0050         template<typename I>
0051         constexpr void reverse_impl(I first, I last, std::random_access_iterator_tag)
0052         {
0053             if(first != last)
0054                 for(; first < --last; ++first)
0055                     ranges::iter_swap(first, last);
0056         }
0057     } // namespace detail
0058     /// \endcond
0059 
0060     RANGES_FUNC_BEGIN(reverse)
0061 
0062         /// \brief function template \c reverse
0063         template(typename I, typename S)(
0064             requires bidirectional_iterator<I> AND sentinel_for<S, I> AND permutable<I>)
0065         constexpr I RANGES_FUNC(reverse)(I first, S end_)
0066         {
0067             I last = ranges::next(first, end_);
0068             detail::reverse_impl(first, last, iterator_tag_of<I>{});
0069             return last;
0070         }
0071 
0072         /// \overload
0073         template(typename Rng, typename I = iterator_t<Rng>)(
0074             requires bidirectional_range<Rng> AND permutable<I>)
0075         constexpr borrowed_iterator_t<Rng> RANGES_FUNC(reverse)(Rng && rng) //
0076         {
0077             return (*this)(begin(rng), end(rng));
0078         }
0079 
0080     RANGES_FUNC_END(reverse)
0081 
0082     namespace cpp20
0083     {
0084         using ranges::reverse;
0085     }
0086     /// @}
0087 } // namespace ranges
0088 
0089 #include <range/v3/detail/epilogue.hpp>
0090 
0091 #endif