Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
array517 linesDownload Raw Back to include
1// -*- C++ -*-2//===---------------------------- array -----------------------------------===//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//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_ARRAY11#define _LIBCUDACXX_ARRAY12 13/*14    array synopsis15 16namespace std17{18template <class T, size_t N >19struct array20{21    // types:22    typedef T & reference;23    typedef const T & const_reference;24    typedef implementation defined iterator;25    typedef implementation defined const_iterator;26    typedef size_t size_type;27    typedef ptrdiff_t difference_type;28    typedef T value_type;29    typedef T* pointer;30    typedef const T* const_pointer;31    typedef std::reverse_iterator<iterator> reverse_iterator;32    typedef std::reverse_iterator<const_iterator> const_reverse_iterator;33 34    // No explicit construct/copy/destroy for aggregate type35    void fill(const T& u);36    void swap(array& a) noexcept(is_nothrow_swappable_v<T>);37 38    // iterators:39    iterator begin() noexcept;40    const_iterator begin() const noexcept;41    iterator end() noexcept;42    const_iterator end() const noexcept;43 44    reverse_iterator rbegin() noexcept;45    const_reverse_iterator rbegin() const noexcept;46    reverse_iterator rend() noexcept;47    const_reverse_iterator rend() const noexcept;48 49    const_iterator cbegin() const noexcept;50    const_iterator cend() const noexcept;51    const_reverse_iterator crbegin() const noexcept;52    const_reverse_iterator crend() const noexcept;53 54    // capacity:55    constexpr size_type size() const noexcept;56    constexpr size_type max_size() const noexcept;57    constexpr bool empty() const noexcept;58 59    // element access:60    reference operator[](size_type n);61    const_reference operator[](size_type n) const; // constexpr in C++1462    const_reference at(size_type n) const; // constexpr in C++1463    reference at(size_type n);64 65    reference front();66    const_reference front() const; // constexpr in C++1467    reference back();68    const_reference back() const; // constexpr in C++1469 70    T* data() noexcept;71    const T* data() const noexcept;72};73 74  template <class T, class... U>75    array(T, U...) -> array<T, 1 + sizeof...(U)>;76 77template <class T, size_t N>78  bool operator==(const array<T,N>& x, const array<T,N>& y);79template <class T, size_t N>80  bool operator!=(const array<T,N>& x, const array<T,N>& y);81template <class T, size_t N>82  bool operator<(const array<T,N>& x, const array<T,N>& y);83template <class T, size_t N>84  bool operator>(const array<T,N>& x, const array<T,N>& y);85template <class T, size_t N>86  bool operator<=(const array<T,N>& x, const array<T,N>& y);87template <class T, size_t N>88  bool operator>=(const array<T,N>& x, const array<T,N>& y);89 90template <class T, size_t N >91  void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++1792 93template <class T> struct tuple_size;94template <size_t I, class T> struct tuple_element;95template <class T, size_t N> struct tuple_size<array<T, N>>;96template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;97template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++1498template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++1499template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14100template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14101 102}  // std103 104*/105 106#ifndef __cuda_std__107#include <__config>108#endif // __cuda_std__109 110#include "__algorithm/swap_ranges.h"111#include "__assert" // all public C++ headers provide the assertion handler112#include "__debug"113#include "__iterator/reverse_iterator.h"114#include "__tuple_dir/sfinae_helpers.h"115#include "__tuple_dir/structured_bindings.h"116#include "__type_traits/conditional.h"117#include "__type_traits/enable_if.h"118#include "__type_traits/is_const.h"119#include "__type_traits/is_same.h"120#include "__type_traits/is_swappable.h"121#include "__utility/integer_sequence.h"122#include "__utility/move.h"123#include "__utility/unreachable.h"124#include "algorithm"125#include "cstdint"126#include "cstdlib"127#include "limits"128#include "stdexcept"129#include "type_traits"130#include "version"131 132// standard-mandated includes133#include "version"134 135// [iterator.range]136#include "__iterator/access.h"137#include "__iterator/data.h"138#include "__iterator/empty.h"139#include "__iterator/reverse_access.h"140#include "__iterator/size.h"141 142// [array.syn]143#ifndef _LIBCUDACXX_HAS_NO_SPACESHIP_OPERATOR144#include <compare>145#endif146#include "initializer_list"147 148// [tuple.helper]149#include "__tuple_dir/tuple_element.h"150#include "__tuple_dir/tuple_size.h"151 152#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)153#  pragma GCC system_header154#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)155#  pragma clang system_header156#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)157#  pragma system_header158#endif // no system header159 160_LIBCUDACXX_BEGIN_NAMESPACE_STD161 162 163template <class _Tp, size_t _Size>164struct _LIBCUDACXX_TEMPLATE_VIS array165{166    // types:167    typedef array __self;168    typedef _Tp                                          value_type;169    typedef value_type&                                  reference;170    typedef const value_type&                            const_reference;171    typedef value_type*                                  iterator;172    typedef const value_type*                            const_iterator;173    typedef value_type*                                  pointer;174    typedef const value_type*                            const_pointer;175    typedef size_t                                       size_type;176    typedef ptrdiff_t                                    difference_type;177    typedef _CUDA_VSTD::reverse_iterator<const_iterator> const_reverse_iterator;178    typedef _CUDA_VSTD::reverse_iterator<iterator>       reverse_iterator;179 180    _Tp __elems_[_Size];181 182    // No explicit construct/copy/destroy for aggregate type183    _LIBCUDACXX_INLINE_VISIBILITY void fill(const value_type& __u) {184      _CUDA_VSTD::fill_n(__elems_, _Size, __u);185    }186 187    _LIBCUDACXX_INLINE_VISIBILITY188    void swap(array& __a) noexcept(__is_nothrow_swappable<_Tp>::value) {189      _CUDA_VSTD::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);190    }191 192    // iterators:193    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14194    iterator begin() noexcept {return iterator(data());}195    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14196    const_iterator begin() const noexcept {return const_iterator(data());}197    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14198    iterator end() noexcept {return iterator(data() + _Size);}199    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14200    const_iterator end() const noexcept {return const_iterator(data() + _Size);}201 202    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14203    reverse_iterator rbegin() noexcept {return reverse_iterator(end());}204    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14205    const_reverse_iterator rbegin() const noexcept {return const_reverse_iterator(end());}206    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14207    reverse_iterator rend() noexcept {return reverse_iterator(begin());}208    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14209    const_reverse_iterator rend() const noexcept {return const_reverse_iterator(begin());}210 211    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14212    const_iterator cbegin() const noexcept {return begin();}213    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14214    const_iterator cend() const noexcept {return end();}215    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14216    const_reverse_iterator crbegin() const noexcept {return rbegin();}217    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14218    const_reverse_iterator crend() const noexcept {return rend();}219 220    // capacity:221    _LIBCUDACXX_INLINE_VISIBILITY222    constexpr size_type size() const noexcept {return _Size;}223    _LIBCUDACXX_INLINE_VISIBILITY224    constexpr size_type max_size() const noexcept {return _Size;}225    _LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY226    constexpr bool empty() const noexcept {return false; }227 228    // element access:229    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14230    reference operator[](size_type __n)             noexcept {return __elems_[__n];}231    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11232    const_reference operator[](size_type __n) const noexcept {return __elems_[__n];}233 234    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14       reference at(size_type __n);235    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;236 237    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 reference front()             noexcept {return __elems_[0];}238    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const_reference front() const noexcept {return __elems_[0];}239    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 reference back()              noexcept {return __elems_[_Size - 1];}240    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const_reference back() const  noexcept {return __elems_[_Size - 1];}241 242    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14243    value_type* data() noexcept {return __elems_;}244    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX14245    const value_type* data() const noexcept {return __elems_;}246};247 248 249template <class _Tp, size_t _Size>250_LIBCUDACXX_CONSTEXPR_AFTER_CXX14251typename array<_Tp, _Size>::reference252array<_Tp, _Size>::at(size_type __n)253{254    if (__n >= _Size)255        __throw_out_of_range("array::at");256 257    return __elems_[__n];258}259 260template <class _Tp, size_t _Size>261_LIBCUDACXX_CONSTEXPR_AFTER_CXX11262typename array<_Tp, _Size>::const_reference263array<_Tp, _Size>::at(size_type __n) const264{265    if (__n >= _Size)266        __throw_out_of_range("array::at");267    return __elems_[__n];268}269 270template <class _Tp>271struct _LIBCUDACXX_TEMPLATE_VIS array<_Tp, 0>272{273    // types:274    typedef array __self;275    typedef _Tp                                   value_type;276    typedef value_type&                           reference;277    typedef const value_type&                     const_reference;278    typedef value_type*                           iterator;279    typedef const value_type*                     const_iterator;280    typedef value_type*                           pointer;281    typedef const value_type*                     const_pointer;282    typedef size_t                                size_type;283    typedef ptrdiff_t                             difference_type;284    typedef _CUDA_VSTD::reverse_iterator<const_iterator>      const_reverse_iterator;285    typedef _CUDA_VSTD::reverse_iterator<iterator>            reverse_iterator;286 287    typedef __conditional_t<is_const<_Tp>::value, const char,288                                char> _CharType;289 290    struct  _ArrayInStructT { _Tp __data_[1]; };291    _ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];292 293    // No explicit construct/copy/destroy for aggregate type294    _LIBCUDACXX_INLINE_VISIBILITY void fill(const value_type&) {295      static_assert(!is_const<_Tp>::value,296                    "cannot fill zero-sized array of type 'const T'");297    }298 299    _LIBCUDACXX_INLINE_VISIBILITY300    void swap(array&) noexcept {301      static_assert(!is_const<_Tp>::value,302                    "cannot swap zero-sized array of type 'const T'");303    }304 305    // iterators:306    _LIBCUDACXX_INLINE_VISIBILITY307    iterator begin() noexcept {return iterator(data());}308    _LIBCUDACXX_INLINE_VISIBILITY309    const_iterator begin() const noexcept {return const_iterator(data());}310    _LIBCUDACXX_INLINE_VISIBILITY311    iterator end() noexcept {return iterator(data());}312    _LIBCUDACXX_INLINE_VISIBILITY313    const_iterator end() const noexcept {return const_iterator(data());}314 315    _LIBCUDACXX_INLINE_VISIBILITY316    reverse_iterator rbegin() noexcept {return reverse_iterator(end());}317    _LIBCUDACXX_INLINE_VISIBILITY318    const_reverse_iterator rbegin() const noexcept {return const_reverse_iterator(end());}319    _LIBCUDACXX_INLINE_VISIBILITY320    reverse_iterator rend() noexcept {return reverse_iterator(begin());}321    _LIBCUDACXX_INLINE_VISIBILITY322    const_reverse_iterator rend() const noexcept {return const_reverse_iterator(begin());}323 324    _LIBCUDACXX_INLINE_VISIBILITY325    const_iterator cbegin() const noexcept {return begin();}326    _LIBCUDACXX_INLINE_VISIBILITY327    const_iterator cend() const noexcept {return end();}328    _LIBCUDACXX_INLINE_VISIBILITY329    const_reverse_iterator crbegin() const noexcept {return rbegin();}330    _LIBCUDACXX_INLINE_VISIBILITY331    const_reverse_iterator crend() const noexcept {return rend();}332 333    // capacity:334    _LIBCUDACXX_INLINE_VISIBILITY335    constexpr size_type size() const noexcept {return 0; }336    _LIBCUDACXX_INLINE_VISIBILITY337    constexpr size_type max_size() const noexcept {return 0;}338    _LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY339    constexpr bool empty() const noexcept {return true;}340 341    // element access:342    _LIBCUDACXX_INLINE_VISIBILITY343    reference operator[](size_type) noexcept {344      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");345      _LIBCUDACXX_UNREACHABLE();346    }347 348    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11349    const_reference operator[](size_type) const noexcept {350      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");351      _LIBCUDACXX_UNREACHABLE();352    }353 354    _LIBCUDACXX_INLINE_VISIBILITY355    reference at(size_type) {356      __throw_out_of_range("array<T, 0>::at");357      _LIBCUDACXX_UNREACHABLE();358    }359 360    _LIBCUDACXX_INLINE_VISIBILITY361    const_reference at(size_type) const {362      __throw_out_of_range("array<T, 0>::at");363      _LIBCUDACXX_UNREACHABLE();364    }365 366    _LIBCUDACXX_INLINE_VISIBILITY367    reference front() noexcept {368      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");369      _LIBCUDACXX_UNREACHABLE();370    }371 372    _LIBCUDACXX_INLINE_VISIBILITY373    const_reference front() const noexcept {374      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");375      _LIBCUDACXX_UNREACHABLE();376    }377 378    _LIBCUDACXX_INLINE_VISIBILITY379    reference back() noexcept {380      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");381      _LIBCUDACXX_UNREACHABLE();382    }383 384    _LIBCUDACXX_INLINE_VISIBILITY385    const_reference back() const noexcept {386      _LIBCUDACXX_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");387      _LIBCUDACXX_UNREACHABLE();388    }389 390    _LIBCUDACXX_INLINE_VISIBILITY391    value_type* data() noexcept {return reinterpret_cast<value_type*>(__elems_);}392    _LIBCUDACXX_INLINE_VISIBILITY393    const value_type* data() const noexcept {return reinterpret_cast<const value_type*>(__elems_);}394};395 396 397#ifndef _LIBCUDACXX_HAS_NO_DEDUCTION_GUIDES398template<class _Tp, class... _Args,399         class = __enable_if_t<(is_same_v<_Tp, _Args> && ...), void>400         >401_LIBCUDACXX_HOST_DEVICE array(_Tp, _Args...) -> array<_Tp, 1 + sizeof...(_Args)>;402#endif403 404template <class _Tp, size_t _Size>405inline _LIBCUDACXX_INLINE_VISIBILITY406_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool407operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)408{409    return _CUDA_VSTD::equal(__x.begin(), __x.end(), __y.begin());410}411 412template <class _Tp, size_t _Size>413inline _LIBCUDACXX_INLINE_VISIBILITY414_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool415operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)416{417    return !(__x == __y);418}419 420template <class _Tp, size_t _Size>421inline _LIBCUDACXX_INLINE_VISIBILITY422_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool423operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)424{425    return _CUDA_VSTD::lexicographical_compare(__x.begin(), __x.end(),426                                          __y.begin(), __y.end());427}428 429template <class _Tp, size_t _Size>430inline _LIBCUDACXX_INLINE_VISIBILITY431_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool432operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)433{434    return __y < __x;435}436 437template <class _Tp, size_t _Size>438inline _LIBCUDACXX_INLINE_VISIBILITY439_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool440operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)441{442    return !(__y < __x);443}444 445template <class _Tp, size_t _Size>446inline _LIBCUDACXX_INLINE_VISIBILITY447_LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool448operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)449{450    return !(__x < __y);451}452 453template <class _Tp, size_t _Size>454inline _LIBCUDACXX_INLINE_VISIBILITY455__enable_if_t456<457    _Size == 0 ||458    __is_swappable<_Tp>::value,459    void460>461swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)462                                  noexcept(noexcept(__x.swap(__y)))463{464    __x.swap(__y);465}466 467template <class _Tp, size_t _Size>468struct _LIBCUDACXX_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >469    : public integral_constant<size_t, _Size> {};470 471template <size_t _Ip, class _Tp, size_t _Size>472struct _LIBCUDACXX_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >473{474    static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");475    typedef _Tp type;476};477 478template <size_t _Ip, class _Tp, size_t _Size>479inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11480_Tp&481get(array<_Tp, _Size>& __a) noexcept482{483    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");484    return __a.__elems_[_Ip];485}486 487template <size_t _Ip, class _Tp, size_t _Size>488inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11489const _Tp&490get(const array<_Tp, _Size>& __a) noexcept491{492    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");493    return __a.__elems_[_Ip];494}495 496template <size_t _Ip, class _Tp, size_t _Size>497inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11498_Tp&&499get(array<_Tp, _Size>&& __a) noexcept500{501    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");502    return _CUDA_VSTD::move(__a.__elems_[_Ip]);503}504 505template <size_t _Ip, class _Tp, size_t _Size>506inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11507const _Tp&&508get(const array<_Tp, _Size>&& __a) noexcept509{510    static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");511    return _CUDA_VSTD::move(__a.__elems_[_Ip]);512}513 514_LIBCUDACXX_END_NAMESPACE_STD515 516#endif  // _LIBCUDACXX_ARRAY517 
codekingpro/portable-devtools · Team Ai