- tmp/tmp3wu7qryj/{from.md → to.md} +107 -103
tmp/tmp3wu7qryj/{from.md → to.md}
RENAMED
|
@@ -1,79 +1,82 @@
|
|
| 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:
|
| 7 |
// bit reference
|
| 8 |
class reference {
|
| 9 |
friend class bitset;
|
| 10 |
-
reference() noexcept;
|
| 11 |
|
| 12 |
public:
|
| 13 |
-
reference(const reference&) = default;
|
| 14 |
-
~reference();
|
| 15 |
-
reference& operator=(bool x) noexcept;
|
| 16 |
-
reference& operator=(const reference&) noexcept;
|
| 17 |
-
bool operator~() const noexcept;
|
| 18 |
-
operator bool() const noexcept;
|
| 19 |
-
reference& flip() noexcept;
|
| 20 |
};
|
| 21 |
|
| 22 |
// [bitset.cons], constructors
|
| 23 |
constexpr bitset() noexcept;
|
| 24 |
constexpr bitset(unsigned long long val) noexcept;
|
| 25 |
template<class charT, class traits, class Allocator>
|
| 26 |
-
explicit bitset(
|
| 27 |
const basic_string<charT, traits, Allocator>& str,
|
| 28 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 29 |
typename basic_string<charT, traits, Allocator>::size_type n
|
| 30 |
= basic_string<charT, traits, Allocator>::npos,
|
| 31 |
charT zero = charT('0'),
|
| 32 |
charT one = charT('1'));
|
| 33 |
template<class charT>
|
| 34 |
-
explicit bitset(
|
| 35 |
const charT* str,
|
| 36 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 37 |
charT zero = charT('0'),
|
| 38 |
charT one = charT('1'));
|
| 39 |
|
| 40 |
// [bitset.members], bitset operations
|
| 41 |
-
bitset
|
| 42 |
-
bitset
|
| 43 |
-
bitset
|
| 44 |
-
bitset
|
| 45 |
-
bitset
|
| 46 |
-
bitset<
|
| 47 |
-
bitset
|
| 48 |
-
bitset
|
| 49 |
-
bitset
|
| 50 |
-
bitset
|
| 51 |
-
bitset
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
// element access
|
| 55 |
-
constexpr bool operator[](size_t pos) const;
|
| 56 |
-
reference operator[](size_t pos);
|
| 57 |
|
| 58 |
-
unsigned long to_ulong() const;
|
| 59 |
-
unsigned long long to_ullong() const;
|
| 60 |
template<class charT = char,
|
| 61 |
class traits = char_traits<charT>,
|
| 62 |
class Allocator = allocator<charT>>
|
| 63 |
-
basic_string<charT, traits, Allocator>
|
| 64 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 65 |
|
| 66 |
-
|
|
|
|
| 67 |
constexpr size_t size() const noexcept;
|
| 68 |
-
bool operator==(const bitset
|
| 69 |
-
bool test(size_t pos) const;
|
| 70 |
-
bool all() const noexcept;
|
| 71 |
-
bool any() const noexcept;
|
| 72 |
-
bool none() const noexcept;
|
| 73 |
-
bitset<N> operator<<(size_t pos) const noexcept;
|
| 74 |
-
bitset<N> operator>>(size_t pos) const noexcept;
|
| 75 |
};
|
| 76 |
|
| 77 |
// [bitset.hash], hash support
|
| 78 |
template<class T> struct hash;
|
| 79 |
template<size_t N> struct hash<bitset<N>>;
|
|
@@ -89,11 +92,11 @@ zero. Each bit has a non-negative position `pos`. When converting
|
|
| 89 |
between an object of class `bitset<N>` and a value of some integral
|
| 90 |
type, bit position `pos` corresponds to the *bit value* `1 << pos`. The
|
| 91 |
integral value corresponding to two or more bits is the sum of their bit
|
| 92 |
values.
|
| 93 |
|
| 94 |
-
The functions described in
|
| 95 |
errors, each associated with a distinct exception:
|
| 96 |
|
| 97 |
- an *invalid-argument* error is associated with exceptions of type
|
| 98 |
`invalid_argument` [[invalid.argument]];
|
| 99 |
- an *out-of-range* error is associated with exceptions of type
|
|
@@ -113,16 +116,17 @@ constexpr bitset() noexcept;
|
|
| 113 |
constexpr bitset(unsigned long long val) noexcept;
|
| 114 |
```
|
| 115 |
|
| 116 |
*Effects:* Initializes the first `M` bit positions to the corresponding
|
| 117 |
bit values in `val`. `M` is the smaller of `N` and the number of bits in
|
| 118 |
-
the value representation [[
|
| 119 |
-
`M < N`, the remaining bit positions are
|
|
|
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
template<class charT, class traits, class Allocator>
|
| 123 |
-
explicit bitset(
|
| 124 |
const basic_string<charT, traits, Allocator>& str,
|
| 125 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 126 |
typename basic_string<charT, traits, Allocator>::size_type n
|
| 127 |
= basic_string<charT, traits, Allocator>::npos,
|
| 128 |
charT zero = charT('0'),
|
|
@@ -148,11 +152,11 @@ The function uses `traits::eq` to compare the character values.
|
|
| 148 |
any of the `rlen` characters in `str` beginning at position `pos` is
|
| 149 |
other than `zero` or `one`.
|
| 150 |
|
| 151 |
``` cpp
|
| 152 |
template<class charT>
|
| 153 |
-
explicit bitset(
|
| 154 |
const charT* str,
|
| 155 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 156 |
charT zero = charT('0'),
|
| 157 |
charT one = charT('1'));
|
| 158 |
```
|
|
@@ -167,38 +171,38 @@ bitset(n == basic_string<charT>::npos
|
|
| 167 |
```
|
| 168 |
|
| 169 |
#### Members <a id="bitset.members">[[bitset.members]]</a>
|
| 170 |
|
| 171 |
``` cpp
|
| 172 |
-
bitset
|
| 173 |
```
|
| 174 |
|
| 175 |
*Effects:* Clears each bit in `*this` for which the corresponding bit in
|
| 176 |
`rhs` is clear, and leaves all other bits unchanged.
|
| 177 |
|
| 178 |
*Returns:* `*this`.
|
| 179 |
|
| 180 |
``` cpp
|
| 181 |
-
bitset
|
| 182 |
```
|
| 183 |
|
| 184 |
*Effects:* Sets each bit in `*this` for which the corresponding bit in
|
| 185 |
`rhs` is set, and leaves all other bits unchanged.
|
| 186 |
|
| 187 |
*Returns:* `*this`.
|
| 188 |
|
| 189 |
``` cpp
|
| 190 |
-
bitset
|
| 191 |
```
|
| 192 |
|
| 193 |
*Effects:* Toggles each bit in `*this` for which the corresponding bit
|
| 194 |
in `rhs` is set, and leaves all other bits unchanged.
|
| 195 |
|
| 196 |
*Returns:* `*this`.
|
| 197 |
|
| 198 |
``` cpp
|
| 199 |
-
bitset
|
| 200 |
```
|
| 201 |
|
| 202 |
*Effects:* Replaces each bit at position `I` in `*this` with a value
|
| 203 |
determined as follows:
|
| 204 |
|
|
@@ -207,11 +211,11 @@ determined as follows:
|
|
| 207 |
position `I - pos`.
|
| 208 |
|
| 209 |
*Returns:* `*this`.
|
| 210 |
|
| 211 |
``` cpp
|
| 212 |
-
bitset
|
| 213 |
```
|
| 214 |
|
| 215 |
*Effects:* Replaces each bit at position `I` in `*this` with a value
|
| 216 |
determined as follows:
|
| 217 |
|
|
@@ -220,19 +224,31 @@ determined as follows:
|
|
| 220 |
position `I + pos`.
|
| 221 |
|
| 222 |
*Returns:* `*this`.
|
| 223 |
|
| 224 |
``` cpp
|
| 225 |
-
bitset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
```
|
| 227 |
|
| 228 |
*Effects:* Sets all bits in `*this`.
|
| 229 |
|
| 230 |
*Returns:* `*this`.
|
| 231 |
|
| 232 |
``` cpp
|
| 233 |
-
bitset
|
| 234 |
```
|
| 235 |
|
| 236 |
*Effects:* Stores a new value in the bit at position `pos` in `*this`.
|
| 237 |
If `val` is `true`, the stored value is one, otherwise it is zero.
|
| 238 |
|
|
@@ -240,67 +256,95 @@ If `val` is `true`, the stored value is one, otherwise it is zero.
|
|
| 240 |
|
| 241 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 242 |
position.
|
| 243 |
|
| 244 |
``` cpp
|
| 245 |
-
bitset
|
| 246 |
```
|
| 247 |
|
| 248 |
*Effects:* Resets all bits in `*this`.
|
| 249 |
|
| 250 |
*Returns:* `*this`.
|
| 251 |
|
| 252 |
``` cpp
|
| 253 |
-
bitset
|
| 254 |
```
|
| 255 |
|
| 256 |
*Effects:* Resets the bit at position `pos` in `*this`.
|
| 257 |
|
| 258 |
*Returns:* `*this`.
|
| 259 |
|
| 260 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 261 |
position.
|
| 262 |
|
| 263 |
``` cpp
|
| 264 |
-
bitset
|
| 265 |
```
|
| 266 |
|
| 267 |
-
*Effects:* Constructs an object `x` of class `bitset
|
| 268 |
-
|
| 269 |
|
| 270 |
*Returns:* `x.flip()`.
|
| 271 |
|
| 272 |
``` cpp
|
| 273 |
-
bitset
|
| 274 |
```
|
| 275 |
|
| 276 |
*Effects:* Toggles all bits in `*this`.
|
| 277 |
|
| 278 |
*Returns:* `*this`.
|
| 279 |
|
| 280 |
``` cpp
|
| 281 |
-
bitset
|
| 282 |
```
|
| 283 |
|
| 284 |
*Effects:* Toggles the bit at position `pos` in `*this`.
|
| 285 |
|
| 286 |
*Returns:* `*this`.
|
| 287 |
|
| 288 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 289 |
position.
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
```
|
| 294 |
|
| 295 |
*Returns:* `x`.
|
| 296 |
|
| 297 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
| 298 |
the bits in `*this` cannot be represented as type `unsigned long`.
|
| 299 |
|
| 300 |
``` cpp
|
| 301 |
-
unsigned long long to_ullong() const;
|
| 302 |
```
|
| 303 |
|
| 304 |
*Returns:* `x`.
|
| 305 |
|
| 306 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
|
@@ -308,11 +352,11 @@ the bits in `*this` cannot be represented as type `unsigned long long`.
|
|
| 308 |
|
| 309 |
``` cpp
|
| 310 |
template<class charT = char,
|
| 311 |
class traits = char_traits<charT>,
|
| 312 |
class Allocator = allocator<charT>>
|
| 313 |
-
basic_string<charT, traits, Allocator>
|
| 314 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 315 |
```
|
| 316 |
|
| 317 |
*Effects:* Constructs a string object of the appropriate type and
|
| 318 |
initializes it to a string of length `N` characters. Each character is
|
|
@@ -323,11 +367,11 @@ Bit value zero becomes the character `zero`, bit value one becomes the
|
|
| 323 |
character `one`.
|
| 324 |
|
| 325 |
*Returns:* The created object.
|
| 326 |
|
| 327 |
``` cpp
|
| 328 |
-
size_t count() const noexcept;
|
| 329 |
```
|
| 330 |
|
| 331 |
*Returns:* A count of the number of bits set in `*this`.
|
| 332 |
|
| 333 |
``` cpp
|
|
@@ -335,79 +379,39 @@ constexpr size_t size() const noexcept;
|
|
| 335 |
```
|
| 336 |
|
| 337 |
*Returns:* `N`.
|
| 338 |
|
| 339 |
``` cpp
|
| 340 |
-
bool operator==(const bitset
|
| 341 |
```
|
| 342 |
|
| 343 |
*Returns:* `true` if the value of each bit in `*this` equals the value
|
| 344 |
of the corresponding bit in `rhs`.
|
| 345 |
|
| 346 |
``` cpp
|
| 347 |
-
bool test(size_t pos) const;
|
| 348 |
```
|
| 349 |
|
| 350 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 351 |
one.
|
| 352 |
|
| 353 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 354 |
position.
|
| 355 |
|
| 356 |
``` cpp
|
| 357 |
-
bool all() const noexcept;
|
| 358 |
```
|
| 359 |
|
| 360 |
*Returns:* `count() == size()`.
|
| 361 |
|
| 362 |
``` cpp
|
| 363 |
-
bool any() const noexcept;
|
| 364 |
```
|
| 365 |
|
| 366 |
*Returns:* `count() != 0`.
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
-
bool none() const noexcept;
|
| 370 |
```
|
| 371 |
|
| 372 |
*Returns:* `count() == 0`.
|
| 373 |
|
| 374 |
-
``` cpp
|
| 375 |
-
bitset<N> operator<<(size_t pos) const noexcept;
|
| 376 |
-
```
|
| 377 |
-
|
| 378 |
-
*Returns:* `bitset<N>(*this) <<= pos`.
|
| 379 |
-
|
| 380 |
-
``` cpp
|
| 381 |
-
bitset<N> operator>>(size_t pos) const noexcept;
|
| 382 |
-
```
|
| 383 |
-
|
| 384 |
-
*Returns:* `bitset<N>(*this) >>= pos`.
|
| 385 |
-
|
| 386 |
-
``` cpp
|
| 387 |
-
constexpr bool operator[](size_t pos) const;
|
| 388 |
-
```
|
| 389 |
-
|
| 390 |
-
*Preconditions:* `pos` is valid.
|
| 391 |
-
|
| 392 |
-
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 393 |
-
one, otherwise `false`.
|
| 394 |
-
|
| 395 |
-
*Throws:* Nothing.
|
| 396 |
-
|
| 397 |
-
``` cpp
|
| 398 |
-
bitset<N>::reference operator[](size_t pos);
|
| 399 |
-
```
|
| 400 |
-
|
| 401 |
-
*Preconditions:* `pos` is valid.
|
| 402 |
-
|
| 403 |
-
*Returns:* An object of type `bitset<N>::reference` such that
|
| 404 |
-
`(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
|
| 405 |
-
equivalent to `this->set(pos, val)`.
|
| 406 |
-
|
| 407 |
-
*Throws:* Nothing.
|
| 408 |
-
|
| 409 |
-
*Remarks:* For the purpose of determining the presence of a data
|
| 410 |
-
race [[intro.multithread]], any access or update through the resulting
|
| 411 |
-
reference potentially accesses or modifies, respectively, the entire
|
| 412 |
-
underlying bitset.
|
| 413 |
-
|
|
|
|
| 1 |
### Class template `bitset` <a id="template.bitset">[[template.bitset]]</a>
|
| 2 |
|
| 3 |
+
#### General <a id="template.bitset.general">[[template.bitset.general]]</a>
|
| 4 |
+
|
| 5 |
``` cpp
|
| 6 |
namespace std {
|
| 7 |
template<size_t N> class bitset {
|
| 8 |
public:
|
| 9 |
// bit reference
|
| 10 |
class reference {
|
| 11 |
friend class bitset;
|
| 12 |
+
constexpr reference() noexcept;
|
| 13 |
|
| 14 |
public:
|
| 15 |
+
constexpr reference(const reference&) = default;
|
| 16 |
+
constexpr ~reference();
|
| 17 |
+
constexpr reference& operator=(bool x) noexcept; // for b[i] = x;
|
| 18 |
+
constexpr reference& operator=(const reference&) noexcept; // for b[i] = b[j];
|
| 19 |
+
constexpr bool operator~() const noexcept; // flips the bit
|
| 20 |
+
constexpr operator bool() const noexcept; // for x = b[i];
|
| 21 |
+
constexpr reference& flip() noexcept; // for b[i].flip();
|
| 22 |
};
|
| 23 |
|
| 24 |
// [bitset.cons], constructors
|
| 25 |
constexpr bitset() noexcept;
|
| 26 |
constexpr bitset(unsigned long long val) noexcept;
|
| 27 |
template<class charT, class traits, class Allocator>
|
| 28 |
+
constexpr explicit bitset(
|
| 29 |
const basic_string<charT, traits, Allocator>& str,
|
| 30 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 31 |
typename basic_string<charT, traits, Allocator>::size_type n
|
| 32 |
= basic_string<charT, traits, Allocator>::npos,
|
| 33 |
charT zero = charT('0'),
|
| 34 |
charT one = charT('1'));
|
| 35 |
template<class charT>
|
| 36 |
+
constexpr explicit bitset(
|
| 37 |
const charT* str,
|
| 38 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 39 |
charT zero = charT('0'),
|
| 40 |
charT one = charT('1'));
|
| 41 |
|
| 42 |
// [bitset.members], bitset operations
|
| 43 |
+
constexpr bitset& operator&=(const bitset& rhs) noexcept;
|
| 44 |
+
constexpr bitset& operator|=(const bitset& rhs) noexcept;
|
| 45 |
+
constexpr bitset& operator^=(const bitset& rhs) noexcept;
|
| 46 |
+
constexpr bitset& operator<<=(size_t pos) noexcept;
|
| 47 |
+
constexpr bitset& operator>>=(size_t pos) noexcept;
|
| 48 |
+
constexpr bitset operator<<(size_t pos) const noexcept;
|
| 49 |
+
constexpr bitset operator>>(size_t pos) const noexcept;
|
| 50 |
+
constexpr bitset& set() noexcept;
|
| 51 |
+
constexpr bitset& set(size_t pos, bool val = true);
|
| 52 |
+
constexpr bitset& reset() noexcept;
|
| 53 |
+
constexpr bitset& reset(size_t pos);
|
| 54 |
+
constexpr bitset operator~() const noexcept;
|
| 55 |
+
constexpr bitset& flip() noexcept;
|
| 56 |
+
constexpr bitset& flip(size_t pos);
|
| 57 |
|
| 58 |
// element access
|
| 59 |
+
constexpr bool operator[](size_t pos) const;
|
| 60 |
+
constexpr reference operator[](size_t pos);
|
| 61 |
|
| 62 |
+
constexpr unsigned long to_ulong() const;
|
| 63 |
+
constexpr unsigned long long to_ullong() const;
|
| 64 |
template<class charT = char,
|
| 65 |
class traits = char_traits<charT>,
|
| 66 |
class Allocator = allocator<charT>>
|
| 67 |
+
constexpr basic_string<charT, traits, Allocator>
|
| 68 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 69 |
|
| 70 |
+
// observers
|
| 71 |
+
constexpr size_t count() const noexcept;
|
| 72 |
constexpr size_t size() const noexcept;
|
| 73 |
+
constexpr bool operator==(const bitset& rhs) const noexcept;
|
| 74 |
+
constexpr bool test(size_t pos) const;
|
| 75 |
+
constexpr bool all() const noexcept;
|
| 76 |
+
constexpr bool any() const noexcept;
|
| 77 |
+
constexpr bool none() const noexcept;
|
|
|
|
|
|
|
| 78 |
};
|
| 79 |
|
| 80 |
// [bitset.hash], hash support
|
| 81 |
template<class T> struct hash;
|
| 82 |
template<size_t N> struct hash<bitset<N>>;
|
|
|
|
| 92 |
between an object of class `bitset<N>` and a value of some integral
|
| 93 |
type, bit position `pos` corresponds to the *bit value* `1 << pos`. The
|
| 94 |
integral value corresponding to two or more bits is the sum of their bit
|
| 95 |
values.
|
| 96 |
|
| 97 |
+
The functions described in [[template.bitset]] can report three kinds of
|
| 98 |
errors, each associated with a distinct exception:
|
| 99 |
|
| 100 |
- an *invalid-argument* error is associated with exceptions of type
|
| 101 |
`invalid_argument` [[invalid.argument]];
|
| 102 |
- an *out-of-range* error is associated with exceptions of type
|
|
|
|
| 116 |
constexpr bitset(unsigned long long val) noexcept;
|
| 117 |
```
|
| 118 |
|
| 119 |
*Effects:* Initializes the first `M` bit positions to the corresponding
|
| 120 |
bit values in `val`. `M` is the smaller of `N` and the number of bits in
|
| 121 |
+
the value representation [[term.object.representation]] of
|
| 122 |
+
`unsigned long long`. If `M < N`, the remaining bit positions are
|
| 123 |
+
initialized to zero.
|
| 124 |
|
| 125 |
``` cpp
|
| 126 |
template<class charT, class traits, class Allocator>
|
| 127 |
+
constexpr explicit bitset(
|
| 128 |
const basic_string<charT, traits, Allocator>& str,
|
| 129 |
typename basic_string<charT, traits, Allocator>::size_type pos = 0,
|
| 130 |
typename basic_string<charT, traits, Allocator>::size_type n
|
| 131 |
= basic_string<charT, traits, Allocator>::npos,
|
| 132 |
charT zero = charT('0'),
|
|
|
|
| 152 |
any of the `rlen` characters in `str` beginning at position `pos` is
|
| 153 |
other than `zero` or `one`.
|
| 154 |
|
| 155 |
``` cpp
|
| 156 |
template<class charT>
|
| 157 |
+
constexpr explicit bitset(
|
| 158 |
const charT* str,
|
| 159 |
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
|
| 160 |
charT zero = charT('0'),
|
| 161 |
charT one = charT('1'));
|
| 162 |
```
|
|
|
|
| 171 |
```
|
| 172 |
|
| 173 |
#### Members <a id="bitset.members">[[bitset.members]]</a>
|
| 174 |
|
| 175 |
``` cpp
|
| 176 |
+
constexpr bitset& operator&=(const bitset& rhs) noexcept;
|
| 177 |
```
|
| 178 |
|
| 179 |
*Effects:* Clears each bit in `*this` for which the corresponding bit in
|
| 180 |
`rhs` is clear, and leaves all other bits unchanged.
|
| 181 |
|
| 182 |
*Returns:* `*this`.
|
| 183 |
|
| 184 |
``` cpp
|
| 185 |
+
constexpr bitset& operator|=(const bitset& rhs) noexcept;
|
| 186 |
```
|
| 187 |
|
| 188 |
*Effects:* Sets each bit in `*this` for which the corresponding bit in
|
| 189 |
`rhs` is set, and leaves all other bits unchanged.
|
| 190 |
|
| 191 |
*Returns:* `*this`.
|
| 192 |
|
| 193 |
``` cpp
|
| 194 |
+
constexpr bitset& operator^=(const bitset& rhs) noexcept;
|
| 195 |
```
|
| 196 |
|
| 197 |
*Effects:* Toggles each bit in `*this` for which the corresponding bit
|
| 198 |
in `rhs` is set, and leaves all other bits unchanged.
|
| 199 |
|
| 200 |
*Returns:* `*this`.
|
| 201 |
|
| 202 |
``` cpp
|
| 203 |
+
constexpr bitset& operator<<=(size_t pos) noexcept;
|
| 204 |
```
|
| 205 |
|
| 206 |
*Effects:* Replaces each bit at position `I` in `*this` with a value
|
| 207 |
determined as follows:
|
| 208 |
|
|
|
|
| 211 |
position `I - pos`.
|
| 212 |
|
| 213 |
*Returns:* `*this`.
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
+
constexpr bitset& operator>>=(size_t pos) noexcept;
|
| 217 |
```
|
| 218 |
|
| 219 |
*Effects:* Replaces each bit at position `I` in `*this` with a value
|
| 220 |
determined as follows:
|
| 221 |
|
|
|
|
| 224 |
position `I + pos`.
|
| 225 |
|
| 226 |
*Returns:* `*this`.
|
| 227 |
|
| 228 |
``` cpp
|
| 229 |
+
constexpr bitset operator<<(size_t pos) const noexcept;
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
*Returns:* `bitset(*this) <<= pos`.
|
| 233 |
+
|
| 234 |
+
``` cpp
|
| 235 |
+
constexpr bitset operator>>(size_t pos) const noexcept;
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
*Returns:* `bitset(*this) >>= pos`.
|
| 239 |
+
|
| 240 |
+
``` cpp
|
| 241 |
+
constexpr bitset& set() noexcept;
|
| 242 |
```
|
| 243 |
|
| 244 |
*Effects:* Sets all bits in `*this`.
|
| 245 |
|
| 246 |
*Returns:* `*this`.
|
| 247 |
|
| 248 |
``` cpp
|
| 249 |
+
constexpr bitset& set(size_t pos, bool val = true);
|
| 250 |
```
|
| 251 |
|
| 252 |
*Effects:* Stores a new value in the bit at position `pos` in `*this`.
|
| 253 |
If `val` is `true`, the stored value is one, otherwise it is zero.
|
| 254 |
|
|
|
|
| 256 |
|
| 257 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 258 |
position.
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
+
constexpr bitset& reset() noexcept;
|
| 262 |
```
|
| 263 |
|
| 264 |
*Effects:* Resets all bits in `*this`.
|
| 265 |
|
| 266 |
*Returns:* `*this`.
|
| 267 |
|
| 268 |
``` cpp
|
| 269 |
+
constexpr bitset& reset(size_t pos);
|
| 270 |
```
|
| 271 |
|
| 272 |
*Effects:* Resets the bit at position `pos` in `*this`.
|
| 273 |
|
| 274 |
*Returns:* `*this`.
|
| 275 |
|
| 276 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 277 |
position.
|
| 278 |
|
| 279 |
``` cpp
|
| 280 |
+
constexpr bitset operator~() const noexcept;
|
| 281 |
```
|
| 282 |
|
| 283 |
+
*Effects:* Constructs an object `x` of class `bitset` and initializes it
|
| 284 |
+
with `*this`.
|
| 285 |
|
| 286 |
*Returns:* `x.flip()`.
|
| 287 |
|
| 288 |
``` cpp
|
| 289 |
+
constexpr bitset& flip() noexcept;
|
| 290 |
```
|
| 291 |
|
| 292 |
*Effects:* Toggles all bits in `*this`.
|
| 293 |
|
| 294 |
*Returns:* `*this`.
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
+
constexpr bitset& flip(size_t pos);
|
| 298 |
```
|
| 299 |
|
| 300 |
*Effects:* Toggles the bit at position `pos` in `*this`.
|
| 301 |
|
| 302 |
*Returns:* `*this`.
|
| 303 |
|
| 304 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 305 |
position.
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
+
constexpr bool operator[](size_t pos) const;
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
*Preconditions:* `pos` is valid.
|
| 312 |
+
|
| 313 |
+
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 314 |
+
one, otherwise `false`.
|
| 315 |
+
|
| 316 |
+
*Throws:* Nothing.
|
| 317 |
+
|
| 318 |
+
``` cpp
|
| 319 |
+
constexpr bitset::reference operator[](size_t pos);
|
| 320 |
+
```
|
| 321 |
+
|
| 322 |
+
*Preconditions:* `pos` is valid.
|
| 323 |
+
|
| 324 |
+
*Returns:* An object of type `bitset::reference` such that
|
| 325 |
+
`(*this)[pos] == this->test(pos)`, and such that `(*this)[pos] = val` is
|
| 326 |
+
equivalent to `this->set(pos, val)`.
|
| 327 |
+
|
| 328 |
+
*Throws:* Nothing.
|
| 329 |
+
|
| 330 |
+
*Remarks:* For the purpose of determining the presence of a data
|
| 331 |
+
race [[intro.multithread]], any access or update through the resulting
|
| 332 |
+
reference potentially accesses or modifies, respectively, the entire
|
| 333 |
+
underlying bitset.
|
| 334 |
+
|
| 335 |
+
``` cpp
|
| 336 |
+
constexpr unsigned long to_ulong() const;
|
| 337 |
```
|
| 338 |
|
| 339 |
*Returns:* `x`.
|
| 340 |
|
| 341 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
| 342 |
the bits in `*this` cannot be represented as type `unsigned long`.
|
| 343 |
|
| 344 |
``` cpp
|
| 345 |
+
constexpr unsigned long long to_ullong() const;
|
| 346 |
```
|
| 347 |
|
| 348 |
*Returns:* `x`.
|
| 349 |
|
| 350 |
*Throws:* `overflow_error` if the integral value `x` corresponding to
|
|
|
|
| 352 |
|
| 353 |
``` cpp
|
| 354 |
template<class charT = char,
|
| 355 |
class traits = char_traits<charT>,
|
| 356 |
class Allocator = allocator<charT>>
|
| 357 |
+
constexpr basic_string<charT, traits, Allocator>
|
| 358 |
to_string(charT zero = charT('0'), charT one = charT('1')) const;
|
| 359 |
```
|
| 360 |
|
| 361 |
*Effects:* Constructs a string object of the appropriate type and
|
| 362 |
initializes it to a string of length `N` characters. Each character is
|
|
|
|
| 367 |
character `one`.
|
| 368 |
|
| 369 |
*Returns:* The created object.
|
| 370 |
|
| 371 |
``` cpp
|
| 372 |
+
constexpr size_t count() const noexcept;
|
| 373 |
```
|
| 374 |
|
| 375 |
*Returns:* A count of the number of bits set in `*this`.
|
| 376 |
|
| 377 |
``` cpp
|
|
|
|
| 379 |
```
|
| 380 |
|
| 381 |
*Returns:* `N`.
|
| 382 |
|
| 383 |
``` cpp
|
| 384 |
+
constexpr bool operator==(const bitset& rhs) const noexcept;
|
| 385 |
```
|
| 386 |
|
| 387 |
*Returns:* `true` if the value of each bit in `*this` equals the value
|
| 388 |
of the corresponding bit in `rhs`.
|
| 389 |
|
| 390 |
``` cpp
|
| 391 |
+
constexpr bool test(size_t pos) const;
|
| 392 |
```
|
| 393 |
|
| 394 |
*Returns:* `true` if the bit at position `pos` in `*this` has the value
|
| 395 |
one.
|
| 396 |
|
| 397 |
*Throws:* `out_of_range` if `pos` does not correspond to a valid bit
|
| 398 |
position.
|
| 399 |
|
| 400 |
``` cpp
|
| 401 |
+
constexpr bool all() const noexcept;
|
| 402 |
```
|
| 403 |
|
| 404 |
*Returns:* `count() == size()`.
|
| 405 |
|
| 406 |
``` cpp
|
| 407 |
+
constexpr bool any() const noexcept;
|
| 408 |
```
|
| 409 |
|
| 410 |
*Returns:* `count() != 0`.
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
+
constexpr bool none() const noexcept;
|
| 414 |
```
|
| 415 |
|
| 416 |
*Returns:* `count() == 0`.
|
| 417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|