codekingpro/portable-devtools
115k
1// -*- C++ -*-2//===-------------------------- memory ------------------------------------===//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_MEMORY11#define _LIBCUDACXX_MEMORY12 13/*14 memory synopsis15 16namespace std17{18 19struct allocator_arg_t { };20inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();21 22template <class T, class Alloc> struct uses_allocator;23 24template <class Ptr>25struct pointer_traits26{27 typedef Ptr pointer;28 typedef <details> element_type;29 typedef <details> difference_type;30 31 template <class U> using rebind = <details>;32 33 static pointer pointer_to(<details>);34};35 36template <class T>37struct pointer_traits<T*>38{39 typedef T* pointer;40 typedef T element_type;41 typedef ptrdiff_t difference_type;42 43 template <class U> using rebind = U*;44 45 static pointer pointer_to(<details>) noexcept; // constexpr in C++2046};47 48template <class T> constexpr T* to_address(T* p) noexcept; // C++2049template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++2050 51template <class Alloc>52struct allocator_traits53{54 typedef Alloc allocator_type;55 typedef typename allocator_type::value_type56 value_type;57 58 typedef Alloc::pointer | value_type* pointer;59 typedef Alloc::const_pointer60 | pointer_traits<pointer>::rebind<const value_type>61 const_pointer;62 typedef Alloc::void_pointer63 | pointer_traits<pointer>::rebind<void>64 void_pointer;65 typedef Alloc::const_void_pointer66 | pointer_traits<pointer>::rebind<const void>67 const_void_pointer;68 typedef Alloc::difference_type69 | pointer_traits<pointer>::difference_type70 difference_type;71 typedef Alloc::size_type72 | make_unsigned<difference_type>::type73 size_type;74 typedef Alloc::propagate_on_container_copy_assignment75 | false_type propagate_on_container_copy_assignment;76 typedef Alloc::propagate_on_container_move_assignment77 | false_type propagate_on_container_move_assignment;78 typedef Alloc::propagate_on_container_swap79 | false_type propagate_on_container_swap;80 typedef Alloc::is_always_equal81 | is_empty is_always_equal;82 83 template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;84 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;85 86 static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++2087 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++2088 89 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;90 91 template <class T, class... Args>92 static void construct(allocator_type& a, T* p, Args&&... args);93 94 template <class T>95 static void destroy(allocator_type& a, T* p);96 97 static size_type max_size(const allocator_type& a); // noexcept in C++1498 99 static allocator_type100 select_on_container_copy_construction(const allocator_type& a);101};102 103template <>104class allocator<void>105{106public:107 typedef void* pointer;108 typedef const void* const_pointer;109 typedef void value_type;110 111 template <class _Up> struct rebind {typedef allocator<_Up> other;};112};113 114template <class T>115class allocator116{117public:118 typedef size_t size_type;119 typedef ptrdiff_t difference_type;120 typedef T* pointer;121 typedef const T* const_pointer;122 typedef typename add_lvalue_reference<T>::type reference;123 typedef typename add_lvalue_reference<const T>::type const_reference;124 typedef T value_type;125 126 template <class U> struct rebind {typedef allocator<U> other;};127 128 constexpr allocator() noexcept; // constexpr in C++20129 constexpr allocator(const allocator&) noexcept; // constexpr in C++20130 template <class U>131 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20132 ~allocator();133 pointer address(reference x) const noexcept;134 const_pointer address(const_reference x) const noexcept;135 pointer allocate(size_type, allocator<void>::const_pointer hint = 0);136 void deallocate(pointer p, size_type n) noexcept;137 size_type max_size() const noexcept;138 template<class U, class... Args>139 void construct(U* p, Args&&... args);140 template <class U>141 void destroy(U* p);142};143 144template <class T, class U>145bool operator==(const allocator<T>&, const allocator<U>&) noexcept;146 147template <class T, class U>148bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;149 150template <class OutputIterator, class T>151class raw_storage_iterator152 : public iterator<output_iterator_tag,153 T, // purposefully not C++03154 ptrdiff_t, // purposefully not C++03155 T*, // purposefully not C++03156 raw_storage_iterator&> // purposefully not C++03157{158public:159 explicit raw_storage_iterator(OutputIterator x);160 raw_storage_iterator& operator*();161 raw_storage_iterator& operator=(const T& element);162 raw_storage_iterator& operator++();163 raw_storage_iterator operator++(int);164};165 166template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;167template <class T> void return_temporary_buffer(T* p) noexcept;168 169template <class T> T* addressof(T& r) noexcept;170template <class T> T* addressof(const T&& r) noexcept = delete;171 172template <class InputIterator, class ForwardIterator>173ForwardIterator174uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);175 176template <class InputIterator, class Size, class ForwardIterator>177ForwardIterator178uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);179 180template <class ForwardIterator, class T>181void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);182 183template <class ForwardIterator, class Size, class T>184ForwardIterator185uninitialized_fill_n(ForwardIterator first, Size n, const T& x);186 187template <class T>188void destroy_at(T* location);189 190template <class ForwardIterator>191 void destroy(ForwardIterator first, ForwardIterator last);192 193template <class ForwardIterator, class Size>194 ForwardIterator destroy_n(ForwardIterator first, Size n);195 196template <class InputIterator, class ForwardIterator>197 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);198 199template <class InputIterator, class Size, class ForwardIterator>200 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);201 202template <class ForwardIterator>203 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);204 205template <class ForwardIterator, class Size>206 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);207 208template <class ForwardIterator>209 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);210 211template <class ForwardIterator, class Size>212 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);213 214template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17215 216template<class X>217class auto_ptr // deprecated in C++11, removed in C++17218{219public:220 typedef X element_type;221 222 explicit auto_ptr(X* p =0) throw();223 auto_ptr(auto_ptr&) throw();224 template<class Y> auto_ptr(auto_ptr<Y>&) throw();225 auto_ptr& operator=(auto_ptr&) throw();226 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();227 auto_ptr& operator=(auto_ptr_ref<X> r) throw();228 ~auto_ptr() throw();229 230 typename add_lvalue_reference<X>::type operator*() const throw();231 X* operator->() const throw();232 X* get() const throw();233 X* release() throw();234 void reset(X* p =0) throw();235 236 auto_ptr(auto_ptr_ref<X>) throw();237 template<class Y> operator auto_ptr_ref<Y>() throw();238 template<class Y> operator auto_ptr<Y>() throw();239};240 241template <class T>242struct default_delete243{244 constexpr default_delete() noexcept = default;245 template <class U> default_delete(const default_delete<U>&) noexcept;246 247 void operator()(T*) const noexcept;248};249 250template <class T>251struct default_delete<T[]>252{253 constexpr default_delete() noexcept = default;254 void operator()(T*) const noexcept;255 template <class U> void operator()(U*) const = delete;256};257 258template <class T, class D = default_delete<T>>259class unique_ptr260{261public:262 typedef see below pointer;263 typedef T element_type;264 typedef D deleter_type;265 266 // constructors267 constexpr unique_ptr() noexcept;268 explicit unique_ptr(pointer p) noexcept;269 unique_ptr(pointer p, see below d1) noexcept;270 unique_ptr(pointer p, see below d2) noexcept;271 unique_ptr(unique_ptr&& u) noexcept;272 unique_ptr(nullptr_t) noexcept : unique_ptr() { }273 template <class U, class E>274 unique_ptr(unique_ptr<U, E>&& u) noexcept;275 template <class U>276 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17277 278 // destructor279 ~unique_ptr();280 281 // assignment282 unique_ptr& operator=(unique_ptr&& u) noexcept;283 template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;284 unique_ptr& operator=(nullptr_t) noexcept;285 286 // observers287 typename add_lvalue_reference<T>::type operator*() const;288 pointer operator->() const noexcept;289 pointer get() const noexcept;290 deleter_type& get_deleter() noexcept;291 const deleter_type& get_deleter() const noexcept;292 explicit operator bool() const noexcept;293 294 // modifiers295 pointer release() noexcept;296 void reset(pointer p = pointer()) noexcept;297 void swap(unique_ptr& u) noexcept;298};299 300template <class T, class D>301class unique_ptr<T[], D>302{303public:304 typedef implementation-defined pointer;305 typedef T element_type;306 typedef D deleter_type;307 308 // constructors309 constexpr unique_ptr() noexcept;310 explicit unique_ptr(pointer p) noexcept;311 unique_ptr(pointer p, see below d) noexcept;312 unique_ptr(pointer p, see below d) noexcept;313 unique_ptr(unique_ptr&& u) noexcept;314 unique_ptr(nullptr_t) noexcept : unique_ptr() { }315 316 // destructor317 ~unique_ptr();318 319 // assignment320 unique_ptr& operator=(unique_ptr&& u) noexcept;321 unique_ptr& operator=(nullptr_t) noexcept;322 323 // observers324 T& operator[](size_t i) const;325 pointer get() const noexcept;326 deleter_type& get_deleter() noexcept;327 const deleter_type& get_deleter() const noexcept;328 explicit operator bool() const noexcept;329 330 // modifiers331 pointer release() noexcept;332 void reset(pointer p = pointer()) noexcept;333 void reset(nullptr_t) noexcept;334 template <class U> void reset(U) = delete;335 void swap(unique_ptr& u) noexcept;336};337 338template <class T, class D>339 void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;340 341template <class T1, class D1, class T2, class D2>342 bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);343template <class T1, class D1, class T2, class D2>344 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);345template <class T1, class D1, class T2, class D2>346 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);347template <class T1, class D1, class T2, class D2>348 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);349template <class T1, class D1, class T2, class D2>350 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);351template <class T1, class D1, class T2, class D2>352 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);353 354template <class T, class D>355 bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;356template <class T, class D>357 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;358template <class T, class D>359 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;360template <class T, class D>361 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;362 363template <class T, class D>364 bool operator<(const unique_ptr<T, D>& x, nullptr_t);365template <class T, class D>366 bool operator<(nullptr_t, const unique_ptr<T, D>& y);367template <class T, class D>368 bool operator<=(const unique_ptr<T, D>& x, nullptr_t);369template <class T, class D>370 bool operator<=(nullptr_t, const unique_ptr<T, D>& y);371template <class T, class D>372 bool operator>(const unique_ptr<T, D>& x, nullptr_t);373template <class T, class D>374 bool operator>(nullptr_t, const unique_ptr<T, D>& y);375template <class T, class D>376 bool operator>=(const unique_ptr<T, D>& x, nullptr_t);377template <class T, class D>378 bool operator>=(nullptr_t, const unique_ptr<T, D>& y);379 380class bad_weak_ptr381 : public std::exception382{383 bad_weak_ptr() noexcept;384};385 386template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14387template<class T> unique_ptr<T> make_unique(size_t n); // C++14388template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]389 390template<class E, class T, class Y, class D>391 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);392 393template<class T>394class shared_ptr395{396public:397 typedef T element_type;398 typedef weak_ptr<T> weak_type; // C++17399 400 // constructors:401 constexpr shared_ptr() noexcept;402 template<class Y> explicit shared_ptr(Y* p);403 template<class Y, class D> shared_ptr(Y* p, D d);404 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);405 template <class D> shared_ptr(nullptr_t p, D d);406 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);407 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;408 shared_ptr(const shared_ptr& r) noexcept;409 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;410 shared_ptr(shared_ptr&& r) noexcept;411 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;412 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);413 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17414 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);415 shared_ptr(nullptr_t) : shared_ptr() { }416 417 // destructor:418 ~shared_ptr();419 420 // assignment:421 shared_ptr& operator=(const shared_ptr& r) noexcept;422 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;423 shared_ptr& operator=(shared_ptr&& r) noexcept;424 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);425 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17426 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);427 428 // modifiers:429 void swap(shared_ptr& r) noexcept;430 void reset() noexcept;431 template<class Y> void reset(Y* p);432 template<class Y, class D> void reset(Y* p, D d);433 template<class Y, class D, class A> void reset(Y* p, D d, A a);434 435 // observers:436 T* get() const noexcept;437 T& operator*() const noexcept;438 T* operator->() const noexcept;439 long use_count() const noexcept;440 bool unique() const noexcept;441 explicit operator bool() const noexcept;442 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;443 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;444};445 446// shared_ptr comparisons:447template<class T, class U>448 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;449template<class T, class U>450 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;451template<class T, class U>452 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;453template<class T, class U>454 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;455template<class T, class U>456 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;457template<class T, class U>458 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;459 460template <class T>461 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;462template <class T>463 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;464template <class T>465 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;466template <class T>467 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;468template <class T>469 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;470template <class T>471bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;472template <class T>473 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;474template <class T>475 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;476template <class T>477 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;478template <class T>479 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;480template <class T>481 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;482template <class T>483 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;484 485// shared_ptr specialized algorithms:486template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;487 488// shared_ptr casts:489template<class T, class U>490 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;491template<class T, class U>492 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;493template<class T, class U>494 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;495 496// shared_ptr I/O:497template<class E, class T, class Y>498 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);499 500// shared_ptr get_deleter:501template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;502 503template<class T, class... Args>504 shared_ptr<T> make_shared(Args&&... args);505template<class T, class A, class... Args>506 shared_ptr<T> allocate_shared(const A& a, Args&&... args);507 508template<class T>509class weak_ptr510{511public:512 typedef T element_type;513 514 // constructors515 constexpr weak_ptr() noexcept;516 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;517 weak_ptr(weak_ptr const& r) noexcept;518 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;519 weak_ptr(weak_ptr&& r) noexcept; // C++14520 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14521 522 // destructor523 ~weak_ptr();524 525 // assignment526 weak_ptr& operator=(weak_ptr const& r) noexcept;527 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;528 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;529 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14530 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14531 532 // modifiers533 void swap(weak_ptr& r) noexcept;534 void reset() noexcept;535 536 // observers537 long use_count() const noexcept;538 bool expired() const noexcept;539 shared_ptr<T> lock() const noexcept;540 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;541 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;542};543 544// weak_ptr specialized algorithms:545template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;546 547// class owner_less:548template<class T> struct owner_less;549 550template<class T>551struct owner_less<shared_ptr<T> >552 : __binary_function<shared_ptr<T>, shared_ptr<T>, bool>553{554 typedef bool result_type;555 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;556 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;557 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;558};559 560template<class T>561struct owner_less<weak_ptr<T> >562 : __binary_function<weak_ptr<T>, weak_ptr<T>, bool>563{564 typedef bool result_type;565 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;566 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;567 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;568};569 570template <> // Added in C++14571struct owner_less<void>572{573 template <class _Tp, class _Up>574 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;575 template <class _Tp, class _Up>576 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;577 template <class _Tp, class _Up>578 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;579 template <class _Tp, class _Up>580 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;581 582 typedef void is_transparent;583};584 585template<class T>586class enable_shared_from_this587{588protected:589 constexpr enable_shared_from_this() noexcept;590 enable_shared_from_this(enable_shared_from_this const&) noexcept;591 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;592 ~enable_shared_from_this();593public:594 shared_ptr<T> shared_from_this();595 shared_ptr<T const> shared_from_this() const;596};597 598template<class T>599 bool atomic_is_lock_free(const shared_ptr<T>* p);600template<class T>601 shared_ptr<T> atomic_load(const shared_ptr<T>* p);602template<class T>603 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);604template<class T>605 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);606template<class T>607 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);608template<class T>609 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);610template<class T>611 shared_ptr<T>612 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);613template<class T>614 bool615 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);616template<class T>617 bool618 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);619template<class T>620 bool621 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,622 shared_ptr<T> w, memory_order success,623 memory_order failure);624template<class T>625 bool626 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,627 shared_ptr<T> w, memory_order success,628 memory_order failure);629// Hash support630template <class T> struct hash;631template <class T, class D> struct hash<unique_ptr<T, D> >;632template <class T> struct hash<shared_ptr<T> >;633 634template <class T, class Alloc>635 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;636 637// Pointer safety638enum class pointer_safety { relaxed, preferred, strict };639void declare_reachable(void *p);640template <class T> T *undeclare_reachable(T *p);641void declare_no_pointers(char *p, size_t n);642void undeclare_no_pointers(char *p, size_t n);643pointer_safety get_pointer_safety() noexcept;644 645void* align(size_t alignment, size_t size, void*& ptr, size_t& space);646 647} // std648 649*/650#ifndef __cuda_std__651#include <__config>652#include <typeinfo>653#include <new>654#include <stdexcept>655#include <cstring>656#if !defined(_LIBCUDACXX_HAS_NO_ATOMIC_HEADER)657# include <atomic>658#endif659#endif //__cuda_std__660 661#include "__assert" // all public C++ headers provide the assertion handler662#include "__functional_base"663#include "__iterator/iterator_traits.h"664#include "__iterator/iterator.h"665#include "__memory/addressof.h"666#include "__memory/construct_at.h"667#include "__memory/pointer_traits.h"668#include "__memory/voidify.h"669#include "__tuple_dir/tuple_indices.h"670#include "__type_traits/decay.h"671#include "__type_traits/enable_if.h"672#include "__type_traits/integral_constant.h"673#include "__type_traits/is_array.h"674#include "__type_traits/is_assignable.h"675#include "__type_traits/is_copy_constructible.h"676#include "__type_traits/is_constructible.h"677#include "__type_traits/is_convertible.h"678#include "__type_traits/is_default_constructible.h"679#include "__type_traits/is_move_constructible.h"680#include "__type_traits/is_reference.h"681#include "__type_traits/is_same.h"682#include "__type_traits/is_trivially_destructible.h"683#include "__type_traits/is_trivially_move_constructible.h"684#include "__type_traits/is_void.h"685#include "__type_traits/remove_const.h"686#include "__type_traits/remove_cv.h"687#include "__type_traits/remove_extent.h"688#include "__type_traits/remove_reference.h"689#include "__type_traits/void_t.h"690#include "__utility/declval.h"691#include "__utility/forward.h"692#include "__utility/piecewise_construct.h"693#include "cstddef"694#include "cstdint"695#include "iosfwd"696#include "limits"697#include "tuple"698#include "type_traits"699 700// standard-mandated includes701#include "version"702 703#ifndef __cuda_std__704#include <__pragma_push>705#endif //__cuda_std__706 707#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)708# pragma GCC system_header709#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)710# pragma clang system_header711#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)712# pragma system_header713#endif // no system header714 715_LIBCUDACXX_BEGIN_NAMESPACE_STD716 717template <class _ValueType>718inline _LIBCUDACXX_INLINE_VISIBILITY719_ValueType __libcpp_relaxed_load(_ValueType const* __value) {720#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && \721 defined(__ATOMIC_RELAXED) && \722 (__has_builtin(__atomic_load_n) || defined(_LIBCUDACXX_COMPILER_GCC))723 return __atomic_load_n(__value, __ATOMIC_RELAXED);724#else725 return *__value;726#endif727}728 729template <class _ValueType>730inline _LIBCUDACXX_INLINE_VISIBILITY731_ValueType __libcpp_acquire_load(_ValueType const* __value) {732#if !defined(_LIBCUDACXX_HAS_NO_THREADS) && \733 defined(__ATOMIC_ACQUIRE) && \734 (__has_builtin(__atomic_load_n) || defined(_LIBCUDACXX_COMPILER_GCC))735 return __atomic_load_n(__value, __ATOMIC_ACQUIRE);736#else737 return *__value;738#endif739}740 741// addressof moved to <type_traits>742 743template <class _Tp> class allocator;744 745template <>746class _LIBCUDACXX_TEMPLATE_VIS allocator<void>747{748public:749 typedef void* pointer;750 typedef const void* const_pointer;751 typedef void value_type;752 753 template <class _Up> struct rebind {typedef allocator<_Up> other;};754};755 756template <>757class _LIBCUDACXX_TEMPLATE_VIS allocator<const void>758{759public:760 typedef const void* pointer;761 typedef const void* const_pointer;762 typedef const void value_type;763 764 template <class _Up> struct rebind {typedef allocator<_Up> other;};765};766 767// allocator_traits768 769template <class _Tp, class = void>770struct __has_pointer_type : false_type {};771 772template <class _Tp>773struct __has_pointer_type<_Tp,774 __void_t<typename _Tp::pointer>> : true_type {};775 776namespace __pointer_type_imp777{778 779template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>780struct __pointer_type781{782 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Dp::pointer type;783};784 785template <class _Tp, class _Dp>786struct __pointer_type<_Tp, _Dp, false>787{788 typedef _LIBCUDACXX_NODEBUG_TYPE _Tp* type;789};790 791} // __pointer_type_imp792 793template <class _Tp, class _Dp>794struct __pointer_type795{796 typedef _LIBCUDACXX_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, __libcpp_remove_reference_t<_Dp>>::type type;797};798 799template <class _Tp, class = void>800struct __has_const_pointer : false_type {};801 802template <class _Tp>803struct __has_const_pointer<_Tp,804 __void_t<typename _Tp::const_pointer>> : true_type {};805 806template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>807struct __const_pointer808{809 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::const_pointer type;810};811 812template <class _Tp, class _Ptr, class _Alloc>813struct __const_pointer<_Tp, _Ptr, _Alloc, false>814{815 typedef _LIBCUDACXX_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;816};817 818template <class _Tp, class = void>819struct __has_void_pointer : false_type {};820 821template <class _Tp>822struct __has_void_pointer<_Tp,823 __void_t<typename _Tp::void_pointer>> : true_type {};824 825template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>826struct __void_pointer827{828 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::void_pointer type;829};830 831template <class _Ptr, class _Alloc>832struct __void_pointer<_Ptr, _Alloc, false>833{834 typedef _LIBCUDACXX_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;835};836 837template <class _Tp, class = void>838struct __has_const_void_pointer : false_type {};839 840template <class _Tp>841struct __has_const_void_pointer<_Tp,842 __void_t<typename _Tp::const_void_pointer>> : true_type {};843 844template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>845struct __const_void_pointer846{847 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::const_void_pointer type;848};849 850template <class _Ptr, class _Alloc>851struct __const_void_pointer<_Ptr, _Alloc, false>852{853 typedef _LIBCUDACXX_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;854};855 856template <class _Tp>857inline _LIBCUDACXX_INLINE_VISIBILITY constexpr858_Tp*859__to_raw_pointer(_Tp* __p) noexcept860{861 return __p;862}863 864#if _LIBCUDACXX_STD_VER <= 17865template <class _Pointer>866inline _LIBCUDACXX_INLINE_VISIBILITY867typename pointer_traits<_Pointer>::element_type*868__to_raw_pointer(_Pointer __p) noexcept869{870 return _CUDA_VSTD::__to_raw_pointer(__p.operator->());871}872#else873template <class _Pointer>874inline _LIBCUDACXX_INLINE_VISIBILITY875auto876__to_raw_pointer(const _Pointer& __p) noexcept877-> decltype(pointer_traits<_Pointer>::to_address(__p))878{879 return pointer_traits<_Pointer>::to_address(__p);880}881 882template <class _Pointer, class... _None>883inline _LIBCUDACXX_INLINE_VISIBILITY884auto885__to_raw_pointer(const _Pointer& __p, _None...) noexcept886{887 return _CUDA_VSTD::__to_raw_pointer(__p.operator->());888}889#endif890 891template <class _Tp, class = void>892struct __has_size_type : false_type {};893 894template <class _Tp>895struct __has_size_type<_Tp,896 __void_t<typename _Tp::size_type>> : true_type {};897 898template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>899struct __size_type900{901 typedef _LIBCUDACXX_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;902};903 904template <class _Alloc, class _DiffType>905struct __size_type<_Alloc, _DiffType, true>906{907 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::size_type type;908};909 910template <class _Tp, class = void>911struct __has_propagate_on_container_copy_assignment : false_type {};912 913template <class _Tp>914struct __has_propagate_on_container_copy_assignment<_Tp,915 __void_t<typename _Tp::propagate_on_container_copy_assignment>>916 : true_type {};917 918template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>919struct __propagate_on_container_copy_assignment920{921 typedef _LIBCUDACXX_NODEBUG_TYPE false_type type;922};923 924template <class _Alloc>925struct __propagate_on_container_copy_assignment<_Alloc, true>926{927 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;928};929 930template <class _Tp, class = void>931struct __has_propagate_on_container_move_assignment : false_type {};932 933template <class _Tp>934struct __has_propagate_on_container_move_assignment<_Tp,935 __void_t<typename _Tp::propagate_on_container_move_assignment>>936 : true_type {};937 938template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>939struct __propagate_on_container_move_assignment940{941 typedef false_type type;942};943 944template <class _Alloc>945struct __propagate_on_container_move_assignment<_Alloc, true>946{947 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;948};949 950template <class _Tp, class = void>951struct __has_propagate_on_container_swap : false_type {};952 953template <class _Tp>954struct __has_propagate_on_container_swap<_Tp,955 __void_t<typename _Tp::propagate_on_container_swap>>956 : true_type {};957 958template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>959struct __propagate_on_container_swap960{961 typedef false_type type;962};963 964template <class _Alloc>965struct __propagate_on_container_swap<_Alloc, true>966{967 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;968};969 970template <class _Tp, class = void>971struct __has_is_always_equal : false_type {};972 973template <class _Tp>974struct __has_is_always_equal<_Tp,975 __void_t<typename _Tp::is_always_equal>>976 : true_type {};977 978template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>979struct __is_always_equal980{981 typedef _LIBCUDACXX_NODEBUG_TYPE typename _CUDA_VSTD::is_empty<_Alloc>::type type;982};983 984template <class _Alloc>985struct __is_always_equal<_Alloc, true>986{987 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::is_always_equal type;988};989 990template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>991struct __has_rebind_other992{993private:994 struct __two {char __lx; char __lxx;};995 template <class _Xp> static __two __test(...);996 template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);997public:998 static const bool value = sizeof(__test<_Tp>(0)) == 1;999};1000 1001template <class _Tp, class _Up>1002struct __has_rebind_other<_Tp, _Up, false>1003{1004 static const bool value = false;1005};1006 1007template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>1008struct __allocator_traits_rebind1009{1010 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;1011};1012 1013#ifndef _LIBCUDACXX_HAS_NO_VARIADICS1014 1015template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>1016struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>1017{1018 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;1019};1020 1021template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>1022struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>1023{1024 typedef _LIBCUDACXX_NODEBUG_TYPE _Alloc<_Up, _Args...> type;1025};1026 1027#else // _LIBCUDACXX_HAS_NO_VARIADICS1028 1029template <template <class> class _Alloc, class _Tp, class _Up>1030struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>1031{1032 typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;1033};1034 1035template <template <class> class _Alloc, class _Tp, class _Up>1036struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>1037{1038 typedef _Alloc<_Up> type;1039};1040 1041template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>1042struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>1043{1044 typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;1045};1046 1047template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>1048struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>1049{1050 typedef _Alloc<_Up, _A0> type;1051};1052 1053template <template <class, class, class> class _Alloc, class _Tp, class _A0,1054 class _A1, class _Up>1055struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>1056{1057 typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;1058};1059 1060template <template <class, class, class> class _Alloc, class _Tp, class _A0,1061 class _A1, class _Up>1062struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>1063{1064 typedef _Alloc<_Up, _A0, _A1> type;1065};1066 1067template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,1068 class _A1, class _A2, class _Up>1069struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>1070{1071 typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;1072};1073 1074template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,1075 class _A1, class _A2, class _Up>1076struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>1077{1078 typedef _Alloc<_Up, _A0, _A1, _A2> type;1079};1080 1081#endif // _LIBCUDACXX_HAS_NO_VARIADICS1082 1083template <class _Alloc, class _SizeType, class _ConstVoidPtr>1084auto1085__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)1086 -> decltype((void)__a.allocate(__sz, __p), true_type());1087 1088template <class _Alloc, class _SizeType, class _ConstVoidPtr>1089auto1090__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)1091 -> false_type;1092 1093template <class _Alloc, class _SizeType, class _ConstVoidPtr>1094struct __has_allocate_hint1095 : integral_constant<bool,1096 is_same<1097 decltype(_CUDA_VSTD::__has_allocate_hint_test(declval<_Alloc>(),1098 declval<_SizeType>(),1099 declval<_ConstVoidPtr>())),1100 true_type>::value>1101{1102};1103 1104template <class _Alloc, class _Tp, class ..._Args>1105decltype(_CUDA_VSTD::declval<_Alloc>().construct(_CUDA_VSTD::declval<_Tp*>(),1106 _CUDA_VSTD::declval<_Args>()...),1107 true_type())1108__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);1109 1110template <class _Alloc, class _Pointer, class ..._Args>1111false_type1112__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);1113 1114template <class _Alloc, class _Pointer, class ..._Args>1115struct __has_construct1116 : integral_constant<bool,1117 is_same<1118 decltype(_CUDA_VSTD::__has_construct_test(declval<_Alloc>(),1119 declval<_Pointer>(),1120 declval<_Args>()...)),1121 true_type>::value>1122{1123};1124 1125template <class _Alloc, class _Pointer>1126auto1127__has_destroy_test(_Alloc&& __a, _Pointer&& __p)1128 -> decltype(__a.destroy(__p), true_type());1129 1130template <class _Alloc, class _Pointer>1131auto1132__has_destroy_test(const _Alloc& __a, _Pointer&& __p)1133 -> false_type;1134 1135template <class _Alloc, class _Pointer>1136struct __has_destroy1137 : integral_constant<bool,1138 is_same<1139 decltype(_CUDA_VSTD::__has_destroy_test(declval<_Alloc>(),1140 declval<_Pointer>())),1141 true_type>::value>1142{1143};1144 1145template <class _Alloc>1146auto1147__has_max_size_test(_Alloc&& __a)1148 -> decltype(__a.max_size(), true_type());1149 1150template <class _Alloc>1151auto1152__has_max_size_test(const volatile _Alloc& __a)1153 -> false_type;1154 1155template <class _Alloc>1156struct __has_max_size1157 : integral_constant<bool,1158 is_same<1159 decltype(_CUDA_VSTD::__has_max_size_test(declval<_Alloc&>())),1160 true_type>::value>1161{1162};1163 1164template <class _Alloc>1165auto1166__has_select_on_container_copy_construction_test(_Alloc&& __a)1167 -> decltype(__a.select_on_container_copy_construction(), true_type());1168 1169template <class _Alloc>1170auto1171__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)1172 -> false_type;1173 1174template <class _Alloc>1175struct __has_select_on_container_copy_construction1176 : integral_constant<bool,1177 is_same<1178 decltype(_CUDA_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),1179 true_type>::value>1180{1181};1182 1183template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>1184struct __alloc_traits_difference_type1185{1186 typedef _LIBCUDACXX_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;1187};1188 1189template <class _Alloc, class _Ptr>1190struct __alloc_traits_difference_type<_Alloc, _Ptr, true>1191{1192 typedef _LIBCUDACXX_NODEBUG_TYPE typename _Alloc::difference_type type;1193};1194 1195template <class _Tp>1196struct __is_default_allocator : false_type {};1197 1198template <class _Tp>1199struct __is_default_allocator<_CUDA_VSTD::allocator<_Tp> > : true_type {};1200 