Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
wrap_iter.h422 linesDownload Raw Back to __iterator
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_WRAP_ITER_H12#define _LIBCUDACXX___ITERATOR_WRAP_ITER_H13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#include "../__debug"19#include "../__iterator/iterator_traits.h"20#include "../__memory/addressof.h"21#include "../__memory/pointer_traits.h"22#include "../__type_traits/enable_if.h"23#include "../__type_traits/is_convertible.h"24#include "../__type_traits/is_trivially_copy_assignable.h"25 26#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)27#  pragma GCC system_header28#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)29#  pragma clang system_header30#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)31#  pragma system_header32#endif // no system header33 34_LIBCUDACXX_BEGIN_NAMESPACE_STD35 36 37// __wrap_iter38 39template <class _Iter> class __wrap_iter;40 41template <class _Iter1, class _Iter2>42_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG43bool44operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;45 46template <class _Iter1, class _Iter2>47_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG48bool49operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;50 51template <class _Iter1, class _Iter2>52_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG53bool54operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;55 56template <class _Iter1, class _Iter2>57_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG58bool59operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;60 61template <class _Iter1, class _Iter2>62_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG63bool64operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;65 66template <class _Iter1, class _Iter2>67_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG68bool69operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;70 71template <class _Iter1, class _Iter2>72_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG73auto74operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept75-> decltype(__x.base() - __y.base());76 77template <class _Iter>78_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG79__wrap_iter<_Iter>80operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) noexcept;81 82template <class _Ip, class _Op> _Op _LIBCUDACXX_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);83template <class _B1, class _B2> _B2 _LIBCUDACXX_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);84template <class _Ip, class _Op> _Op _LIBCUDACXX_INLINE_VISIBILITY move(_Ip, _Ip, _Op);85template <class _B1, class _B2> _B2 _LIBCUDACXX_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);86 87#if _LIBCUDACXX_DEBUG_LEVEL < 288 89template <class _Tp>90_LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG91__enable_if_t92<93    is_trivially_copy_assignable<_Tp>::value,94    _Tp*95>96__unwrap_iter(__wrap_iter<_Tp*>);97 98#else99 100template <class _Tp>101inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG102__enable_if_t103<104    is_trivially_copy_assignable<_Tp>::value,105    __wrap_iter<_Tp*>106>107__unwrap_iter(__wrap_iter<_Tp*> __i);108 109#endif110 111template <class _Iter>112class __wrap_iter113{114public:115    typedef _Iter                                                      iterator_type;116    typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;117    typedef typename iterator_traits<iterator_type>::value_type        value_type;118    typedef typename iterator_traits<iterator_type>::difference_type   difference_type;119    typedef typename iterator_traits<iterator_type>::pointer           pointer;120    typedef typename iterator_traits<iterator_type>::reference         reference;121private:122    iterator_type __i;123public:124    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter() noexcept125#if _LIBCUDACXX_STD_VER > 11126                : __i{}127#endif128    {129#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE130        __get_db()->__insert_i(this);131#endif132    }133    template <class _Up> _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG134        __wrap_iter(const __wrap_iter<_Up>& __u,135            __enable_if_t<is_convertible<_Up, iterator_type>::value>* = 0) noexcept136            : __i(__u.base())137    {138#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE139        __get_db()->__iterator_copy(this, &__u);140#endif141    }142#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE143    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG144    __wrap_iter(const __wrap_iter& __x)145        : __i(__x.base())146    {147        __get_db()->__iterator_copy(this, &__x);148    }149    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG150    __wrap_iter& operator=(const __wrap_iter& __x)151    {152        if (this != &__x)153        {154            __get_db()->__iterator_copy(this, &__x);155            __i = __x.__i;156        }157        return *this;158    }159    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG160    ~__wrap_iter()161    {162        __get_db()->__erase_i(this);163    }164#endif165    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG reference operator*() const noexcept166    {167#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE168        _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this),169                       "Attempted to dereference a non-dereferenceable iterator");170#endif171        return *__i;172    }173    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG pointer  operator->() const noexcept174    {175#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE176        _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this),177                       "Attempted to dereference a non-dereferenceable iterator");178#endif179        return (pointer)_CUDA_VSTD::addressof(*__i);180    }181    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() noexcept182    {183#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE184        _LIBCUDACXX_ASSERT(__get_const_db()->__dereferenceable(this),185                       "Attempted to increment non-incrementable iterator");186#endif187        ++__i;188        return *this;189    }190    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter  operator++(int) noexcept191        {__wrap_iter __tmp(*this); ++(*this); return __tmp;}192 193    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() noexcept194    {195#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE196        _LIBCUDACXX_ASSERT(__get_const_db()->__decrementable(this),197                       "Attempted to decrement non-decrementable iterator");198#endif199        --__i;200        return *this;201    }202    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter  operator--(int) noexcept203        {__wrap_iter __tmp(*this); --(*this); return __tmp;}204    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter  operator+ (difference_type __n) const noexcept205        {__wrap_iter __w(*this); __w += __n; return __w;}206    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) noexcept207    {208#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE209        _LIBCUDACXX_ASSERT(__get_const_db()->__addable(this, __n),210                   "Attempted to add/subtract iterator outside of valid range");211#endif212        __i += __n;213        return *this;214    }215    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter  operator- (difference_type __n) const noexcept216        {return *this + (-__n);}217    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) noexcept218        {*this += -__n; return *this;}219    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG reference    operator[](difference_type __n) const noexcept220    {221#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE222        _LIBCUDACXX_ASSERT(__get_const_db()->__subscriptable(this, __n),223                   "Attempted to subscript iterator outside of valid range");224#endif225        return __i[__n];226    }227 228    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG iterator_type base() const noexcept {return __i;}229 230private:231#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE232    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)233    {234        __get_db()->__insert_ic(this, __p);235    }236#else237    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) noexcept : __i(__x) {}238#endif239 240    template <class _Up> friend class __wrap_iter;241    template <class _CharT, class _Traits, class _Alloc> friend class basic_string;242    template <class _Tp, class _Alloc> friend class vector;243    template <class _Tp, size_t> friend class span;244 245    template <class _Iter1, class _Iter2>246    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend247    bool248    operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;249 250    template <class _Iter1, class _Iter2>251    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend252    bool253    operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;254 255    template <class _Iter1, class _Iter2>256    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend257    bool258    operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;259 260    template <class _Iter1, class _Iter2>261    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend262    bool263    operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;264 265    template <class _Iter1, class _Iter2>266    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend267    bool268    operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;269 270    template <class _Iter1, class _Iter2>271    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend272    bool273    operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) noexcept;274 275    template <class _Iter1, class _Iter2>276    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend277    auto278    operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept279    -> decltype(__x.base() - __y.base());280 281    template <class _Iter1>282    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend283    __wrap_iter<_Iter1>284    operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) noexcept;285 286    template <class _Ip, class _Op> _LIBCUDACXX_HOST_DEVICE friend _Op copy(_Ip, _Ip, _Op);287    template <class _B1, class _B2> _LIBCUDACXX_HOST_DEVICE friend _B2 copy_backward(_B1, _B1, _B2);288    template <class _Ip, class _Op> _LIBCUDACXX_HOST_DEVICE friend _Op move(_Ip, _Ip, _Op);289    template <class _B1, class _B2> _LIBCUDACXX_HOST_DEVICE friend _B2 move_backward(_B1, _B1, _B2);290 291#if _LIBCUDACXX_DEBUG_LEVEL < 2292    template <class _Tp>293    _LIBCUDACXX_HOST_DEVICE _LIBCUDACXX_CONSTEXPR_IF_NODEBUG friend294    __enable_if_t295    <296        is_trivially_copy_assignable<_Tp>::value,297        _Tp*298    >299    __unwrap_iter(__wrap_iter<_Tp*>);300#else301  template <class _Tp>302  inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG303  __enable_if_t304  <305      is_trivially_copy_assignable<_Tp>::value,306      __wrap_iter<_Tp*>307  >308  __unwrap_iter(__wrap_iter<_Tp*> __i);309#endif310};311 312template <class _Iter1, class _Iter2>313inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG314bool315operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept316{317    return __x.base() == __y.base();318}319 320template <class _Iter1, class _Iter2>321inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG322bool323operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept324{325#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE326    _LIBCUDACXX_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),327                   "Attempted to compare incomparable iterators");328#endif329    return __x.base() < __y.base();330}331 332template <class _Iter1, class _Iter2>333inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG334bool335operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept336{337    return !(__x == __y);338}339 340template <class _Iter1, class _Iter2>341inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG342bool343operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept344{345    return __y < __x;346}347 348template <class _Iter1, class _Iter2>349inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG350bool351operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept352{353    return !(__x < __y);354}355 356template <class _Iter1, class _Iter2>357inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG358bool359operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept360{361    return !(__y < __x);362}363 364template <class _Iter1>365inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG366bool367operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept368{369    return !(__x == __y);370}371 372template <class _Iter1>373inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG374bool375operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept376{377    return __y < __x;378}379 380template <class _Iter1>381inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG382bool383operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept384{385    return !(__x < __y);386}387 388template <class _Iter1>389inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG390bool391operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) noexcept392{393    return !(__y < __x);394}395 396template <class _Iter1, class _Iter2>397inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG398auto399operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) noexcept400-> decltype(__x.base() - __y.base())401{402#ifdef _LIBCUDACXX_ENABLE_DEBUG_MODE403    _LIBCUDACXX_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),404                   "Attempted to subtract incompatible iterators");405#endif406    return __x.base() - __y.base();407}408 409template <class _Iter>410inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_IF_NODEBUG411__wrap_iter<_Iter>412operator+(typename __wrap_iter<_Iter>::difference_type __n,413          __wrap_iter<_Iter> __x) noexcept414{415    __x += __n;416    return __x;417}418 419_LIBCUDACXX_END_NAMESPACE_STD420 421#endif // _LIBCUDACXX___ITERATOR_WRAP_ITER_H422 
codekingpro/portable-devtools · Team Ai