From Jason Turner

[template.bitset]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmplee1cml0/{from.md → to.md} +18 -122
tmp/tmplee1cml0/{from.md → to.md} RENAMED
@@ -1,34 +1,6 @@
1
- ## Class template `bitset` <a id="template.bitset">[[template.bitset]]</a>
2
-
3
- \synopsis{Header \texttt{\<bitset\>} synopsis}
4
-
5
- ``` cpp
6
- #include <string>
7
- #include <iosfwd> // for istream, ostream
8
- namespace std {
9
- template <size_t N> class bitset;
10
-
11
- // [bitset.operators] bitset operators:
12
- template <size_t N>
13
- bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
14
- template <size_t N>
15
- bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
16
- template <size_t N>
17
- bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
18
- template <class charT, class traits, size_t N>
19
- basic_istream<charT, traits>&
20
- operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
21
- template <class charT, class traits, size_t N>
22
- basic_ostream<charT, traits>&
23
- operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
24
- }
25
- ```
26
-
27
- The header `<bitset>` defines a class template and several related
28
- functions for representing and manipulating fixed-size sequences of
29
- bits.
30
 
31
  ``` cpp
32
  namespace std {
33
  template<size_t N> class bitset {
34
  public:
@@ -43,27 +15,29 @@ namespace std {
43
  bool operator~() const noexcept; // flips the bit
44
  operator bool() const noexcept; // for x = b[i];
45
  reference& flip() noexcept; // for b[i].flip();
46
  };
47
 
48
- // [bitset.cons] constructors:
49
  constexpr bitset() noexcept;
50
  constexpr bitset(unsigned long long val) noexcept;
51
  template<class charT, class traits, class Allocator>
52
  explicit bitset(
53
  const basic_string<charT, traits, Allocator>& str,
54
  typename basic_string<charT, traits, Allocator>::size_type pos = 0,
55
  typename basic_string<charT, traits, Allocator>::size_type n =
56
  basic_string<charT, traits, Allocator>::npos,
57
- charT zero = charT('0'), charT one = charT('1'));
 
58
  template <class charT>
59
  explicit bitset(
60
  const charT* str,
61
  typename basic_string<charT>::size_type n = basic_string<charT>::npos,
62
- charT zero = charT('0'), charT one = charT('1'));
 
63
 
64
- // [bitset.members] bitset operations:
65
  bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
66
  bitset<N>& operator|=(const bitset<N>& rhs) noexcept;
67
  bitset<N>& operator^=(const bitset<N>& rhs) noexcept;
68
  bitset<N>& operator<<=(size_t pos) noexcept;
69
  bitset<N>& operator>>=(size_t pos) noexcept;
@@ -84,10 +58,11 @@ namespace std {
84
  template <class charT = char,
85
  class traits = char_traits<charT>,
86
  class Allocator = allocator<charT>>
87
  basic_string<charT, traits, Allocator>
88
  to_string(charT zero = charT('0'), charT one = charT('1')) const;
 
89
  size_t count() const noexcept;
90
  constexpr size_t size() const noexcept;
91
  bool operator==(const bitset<N>& rhs) const noexcept;
92
  bool operator!=(const bitset<N>& rhs) const noexcept;
93
  bool test(size_t pos) const;
@@ -96,11 +71,11 @@ namespace std {
96
  bool none() const noexcept;
97
  bitset<N> operator<<(size_t pos) const noexcept;
98
  bitset<N> operator>>(size_t pos) const noexcept;
99
  };
100
 
101
- // [bitset.hash] hash support
102
  template <class T> struct hash;
103
  template <size_t N> struct hash<bitset<N>>;
104
  }
105
  ```
106
 
@@ -123,11 +98,11 @@ errors, each associated with a distinct exception:
123
  - an *out-of-range* error is associated with exceptions of type
124
  `out_of_range` ([[out.of.range]]);
125
  - an *overflow* error is associated with exceptions of type
126
  `overflow_error` ([[overflow.error]]).
127
 
128
- ### `bitset` constructors <a id="bitset.cons">[[bitset.cons]]</a>
129
 
130
  ``` cpp
131
  constexpr bitset() noexcept;
132
  ```
133
 
@@ -152,13 +127,12 @@ bitset(const basic_string<charT, traits, Allocator>& str,
152
  typename basic_string<charT, traits, Allocator>::size_type n =
153
  basic_string<charT, traits, Allocator>::npos,
154
  charT zero = charT('0'), charT one = charT('1'));
155
  ```
156
 
157
- *Requires:* `pos <= str.size()`.
158
-
159
- *Throws:* `out_of_range` if `pos > str.size()`.
160
 
161
  *Effects:* Determines the effective length `rlen` of the initializing
162
  string as the smaller of `n` and `str.size() - pos`.
163
 
164
  The function then throws
@@ -186,21 +160,21 @@ template <class charT>
186
  const charT* str,
187
  typename basic_string<charT>::size_type n = basic_string<charT>::npos,
188
  charT zero = charT('0'), charT one = charT('1'));
189
  ```
190
 
191
- *Effects:* Constructs an object of class `bitset<N>` as if by
192
 
193
  ``` cpp
194
  bitset(
195
  n == basic_string<charT>::npos
196
  ? basic_string<charT>(str)
197
  : basic_string<charT>(str, n),
198
  0, n, zero, one)
199
  ```
200
 
201
- ### `bitset` members <a id="bitset.members">[[bitset.members]]</a>
202
 
203
  ``` cpp
204
  bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
205
  ```
206
 
@@ -263,12 +237,10 @@ bitset<N>& set() noexcept;
263
 
264
  ``` cpp
265
  bitset<N>& set(size_t pos, bool val = true);
266
  ```
267
 
268
- *Requires:* `pos` is valid
269
-
270
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
271
  position.
272
 
273
  *Effects:* Stores a new value in the bit at position `pos` in `*this`.
274
  If `val` is nonzero, the stored value is one, otherwise it is zero.
@@ -285,12 +257,10 @@ bitset<N>& reset() noexcept;
285
 
286
  ``` cpp
287
  bitset<N>& reset(size_t pos);
288
  ```
289
 
290
- *Requires:* `pos` is valid
291
-
292
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
293
  position.
294
 
295
  *Effects:* Resets the bit at position `pos` in `*this`.
296
 
@@ -315,12 +285,10 @@ bitset<N>& flip() noexcept;
315
 
316
  ``` cpp
317
  bitset<N>& flip(size_t pos);
318
  ```
319
 
320
- *Requires:* `pos` is valid
321
-
322
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
323
  position.
324
 
325
  *Effects:* Toggles the bit at position `pos` in `*this`.
326
 
@@ -391,35 +359,33 @@ bool operator!=(const bitset<N>& rhs) const noexcept;
391
 
392
  ``` cpp
393
  bool test(size_t pos) const;
394
  ```
395
 
396
- *Requires:* `pos` is valid
397
-
398
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
399
  position.
400
 
401
  *Returns:* `true` if the bit at position `pos` in `*this` has the value
402
  one.
403
 
404
  ``` cpp
405
  bool all() const noexcept;
406
  ```
407
 
408
- *Returns:* `count() == size()`
409
 
410
  ``` cpp
411
  bool any() const noexcept;
412
  ```
413
 
414
- *Returns:* `count() != 0`
415
 
416
  ``` cpp
417
  bool none() const noexcept;
418
  ```
419
 
420
- *Returns:* `count() == 0`
421
 
422
  ``` cpp
423
  bitset<N> operator<<(size_t pos) const noexcept;
424
  ```
425
 
@@ -452,80 +418,10 @@ bitset<N>::reference operator[](size_t pos);
452
  `(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
453
  equivalent to `this->set(pos, val)`.
454
 
455
  *Throws:* Nothing.
456
 
457
- For the purpose of determining the presence of a data
458
  race ([[intro.multithread]]), any access or update through the
459
  resulting reference potentially accesses or modifies, respectively, the
460
  entire underlying bitset.
461
 
462
- ### `bitset` hash support <a id="bitset.hash">[[bitset.hash]]</a>
463
-
464
- ``` cpp
465
- template <size_t N> struct hash<bitset<N> >;
466
- ```
467
-
468
- The template specialization shall meet the requirements of class
469
- template `hash` ([[unord.hash]]).
470
-
471
- ### `bitset` operators <a id="bitset.operators">[[bitset.operators]]</a>
472
-
473
- ``` cpp
474
- bitset<N> operator&(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
475
- ```
476
-
477
- *Returns:* `bitset<N>(lhs) &= rhs`.
478
-
479
- ``` cpp
480
- bitset<N> operator|(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
481
- ```
482
-
483
- *Returns:* `bitset<N>(lhs) |= rhs`.
484
-
485
- ``` cpp
486
- bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs) noexcept;
487
- ```
488
-
489
- *Returns:* `bitset<N>(lhs) ^= rhs`.
490
-
491
- ``` cpp
492
- template <class charT, class traits, size_t N>
493
- basic_istream<charT, traits>&
494
- operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
495
- ```
496
-
497
- A formatted input function ([[istream.formatted]]).
498
-
499
- *Effects:* Extracts up to `N` characters from `is`. Stores these
500
- characters in a temporary object `str` of type
501
- `basic_string<charT, traits>`, then evaluates the expression
502
- `x = bitset<N>(str)`. Characters are extracted and stored until any of
503
- the following occurs:
504
-
505
- - `N` characters have been extracted and stored;
506
- - end-of-file occurs on the input sequence;
507
- - the next input character is neither `is.widen(’0’)` nor
508
- `is.widen(’1’)` (in which case the input character is not extracted).
509
-
510
- If no characters are stored in `str`, calls
511
- `is.setstate(ios_base::failbit)` (which may throw
512
- `ios_base::failure` ([[iostate.flags]])).
513
-
514
- *Returns:* `is`.
515
-
516
- ``` cpp
517
- template <class charT, class traits, size_t N>
518
- basic_ostream<charT, traits>&
519
- operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
520
- ```
521
-
522
- *Returns:*
523
-
524
- ``` cpp
525
- os << x.template to_string<charT,traits,allocator<charT> >(
526
- use_facet<ctype<charT> >(os.getloc()).widen('0'),
527
- use_facet<ctype<charT> >(os.getloc()).widen('1'))
528
- ```
529
-
530
- (see  [[ostream.formatted]]).
531
-
 
1
+ ### Class template `bitset` <a id="template.bitset">[[template.bitset]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  ``` cpp
4
  namespace std {
5
  template<size_t N> class bitset {
6
  public:
 
15
  bool operator~() const noexcept; // flips the bit
16
  operator bool() const noexcept; // for x = b[i];
17
  reference& flip() noexcept; // for b[i].flip();
18
  };
19
 
20
+ // [bitset.cons], constructors
21
  constexpr bitset() noexcept;
22
  constexpr bitset(unsigned long long val) noexcept;
23
  template<class charT, class traits, class Allocator>
24
  explicit bitset(
25
  const basic_string<charT, traits, Allocator>& str,
26
  typename basic_string<charT, traits, Allocator>::size_type pos = 0,
27
  typename basic_string<charT, traits, Allocator>::size_type n =
28
  basic_string<charT, traits, Allocator>::npos,
29
+ charT zero = charT('0'),
30
+ charT one = charT('1'));
31
  template <class charT>
32
  explicit bitset(
33
  const charT* str,
34
  typename basic_string<charT>::size_type n = basic_string<charT>::npos,
35
+ charT zero = charT('0'),
36
+ charT one = charT('1'));
37
 
38
+ // [bitset.members], bitset operations
39
  bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
40
  bitset<N>& operator|=(const bitset<N>& rhs) noexcept;
41
  bitset<N>& operator^=(const bitset<N>& rhs) noexcept;
42
  bitset<N>& operator<<=(size_t pos) noexcept;
43
  bitset<N>& operator>>=(size_t pos) noexcept;
 
58
  template <class charT = char,
59
  class traits = char_traits<charT>,
60
  class Allocator = allocator<charT>>
61
  basic_string<charT, traits, Allocator>
62
  to_string(charT zero = charT('0'), charT one = charT('1')) const;
63
+
64
  size_t count() const noexcept;
65
  constexpr size_t size() const noexcept;
66
  bool operator==(const bitset<N>& rhs) const noexcept;
67
  bool operator!=(const bitset<N>& rhs) const noexcept;
68
  bool test(size_t pos) const;
 
71
  bool none() const noexcept;
72
  bitset<N> operator<<(size_t pos) const noexcept;
73
  bitset<N> operator>>(size_t pos) const noexcept;
74
  };
75
 
76
+ // [bitset.hash], hash support
77
  template <class T> struct hash;
78
  template <size_t N> struct hash<bitset<N>>;
79
  }
80
  ```
81
 
 
98
  - an *out-of-range* error is associated with exceptions of type
99
  `out_of_range` ([[out.of.range]]);
100
  - an *overflow* error is associated with exceptions of type
101
  `overflow_error` ([[overflow.error]]).
102
 
103
+ #### `bitset` constructors <a id="bitset.cons">[[bitset.cons]]</a>
104
 
105
  ``` cpp
106
  constexpr bitset() noexcept;
107
  ```
108
 
 
127
  typename basic_string<charT, traits, Allocator>::size_type n =
128
  basic_string<charT, traits, Allocator>::npos,
129
  charT zero = charT('0'), charT one = charT('1'));
130
  ```
131
 
132
+ *Throws:* `out_of_range` if `pos > str.size()` or `invalid_argument` if
133
+ an invalid character is found (see below).
 
134
 
135
  *Effects:* Determines the effective length `rlen` of the initializing
136
  string as the smaller of `n` and `str.size() - pos`.
137
 
138
  The function then throws
 
160
  const charT* str,
161
  typename basic_string<charT>::size_type n = basic_string<charT>::npos,
162
  charT zero = charT('0'), charT one = charT('1'));
163
  ```
164
 
165
+ *Effects:* Constructs an object of class `bitset<N>` as if by:
166
 
167
  ``` cpp
168
  bitset(
169
  n == basic_string<charT>::npos
170
  ? basic_string<charT>(str)
171
  : basic_string<charT>(str, n),
172
  0, n, zero, one)
173
  ```
174
 
175
+ #### `bitset` members <a id="bitset.members">[[bitset.members]]</a>
176
 
177
  ``` cpp
178
  bitset<N>& operator&=(const bitset<N>& rhs) noexcept;
179
  ```
180
 
 
237
 
238
  ``` cpp
239
  bitset<N>& set(size_t pos, bool val = true);
240
  ```
241
 
 
 
242
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
243
  position.
244
 
245
  *Effects:* Stores a new value in the bit at position `pos` in `*this`.
246
  If `val` is nonzero, the stored value is one, otherwise it is zero.
 
257
 
258
  ``` cpp
259
  bitset<N>& reset(size_t pos);
260
  ```
261
 
 
 
262
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
263
  position.
264
 
265
  *Effects:* Resets the bit at position `pos` in `*this`.
266
 
 
285
 
286
  ``` cpp
287
  bitset<N>& flip(size_t pos);
288
  ```
289
 
 
 
290
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
291
  position.
292
 
293
  *Effects:* Toggles the bit at position `pos` in `*this`.
294
 
 
359
 
360
  ``` cpp
361
  bool test(size_t pos) const;
362
  ```
363
 
 
 
364
  *Throws:* `out_of_range` if `pos` does not correspond to a valid bit
365
  position.
366
 
367
  *Returns:* `true` if the bit at position `pos` in `*this` has the value
368
  one.
369
 
370
  ``` cpp
371
  bool all() const noexcept;
372
  ```
373
 
374
+ *Returns:* `count() == size()`.
375
 
376
  ``` cpp
377
  bool any() const noexcept;
378
  ```
379
 
380
+ *Returns:* `count() != 0`.
381
 
382
  ``` cpp
383
  bool none() const noexcept;
384
  ```
385
 
386
+ *Returns:* `count() == 0`.
387
 
388
  ``` cpp
389
  bitset<N> operator<<(size_t pos) const noexcept;
390
  ```
391
 
 
418
  `(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
419
  equivalent to `this->set(pos, val)`.
420
 
421
  *Throws:* Nothing.
422
 
423
+ *Remarks:* For the purpose of determining the presence of a data
424
  race ([[intro.multithread]]), any access or update through the
425
  resulting reference potentially accesses or modifies, respectively, the
426
  entire underlying bitset.
427