Advertisement
Kagalive

Untitled

Sep 30th, 2020
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.31 KB | None | 0 0
  1.  c
  2. Standard library header <vector>
  3.  C++ Standard Library headers
  4. This header is part of the containers library.
  5.  
  6. Includes
  7. <compare>
  8.  
  9. (C++20)
  10.  
  11. Three-way comparison operator support
  12. <initializer_list>
  13.  
  14. (C++11)
  15.  
  16. std::initializer_list class template
  17. Classes
  18. vector
  19.  
  20. dynamic contiguous array
  21. (class template)
  22. vector<bool>
  23.  
  24. space-efficient dynamic bitset
  25. (class template specialization)
  26. std::hash<std::vector<bool>>
  27.  
  28. (C++11)
  29.  
  30. hash support for std::vector<bool>
  31. (class template specialization)
  32. Forward declarations
  33. Defined in header <functional>
  34. hash
  35.  
  36. (C++11)
  37.  
  38. hash function object
  39. (class template)
  40. Functions
  41. operator==
  42. operator!=
  43. operator<
  44. operator<=
  45. operator>
  46. operator>=
  47. operator<=>
  48.  
  49. (removed in C++20)
  50. (removed in C++20)
  51. (removed in C++20)
  52. (removed in C++20)
  53. (removed in C++20)
  54. (C++20)
  55.  
  56. lexicographically compares the values in the vector
  57. (function template)
  58. std::swap(std::vector)
  59.  
  60. specializes the std::swap algorithm
  61. (function template)
  62. erase(std::vector)
  63. erase_if(std::vector)
  64.  
  65. (C++20)
  66.  
  67. Erases all elements satisfying specific criteria
  68. (function template)
  69. Range access
  70. begin
  71. cbegin
  72.  
  73. (C++11)
  74. (C++14)
  75.  
  76. returns an iterator to the beginning of a container or array
  77. (function template)
  78. end
  79. cend
  80.  
  81. (C++11)
  82. (C++14)
  83.  
  84. returns an iterator to the end of a container or array
  85. (function template)
  86. rbegin
  87. crbegin
  88.  
  89. (C++14)
  90.  
  91. returns a reverse iterator to a container or array
  92. (function template)
  93. rend
  94. crend
  95.  
  96. (C++14)
  97.  
  98. returns a reverse end iterator for a container or array
  99. (function template)
  100. size
  101. ssize
  102.  
  103. (C++17)
  104. (C++20)
  105.  
  106. returns the size of a container or array
  107. (function template)
  108. empty
  109.  
  110. (C++17)
  111.  
  112. checks whether the container is empty
  113. (function template)
  114. data
  115.  
  116. (C++17)
  117.  
  118. obtains the pointer to the underlying array
  119. (function template)
  120. Synopsis
  121. #include <compare>
  122. #include <initializer_list>
  123.  
  124. namespace std {
  125.   // class template vector
  126.   template<class T, class Allocator = allocator<T>> class vector;
  127.  
  128.   template<class T, class Allocator>
  129.     constexpr bool operator==(const vector<T, Allocator>& x,
  130.                               const vector<T, Allocator>& y);
  131.   template<class T, class Allocator>
  132.     constexpr /*synth-three-way-result*/<T> operator<=>(const vector<T, Allocator>& x,
  133.                                                         const vector<T, Allocator>& y);
  134.  
  135.   template<class T, class Allocator>
  136.     constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
  137.       noexcept(noexcept(x.swap(y)));
  138.  
  139.   template<class T, class Allocator, class U>
  140.     constexpr typename vector<T, Allocator>::size_type
  141.       erase(vector<T, Allocator>& c, const U& value);
  142.   template<class T, class Allocator, class Predicate>
  143.     constexpr typename vector<T, Allocator>::size_type
  144.       erase_if(vector<T, Allocator>& c, Predicate pred);
  145.  
  146.   // class vector<bool>
  147.   template<class Allocator> class vector<bool, Allocator>;
  148.  
  149.   // hash support
  150.   template<class T> struct hash;
  151.   template<class Allocator> struct hash<vector<bool, Allocator>>;
  152.  
  153.   namespace pmr {
  154.     template<class T>
  155.       using vector = std::vector<T, polymorphic_allocator<T>>;
  156.   }
  157. }
  158. Class template std::vector
  159. namespace std {
  160.   template<class T, class Allocator = allocator<T>>
  161.   class vector {
  162.   public:
  163.     // types
  164.     using value_type             = T;
  165.     using allocator_type         = Allocator;
  166.     using pointer                = typename allocator_traits<Allocator>::pointer;
  167.     using const_pointer          = typename allocator_traits<Allocator>::const_pointer;
  168.     using reference              = value_type&;
  169.     using const_reference        = const value_type&;
  170.     using size_type              = /* implementation-defined */;
  171.     using difference_type        = /* implementation-defined */;
  172.     using iterator               = /* implementation-defined */;
  173.     using const_iterator         = /* implementation-defined */;
  174.     using reverse_iterator       = std::reverse_iterator<iterator>;
  175.     using const_reverse_iterator = std::reverse_iterator<const_iterator>;
  176.  
  177.     // construct/copy/destroy
  178.     constexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
  179.     constexpr explicit vector(const Allocator&) noexcept;
  180.     constexpr explicit vector(size_type n, const Allocator& = Allocator());
  181.     constexpr vector(size_type n, const T& value, const Allocator& = Allocator());
  182.     template<class InputIt>
  183.       constexpr vector(InputIt first, InputIt last, const Allocator& = Allocator());
  184.     constexpr vector(const vector& x);
  185.     constexpr vector(vector&&) noexcept;
  186.     constexpr vector(const vector&, const Allocator&);
  187.     constexpr vector(vector&&, const Allocator&);
  188.     constexpr vector(initializer_list<T>, const Allocator& = Allocator());
  189.     constexpr ~vector();
  190.     constexpr vector& operator=(const vector& x);
  191.     constexpr vector& operator=(vector&& x)
  192.       noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
  193.                allocator_traits<Allocator>::is_always_equal::value);
  194.     constexpr vector& operator=(initializer_list<T>);
  195.     template<class InputIt>
  196.       constexpr void assign(InputIt first, InputIt last);
  197.     constexpr void assign(size_type n, const T& u);
  198.     constexpr void assign(initializer_list<T>);
  199.     constexpr allocator_type get_allocator() const noexcept;
  200.  
  201.     // iterators
  202.     constexpr iterator               begin() noexcept;
  203.     constexpr const_iterator         begin() const noexcept;
  204.     constexpr iterator               end() noexcept;
  205.     constexpr const_iterator         end() const noexcept;
  206.     constexpr reverse_iterator       rbegin() noexcept;
  207.     constexpr const_reverse_iterator rbegin() const noexcept;
  208.     constexpr reverse_iterator       rend() noexcept;
  209.     constexpr const_reverse_iterator rend() const noexcept;
  210.  
  211.     constexpr const_iterator         cbegin() const noexcept;
  212.     constexpr const_iterator         cend() const noexcept;
  213.     constexpr const_reverse_iterator crbegin() const noexcept;
  214.     constexpr const_reverse_iterator crend() const noexcept;
  215.  
  216.     // capacity
  217.     [[nodiscard]] constexpr bool empty() const noexcept;
  218.     constexpr size_type size() const noexcept;
  219.     constexpr size_type max_size() const noexcept;
  220.     constexpr size_type capacity() const noexcept;
  221.     constexpr void      resize(size_type sz);
  222.     constexpr void      resize(size_type sz, const T& c);
  223.     constexpr void      reserve(size_type n);
  224.     constexpr void      shrink_to_fit();
  225.  
  226.     // element access
  227.     constexpr reference       operator[](size_type n);
  228.     constexpr const_reference operator[](size_type n) const;
  229.     constexpr const_reference at(size_type n) const;
  230.     constexpr reference       at(size_type n);
  231.     constexpr reference       front();
  232.     constexpr const_reference front() const;
  233.     constexpr reference       back();
  234.     constexpr const_reference back() const;
  235.  
  236.     // data access
  237.     constexpr T*       data() noexcept;
  238.     constexpr const T* data() const noexcept;
  239.  
  240.     // modifiers
  241.     template<class... Args> constexpr reference emplace_back(Args&&... args);
  242.     constexpr void push_back(const T& x);
  243.     constexpr void push_back(T&& x);
  244.     constexpr void pop_back();
  245.  
  246.     template<class... Args>
  247.       constexpr iterator emplace(const_iterator position, Args&&... args);
  248.     constexpr iterator insert(const_iterator position, const T& x);
  249.     constexpr iterator insert(const_iterator position, T&& x);
  250.     constexpr iterator insert(const_iterator position, size_type n, const T& x);
  251.     template<class InputIt>
  252.       constexpr iterator insert(const_iterator position,
  253.                                 InputIt first, InputIt last);
  254.     constexpr iterator insert(const_iterator position, initializer_list<T> il);
  255.     constexpr iterator erase(const_iterator position);
  256.     constexpr iterator erase(const_iterator first, const_iterator last);
  257.     constexpr void     swap(vector&)
  258.       noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
  259.                allocator_traits<Allocator>::is_always_equal::value);
  260.     constexpr void     clear() noexcept;
  261.   };
  262.  
  263.   template<class InputIt, class Allocator = allocator</*iter-value-type*/<InputIt>>>
  264.     vector(InputIt, InputIt, Allocator = Allocator())
  265.       -> vector</*iter-value-type*/<InputIt>, Allocator>;
  266.  
  267.   // swap
  268.   template<class T, class Allocator>
  269.     constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
  270.       noexcept(noexcept(x.swap(y)));
  271. }
  272. Class template std::vector's specialization for bool
  273. namespace std {
  274.  template<class Allocator>
  275.  class vector<bool, Allocator> {
  276.  public:
  277.    // types
  278.    using value_type             = bool;
  279.    using allocator_type         = Allocator;
  280.    using pointer                = /* implementation-defined */;
  281.    using const_pointer          = /* implementation-defined */;
  282.    using const_reference        = bool;
  283.    using size_type              = /* implementation-defined */;
  284.    using difference_type        = /* implementation-defined */;
  285.    using iterator               = /* implementation-defined */;
  286.    using const_iterator         = /* implementation-defined */;
  287.    using reverse_iterator       = std::reverse_iterator<iterator>;
  288.    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
  289.  
  290.    // bit reference
  291.    class reference {
  292.      friend class vector;
  293.      constexpr reference() noexcept;
  294.    public:
  295.      constexpr reference(const reference&) = default;
  296.      constexpr ~reference();
  297.      constexpr operator bool() const noexcept;
  298.      constexpr reference& operator=(const bool x) noexcept;
  299.      constexpr reference& operator=(const reference& x) noexcept;
  300.      constexpr void flip() noexcept;   // flips the bit
  301.    };
  302.  
  303.    // construct/copy/destroy
  304.    constexpr vector() : vector(Allocator()) { }
  305.    constexpr explicit vector(const Allocator&);
  306.    constexpr explicit vector(size_type n, const Allocator& = Allocator());
  307.    constexpr vector(size_type n, const bool& value, const Allocator& = Allocator());
  308.    template<class InputIt>
  309.      constexpr vector(InputIt first, InputIt last, const Allocator& = Allocator());
  310.    constexpr vector(const vector& x);
  311.    constexpr vector(vector&& x);
  312.    constexpr vector(const vector&, const Allocator&);
  313.    constexpr vector(vector&&, const Allocator&);
  314.    constexpr vector(initializer_list<bool>, const Allocator& = Allocator()));
  315.    constexpr ~vector();
  316.    constexpr vector& operator=(const vector& x);
  317.    constexpr vector& operator=(vector&& x);
  318.    constexpr vector& operator=(initializer_list<bool>);
  319.    template<class InputIt>
  320.      constexpr void assign(InputIt first, InputIt last);
  321.    constexpr void assign(size_type n, const bool& t);
  322.    constexpr void assign(initializer_list<bool>);
  323.    constexpr allocator_type get_allocator() const noexcept;
  324.  
  325.    // iterators
  326.    constexpr iterator               begin() noexcept;
  327.    constexpr const_iterator         begin() const noexcept;
  328.    constexpr iterator               end() noexcept;
  329.    constexpr const_iterator         end() const noexcept;
  330.    constexpr reverse_iterator       rbegin() noexcept;
  331.    constexpr const_reverse_iterator rbegin() const noexcept;
  332.    constexpr reverse_iterator       rend() noexcept;
  333.    constexpr const_reverse_iterator rend() const noexcept;
  334.  
  335.    constexpr const_iterator         cbegin() const noexcept;
  336.    constexpr const_iterator         cend() const noexcept;
  337.    constexpr const_reverse_iterator crbegin() const noexcept;
  338.    constexpr const_reverse_iterator crend() const noexcept;
  339.  
  340.    // capacity
  341.    [[nodiscard]] constexpr bool empty() const noexcept;
  342.    constexpr size_type size() const noexcept;
  343.    constexpr size_type max_size() const noexcept;
  344.    constexpr size_type capacity() const noexcept;
  345.    constexpr void      resize(size_type sz, bool c = false);
  346.    constexpr void      reserve(size_type n);
  347.    constexpr void      shrink_to_fit();
  348.  
  349.    // element access
  350.    constexpr reference       operator[](size_type n);
  351.    constexpr const_reference operator[](size_type n) const;
  352.    constexpr const_reference at(size_type n) const;
  353.    constexpr reference       at(size_type n);
  354.    constexpr reference       front();
  355.    constexpr const_reference front() const;
  356.    constexpr reference       back();
  357.    constexpr const_reference back() const;
  358.  
  359.    // modifiers
  360.    template<class... Args> constexpr reference emplace_back(Args&&... args);
  361.    constexpr void push_back(const bool& x);
  362.    constexpr void pop_back();
  363.    template<class... Args>
  364.      constexpr iterator emplace(const_iterator position, Args&&... args);
  365.    constexpr iterator insert(const_iterator position, const bool& x);
  366.    constexpr iterator insert(const_iterator position, size_type n, const bool& x);
  367.    template<class InputIt>
  368.      constexpr iterator insert(const_iterator position,
  369.                                InputIt first, InputIt last);
  370.    constexpr iterator insert(const_iterator position, initializer_list<bool> il);
  371.  
  372.    constexpr iterator erase(const_iterator position);
  373.    constexpr iterator erase(const_iterator first, const_iterator last);
  374.    constexpr void swap(vector&);
  375.    constexpr static void swap(reference x, reference y) noexcept;
  376.    constexpr void flip() noexcept;     // flips all bits
  377.    constexpr void clear() noexcept;
  378.  };
  379. }
  380.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement