From Jason Turner

[vector.bool]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1xq2kcmi/{from.md → to.md} +83 -20
tmp/tmp1xq2kcmi/{from.md → to.md} RENAMED
@@ -1,59 +1,69 @@
1
- ### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
2
 
3
- To optimize space allocation, a specialization of vector for `bool`
4
- elements is provided:
 
 
5
 
6
  ``` cpp
7
  namespace std {
8
  template<class Allocator>
9
  class vector<bool, Allocator> {
10
  public:
11
  // types
12
  using value_type = bool;
13
  using allocator_type = Allocator;
14
- using pointer = implementation-defined;
15
- using const_pointer = implementation-defined;
16
  using const_reference = bool;
17
- using size_type = implementation-defined; // see [container.requirements]
18
- using difference_type = implementation-defined; // see [container.requirements]
19
  using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
20
  using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
21
  using reverse_iterator = std::reverse_iterator<iterator>;
22
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
23
 
24
  // bit reference
25
  class reference {
26
  friend class vector;
27
  constexpr reference() noexcept;
 
28
  public:
29
  constexpr reference(const reference&) = default;
30
  constexpr ~reference();
31
  constexpr operator bool() const noexcept;
32
- constexpr reference& operator=(const bool x) noexcept;
33
  constexpr reference& operator=(const reference& x) noexcept;
 
34
  constexpr void flip() noexcept; // flips the bit
35
  };
36
 
37
  // construct/copy/destroy
38
- constexpr vector() : vector(Allocator()) { }
39
- constexpr explicit vector(const Allocator&);
40
  constexpr explicit vector(size_type n, const Allocator& = Allocator());
41
  constexpr vector(size_type n, const bool& value, const Allocator& = Allocator());
42
  template<class InputIterator>
43
  constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
 
 
44
  constexpr vector(const vector& x);
45
- constexpr vector(vector&& x);
46
- constexpr vector(const vector&, const Allocator&);
47
- constexpr vector(vector&&, const Allocator&);
48
- constexpr vector(initializer_list<bool>, const Allocator& = Allocator()));
49
  constexpr ~vector();
50
  constexpr vector& operator=(const vector& x);
51
- constexpr vector& operator=(vector&& x);
 
 
52
  constexpr vector& operator=(initializer_list<bool>);
53
  template<class InputIterator>
54
  constexpr void assign(InputIterator first, InputIterator last);
 
 
55
  constexpr void assign(size_type n, const bool& t);
56
  constexpr void assign(initializer_list<bool>);
57
  constexpr allocator_type get_allocator() const noexcept;
58
 
59
  // iterators
@@ -91,23 +101,29 @@ namespace std {
91
  constexpr const_reference back() const;
92
 
93
  // modifiers
94
  template<class... Args> constexpr reference emplace_back(Args&&... args);
95
  constexpr void push_back(const bool& x);
 
 
96
  constexpr void pop_back();
97
  template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
98
  constexpr iterator insert(const_iterator position, const bool& x);
99
  constexpr iterator insert(const_iterator position, size_type n, const bool& x);
100
  template<class InputIterator>
101
  constexpr iterator insert(const_iterator position,
102
  InputIterator first, InputIterator last);
 
 
103
  constexpr iterator insert(const_iterator position, initializer_list<bool> il);
104
 
105
  constexpr iterator erase(const_iterator position);
106
  constexpr iterator erase(const_iterator first, const_iterator last);
107
- constexpr void swap(vector&);
108
- constexpr static void swap(reference x, reference y) noexcept;
 
 
109
  constexpr void flip() noexcept; // flips all bits
110
  constexpr void clear() noexcept;
111
  };
112
  }
113
  ```
@@ -124,22 +140,22 @@ recommended instead.
124
 
125
  `reference`
126
 
127
  is a class that simulates the behavior of references of a single bit in
128
  `vector<bool>`. The conversion function returns `true` when the bit is
129
- set, and `false` otherwise. The assignment operator sets the bit when
130
- the argument is (convertible to) `true` and clears it otherwise. `flip`
131
  reverses the state of the bit.
132
 
133
  ``` cpp
134
  constexpr void flip() noexcept;
135
  ```
136
 
137
  *Effects:* Replaces each element in the container with its complement.
138
 
139
  ``` cpp
140
- constexpr static void swap(reference x, reference y) noexcept;
141
  ```
142
 
143
  *Effects:* Exchanges the contents of `x` and `y` as if by:
144
 
145
  ``` cpp
@@ -152,5 +168,52 @@ y = b;
152
  template<class Allocator> struct hash<vector<bool, Allocator>>;
153
  ```
154
 
155
  The specialization is enabled [[unord.hash]].
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Specialization of `vector` for `bool` <a id="vector.bool">[[vector.bool]]</a>
2
 
3
+ #### Partial class template specialization `vector<bool, Allocator>` <a id="vector.bool.pspc">[[vector.bool.pspc]]</a>
4
+
5
+ To optimize space allocation, a partial specialization of `vector` for
6
+ `bool` elements is provided:
7
 
8
  ``` cpp
9
  namespace std {
10
  template<class Allocator>
11
  class vector<bool, Allocator> {
12
  public:
13
  // types
14
  using value_type = bool;
15
  using allocator_type = Allocator;
16
+ using pointer = implementation-defined // type of vector<bool>::pointer;
17
+ using const_pointer = implementation-defined // type of vector<bool>::const_pointer;
18
  using const_reference = bool;
19
+ using size_type = implementation-defined // type of vector<bool>::size_type; // see [container.requirements]
20
+ using difference_type = implementation-defined // type of vector<bool>::difference_type; // see [container.requirements]
21
  using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
22
  using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
23
  using reverse_iterator = std::reverse_iterator<iterator>;
24
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
25
 
26
  // bit reference
27
  class reference {
28
  friend class vector;
29
  constexpr reference() noexcept;
30
+
31
  public:
32
  constexpr reference(const reference&) = default;
33
  constexpr ~reference();
34
  constexpr operator bool() const noexcept;
35
+ constexpr reference& operator=(bool x) noexcept;
36
  constexpr reference& operator=(const reference& x) noexcept;
37
+ constexpr const reference& operator=(bool x) const noexcept;
38
  constexpr void flip() noexcept; // flips the bit
39
  };
40
 
41
  // construct/copy/destroy
42
+ constexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
43
+ constexpr explicit vector(const Allocator&) noexcept;
44
  constexpr explicit vector(size_type n, const Allocator& = Allocator());
45
  constexpr vector(size_type n, const bool& value, const Allocator& = Allocator());
46
  template<class InputIterator>
47
  constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
48
+ template<container-compatible-range<bool> R>
49
+ constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
50
  constexpr vector(const vector& x);
51
+ constexpr vector(vector&& x) noexcept;
52
+ constexpr vector(const vector&, const type_identity_t<Allocator>&);
53
+ constexpr vector(vector&&, const type_identity_t<Allocator>&);
54
+ constexpr vector(initializer_list<bool>, const Allocator& = Allocator());
55
  constexpr ~vector();
56
  constexpr vector& operator=(const vector& x);
57
+ constexpr vector& operator=(vector&& x)
58
+ noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
59
+ allocator_traits<Allocator>::is_always_equal::value);
60
  constexpr vector& operator=(initializer_list<bool>);
61
  template<class InputIterator>
62
  constexpr void assign(InputIterator first, InputIterator last);
63
+ template<container-compatible-range<bool> R>
64
+ constexpr void assign_range(R&& rg);
65
  constexpr void assign(size_type n, const bool& t);
66
  constexpr void assign(initializer_list<bool>);
67
  constexpr allocator_type get_allocator() const noexcept;
68
 
69
  // iterators
 
101
  constexpr const_reference back() const;
102
 
103
  // modifiers
104
  template<class... Args> constexpr reference emplace_back(Args&&... args);
105
  constexpr void push_back(const bool& x);
106
+ template<container-compatible-range<bool> R>
107
+ constexpr void append_range(R&& rg);
108
  constexpr void pop_back();
109
  template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
110
  constexpr iterator insert(const_iterator position, const bool& x);
111
  constexpr iterator insert(const_iterator position, size_type n, const bool& x);
112
  template<class InputIterator>
113
  constexpr iterator insert(const_iterator position,
114
  InputIterator first, InputIterator last);
115
+ template<container-compatible-range<bool> R>
116
+ constexpr iterator insert_range(const_iterator position, R&& rg);
117
  constexpr iterator insert(const_iterator position, initializer_list<bool> il);
118
 
119
  constexpr iterator erase(const_iterator position);
120
  constexpr iterator erase(const_iterator first, const_iterator last);
121
+ constexpr void swap(vector&)
122
+ noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
123
+ allocator_traits<Allocator>::is_always_equal::value);
124
+ static constexpr void swap(reference x, reference y) noexcept;
125
  constexpr void flip() noexcept; // flips all bits
126
  constexpr void clear() noexcept;
127
  };
128
  }
129
  ```
 
140
 
141
  `reference`
142
 
143
  is a class that simulates the behavior of references of a single bit in
144
  `vector<bool>`. The conversion function returns `true` when the bit is
145
+ set, and `false` otherwise. The assignment operators set the bit when
146
+ the argument is (convertible to) `true` and clear it otherwise. `flip`
147
  reverses the state of the bit.
148
 
149
  ``` cpp
150
  constexpr void flip() noexcept;
151
  ```
152
 
153
  *Effects:* Replaces each element in the container with its complement.
154
 
155
  ``` cpp
156
+ static constexpr void swap(reference x, reference y) noexcept;
157
  ```
158
 
159
  *Effects:* Exchanges the contents of `x` and `y` as if by:
160
 
161
  ``` cpp
 
168
  template<class Allocator> struct hash<vector<bool, Allocator>>;
169
  ```
170
 
171
  The specialization is enabled [[unord.hash]].
172
 
173
+ ``` cpp
174
+ template<class T>
175
+ constexpr bool is-vector-bool-reference = see below;
176
+ ```
177
+
178
+ The expression *`is-vector-bool-reference`*`<T>` is `true` if `T`
179
+ denotes the type `vector<bool, Alloc>::reference` for some type `Alloc`
180
+ and `vector<bool, Alloc>` is not a program-defined specialization.
181
+
182
+ #### Formatter specialization for `vector<bool>` <a id="vector.bool.fmt">[[vector.bool.fmt]]</a>
183
+
184
+ ``` cpp
185
+ namespace std {
186
+ template<class T, class charT>
187
+ requires is-vector-bool-reference<T>
188
+ struct formatter<T, charT> {
189
+ private:
190
+ formatter<bool, charT> underlying_; // exposition only
191
+
192
+ public:
193
+ template<class ParseContext>
194
+ constexpr typename ParseContext::iterator
195
+ parse(ParseContext& ctx);
196
+
197
+ template<class FormatContext>
198
+ typename FormatContext::iterator
199
+ format(const T& ref, FormatContext& ctx) const;
200
+ };
201
+ }
202
+ ```
203
+
204
+ ``` cpp
205
+ template<class ParseContext>
206
+ constexpr typename ParseContext::iterator
207
+ parse(ParseContext& ctx);
208
+ ```
209
+
210
+ Equivalent to: `return `*`underlying_`*`.parse(ctx);`
211
+
212
+ ``` cpp
213
+ template<class FormatContext>
214
+ typename FormatContext::iterator
215
+ format(const T& ref, FormatContext& ctx) const;
216
+ ```
217
+
218
+ Equivalent to: `return `*`underlying_`*`.format(ref, ctx);`
219
+