Warning: This file is not a C or C++ file. It does not have highlighting.

1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___CXX03___ALGORITHM_REVERSE_H
10#define _LIBCPP___CXX03___ALGORITHM_REVERSE_H
11
12#include <__cxx03/__algorithm/iter_swap.h>
13#include <__cxx03/__algorithm/iterator_operations.h>
14#include <__cxx03/__config>
15#include <__cxx03/__iterator/iterator_traits.h>
16#include <__cxx03/__utility/move.h>
17
18#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
19# pragma GCC system_header
20#endif
21
22_LIBCPP_PUSH_MACROS
23#include <__cxx03/__undef_macros>
24
25_LIBCPP_BEGIN_NAMESPACE_STD
26
27template <class _AlgPolicy, class _BidirectionalIterator>
28inline _LIBCPP_HIDE_FROM_ABI void
29__reverse_impl(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) {
30 while (__first != __last) {
31 if (__first == --__last)
32 break;
33 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
34 ++__first;
35 }
36}
37
38template <class _AlgPolicy, class _RandomAccessIterator>
39inline _LIBCPP_HIDE_FROM_ABI void
40__reverse_impl(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) {
41 if (__first != __last)
42 for (; __first < --__last; ++__first)
43 _IterOps<_AlgPolicy>::iter_swap(__first, __last);
44}
45
46template <class _AlgPolicy, class _BidirectionalIterator, class _Sentinel>
47_LIBCPP_HIDE_FROM_ABI void __reverse(_BidirectionalIterator __first, _Sentinel __last) {
48 using _IterCategory = typename _IterOps<_AlgPolicy>::template __iterator_category<_BidirectionalIterator>;
49 std::__reverse_impl<_AlgPolicy>(std::move(__first), std::move(__last), _IterCategory());
50}
51
52template <class _BidirectionalIterator>
53inline _LIBCPP_HIDE_FROM_ABI void reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) {
54 std::__reverse<_ClassicAlgPolicy>(std::move(__first), std::move(__last));
55}
56
57_LIBCPP_END_NAMESPACE_STD
58
59_LIBCPP_POP_MACROS
60
61#endif // _LIBCPP___CXX03___ALGORITHM_REVERSE_H
62

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of libcxx/include/__cxx03/__algorithm/reverse.h