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_NEXT_H 11 #define _LIBCPP___ITERATOR_NEXT_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 __next_fn final : private __function_like { 32 constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {} 33 34 template <input_or_output_iterator _Ip> 35 constexpr _Ip operator()(_Ip __x) const { 36 ++__x; 37 return __x; 38 } 39 40 template <input_or_output_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 <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp> 47 constexpr _Ip operator()(_Ip __x, _Sp __bound) const { 48 ranges::advance(__x, __bound); 49 return __x; 50 } 51 52 template <input_or_output_iterator _Ip, sentinel_for<_Ip> _Sp> 53 constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound) const { 54 ranges::advance(__x, __n, __bound); 55 return __x; 56 } 57 }; 58 59 inline constexpr auto next = __next_fn(__function_like::__tag()); 60 } // namespace ranges 61 62 #endif // !defined(_LIBCPP_HAS_NO_RANGES) 63 64 _LIBCPP_END_NAMESPACE_STD 65 66 _LIBCPP_POP_MACROS 67 68 #endif // _LIBCPP___ITERATOR_PRIMITIVES_H 69