1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___ITERATOR_PREV_H
11 #define _LIBCPP___ITERATOR_PREV_H
12 
13 #include <__config>
14 #include <__function_like.h>
15 #include <__iterator/advance.h>
16 #include <__iterator/concepts.h>
17 #include <__iterator/incrementable_traits.h>
18 
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 #pragma GCC system_header
21 #endif
22 
23 _LIBCPP_PUSH_MACROS
24 #include <__undef_macros>
25 
26 _LIBCPP_BEGIN_NAMESPACE_STD
27 
28 #if !defined(_LIBCPP_HAS_NO_RANGES)
29 
30 namespace ranges {
31 struct __prev_fn final : private __function_like {
32   constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {}
33 
34   template <bidirectional_iterator _Ip>
35   constexpr _Ip operator()(_Ip __x) const {
36     --__x;
37     return __x;
38   }
39 
40   template <bidirectional_iterator _Ip>
41   constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {
42     ranges::advance(__x, -__n);
43     return __x;
44   }
45 
46   template <bidirectional_iterator _Ip>
47   constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Ip __bound) const {
48     ranges::advance(__x, -__n, __bound);
49     return __x;
50   }
51 };
52 
53 inline constexpr auto prev = __prev_fn(__function_like::__tag());
54 } // namespace ranges
55 
56 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
57 
58 _LIBCPP_END_NAMESPACE_STD
59 
60 _LIBCPP_POP_MACROS
61 
62 #endif // _LIBCPP___ITERATOR_PREV_H
63