codekingpro/portable-devtools
114k
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-exception7// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.8//9//===----------------------------------------------------------------------===//10 11#ifndef _LIBCUDACXX___ITERATOR_NEXT_H12#define _LIBCUDACXX___ITERATOR_NEXT_H13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#include "../__assert"19#include "../__iterator/advance.h"20#include "../__iterator/concepts.h"21#include "../__iterator/incrementable_traits.h"22#include "../__iterator/iterator_traits.h"23#include "../__type_traits/enable_if.h"24 25#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)26# pragma GCC system_header27#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)28# pragma clang system_header29#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)30# pragma system_header31#endif // no system header32 33_LIBCUDACXX_BEGIN_NAMESPACE_STD34 35template <class _InputIter>36inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1437 __enable_if_t<__is_cpp17_input_iterator<_InputIter>::value, _InputIter>38 next(_InputIter __x, typename iterator_traits<_InputIter>::difference_type __n = 1) {39 _LIBCUDACXX_ASSERT(__n >= 0 || __is_cpp17_bidirectional_iterator<_InputIter>::value,40 "Attempt to next(it, n) with negative n on a non-bidirectional iterator");41 42 _CUDA_VSTD::advance(__x, __n);43 return __x;44}45 46_LIBCUDACXX_END_NAMESPACE_STD47 48#if _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_COMPILER_MSVC_2017)49 50// [range.iter.op.next]51 52_LIBCUDACXX_BEGIN_NAMESPACE_RANGES53_LIBCUDACXX_BEGIN_NAMESPACE_CPO(__next)54struct __fn {55 _LIBCUDACXX_TEMPLATE(class _Ip)56 _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip>)57 _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY58 constexpr _Ip operator()(_Ip __x) const {59 ++__x;60 return __x;61 }62 63 _LIBCUDACXX_TEMPLATE(class _Ip)64 _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip>)65 _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY66 constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n) const {67 _CUDA_VRANGES::advance(__x, __n);68 return __x;69 }70 71 _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp)72 _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> && sentinel_for<_Sp, _Ip>)73 _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Ip operator()(_Ip __x, _Sp __bound_sentinel) const {74 _CUDA_VRANGES::advance(__x, __bound_sentinel);75 return __x;76 }77 78 _LIBCUDACXX_TEMPLATE(class _Ip, class _Sp)79 _LIBCUDACXX_REQUIRES(input_or_output_iterator<_Ip> && sentinel_for<_Sp, _Ip>)80 _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY constexpr _Ip operator()(_Ip __x, iter_difference_t<_Ip> __n, _Sp __bound_sentinel) const {81 _CUDA_VRANGES::advance(__x, __n, __bound_sentinel);82 return __x;83 }84};85_LIBCUDACXX_END_NAMESPACE_CPO86 87inline namespace __cpo {88 _LIBCUDACXX_CPO_ACCESSIBILITY auto next = __next::__fn{};89} // namespace __cpo90_LIBCUDACXX_END_NAMESPACE_RANGES91 92#endif // _LIBCUDACXX_STD_VER > 14 && !defined(_LIBCUDACXX_COMPILER_MSVC_2017)93 94#endif // _LIBCUDACXX___ITERATOR_NEXT_H95 