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_REVERSE_ITERATOR_H12#define _LIBCUDACXX___ITERATOR_REVERSE_ITERATOR_H13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#include "../__iterator/iterator.h"19#include "../__iterator/iterator_traits.h"20#include "../__memory/addressof.h"21#include "../__type_traits/void_t.h"22 23#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)24# pragma GCC system_header25#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)26# pragma clang system_header27#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)28# pragma system_header29#endif // no system header30 31_LIBCUDACXX_BEGIN_NAMESPACE_STD32 33template <class _Tp, class = void>34struct __is_cpp17_stashing_iterator : false_type {};35 36template <class _Tp>37struct __is_cpp17_stashing_iterator<_Tp, __void_t<typename _Tp::__stashing_iterator_tag>>38 : true_type {};39 40_LIBCUDACXX_SUPPRESS_DEPRECATED_PUSH41template <class _Iter>42class _LIBCUDACXX_TEMPLATE_VIS reverse_iterator43#if _LIBCUDACXX_STD_VER <= 14 || !defined(_LIBCUDACXX_ABI_NO_ITERATOR_BASES)44 : public iterator<typename iterator_traits<_Iter>::iterator_category,45 typename iterator_traits<_Iter>::value_type,46 typename iterator_traits<_Iter>::difference_type,47 typename iterator_traits<_Iter>::pointer,48 typename iterator_traits<_Iter>::reference>49#endif50{51_LIBCUDACXX_SUPPRESS_DEPRECATED_POP52private:53 /*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break54 55 static_assert(!__is_cpp17_stashing_iterator<_Iter>::value,56 "The specified iterator type cannot be used with reverse_iterator; "57 "Using stashing iterators with reverse_iterator causes undefined behavior");58 59protected:60 _Iter current;61public:62 typedef _Iter iterator_type;63 typedef typename iterator_traits<_Iter>::difference_type difference_type;64 typedef typename iterator_traits<_Iter>::reference reference;65 typedef typename iterator_traits<_Iter>::pointer pointer;66 67 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1468 reverse_iterator() : __t(), current() {}69 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1470 explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}71 template <class _Up>72 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1473 reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}74 template <class _Up>75 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1476 reverse_iterator& operator=(const reverse_iterator<_Up>& __u)77 { __t = current = __u.base(); return *this; }78 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1479 _Iter base() const {return current;}80 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1481 reference operator*() const {_Iter __tmp = current; return *--__tmp;}82 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1483 pointer operator->() const {return _CUDA_VSTD::addressof(operator*());}84 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1485 reverse_iterator& operator++() {--current; return *this;}86 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1487 reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}88 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1489 reverse_iterator& operator--() {++current; return *this;}90 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1491 reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}92 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1493 reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}94 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1495 reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}96 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1497 reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}98 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX1499 reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}100 _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14101 reference operator[](difference_type __n) const {return *(*this + __n);}102};103 104template <class _Iter1, class _Iter2>105inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14106bool107operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)108{109 return __x.base() == __y.base();110}111 112template <class _Iter1, class _Iter2>113inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14114bool115operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)116{117 return __x.base() > __y.base();118}119 120template <class _Iter1, class _Iter2>121inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14122bool123operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)124{125 return __x.base() != __y.base();126}127 128template <class _Iter1, class _Iter2>129inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14130bool131operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)132{133 return __x.base() < __y.base();134}135 136template <class _Iter1, class _Iter2>137inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14138bool139operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)140{141 return __x.base() <= __y.base();142}143 144template <class _Iter1, class _Iter2>145inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14146bool147operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)148{149 return __x.base() >= __y.base();150}151 152template <class _Iter1, class _Iter2>153inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14154auto155operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)156-> decltype(__y.base() - __x.base())157{158 return __y.base() - __x.base();159}160 161template <class _Iter>162inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14163reverse_iterator<_Iter>164operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)165{166 return reverse_iterator<_Iter>(__x.base() - __n);167}168 169#if _LIBCUDACXX_STD_VER > 11170template <class _Iter>171inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14172reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)173{174 return reverse_iterator<_Iter>(__i);175}176#endif177 178_LIBCUDACXX_END_NAMESPACE_STD179 180#endif // _LIBCUDACXX___ITERATOR_REVERSE_ITERATOR_H181 