1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
|
<HTML>
<!--
-- Copyright (c) 1996-1999
-- Silicon Graphics Computer Systems, Inc.
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Silicon Graphics makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-- Copyright (c) 1994
-- Hewlett-Packard Company
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Hewlett-Packard Company makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-->
<Head>
<Title>bitset<N></Title>
<!-- Generated by htmldoc -->
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
ALINK="#ff0000">
<IMG SRC="CorpID.gif"
ALT="SGI" HEIGHT="43" WIDTH="151">
<!--end header-->
<BR Clear>
<H1>bitset<N></H1>
<Table CellPadding=0 CellSpacing=0 width=100%>
<TR>
<TD Align=left><Img src = "containers.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD>
<TD Align=right><Img src = "type.gif" Alt="" WIDTH = "194" HEIGHT = "39" ></TD>
</TR>
<TR>
<TD Align=left VAlign=top><b>Category</b>: containers</TD>
<TD Align=right VAlign=top><b>Component type</b>: type</TD>
</TR>
</Table>
<h3>Description</h3>
<tt>Bitset</tt> is very similar to <A href="Vector.html">vector</A><bool> (also known as
<A href="bit_vector.html">bit_vector</A>): it contains a collection of bits, and provides
constant-time access to each bit. There are two main differences
between <tt>bitset</tt> and <tt>vector<bool></tt>. First, the size of a <tt>bitset</tt>
cannot be changed: <tt>bitset</tt>'s template parameter <tt>N</tt>, which specifies
the number of bits in the bitset, must be an integer constant.
Second, <tt>bitset</tt> is not a <A href="Sequence.html">Sequence</A>; in fact, it is not an STL
<A href="Container.html">Container</A> at all. It does not have iterators, for example, or
<tt>begin()</tt> and <tt>end()</tt> member functions. Instead, <tt>bitset</tt>'s interface
resembles that of unsigned integers. It defines bitwise arithmetic
operators such as <tt>&=</tt>, <tt>|=</tt>, and <tt>^=</tt>.
<P>
In general, bit <tt>0</tt> is the least significant bit and bit <tt>N-1</tt> is the
most significant bit.
<h3>Example</h3>
<pre>
int main() {
const bitset<12> mask(2730ul);
cout << "mask = " << mask << endl;
bitset<12> x;
cout << "Enter a 12-bit bitset in binary: " << flush;
if (cin >> x) {
cout << "x = " << x << endl;
cout << "As ulong: " << x.to_ulong() << endl;
cout << "And with mask: " << (x & mask) << endl;
cout << "Or with mask: " << (x | mask) << endl;
}
}
</pre>
<h3>Definition</h3>
Defined in the standard header <A href="bitset">bitset</A>.
<h3>Template parameters</h3>
<Table border>
<TR>
<TH>
Parameter
</TH>
<TH>
Description
</TH>
<TH>
Default
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>N</tt>
</TD>
<TD VAlign=top>
A nonzero constant of type <tt>size_t</tt>: the number of bits that the
bitset contains.
</TD>
<TD VAlign=top>
</TD>
</tr>
</table>
<h3>Model of</h3>
<A href="Assignable.html">Assignable</A>, <A href="DefaultConstructible.html">Default Constructible</A>, <A href="EqualityComparable.html">Equality Comparable</A>
<h3>Type requirements</h3>
<tt>N</tt> is a constant integer expression of a type convertible to
<tt>size_t</tt>, and <tt>N</tt> is a positive number.
<h3>Public base classes</h3>
None.
<h3>Members</h3>
<Table border>
<TR>
<TH>
Member
</TH>
<TH>
Where defined
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>reference</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
A proxy class that acts as a reference to a single bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt><b>bitset</b>()</tt>
</TD>
<TD VAlign=top>
<A href="DefaultConstructible.html">Default Constructible</A>
</TD>
<TD VAlign=top>
The default constructor. All bits are initially zero.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt><b>bitset</b>(unsigned long val)</tt>
</TD>
<TD VAlign=top>
<tt><b>bitset</b></tt>
</TD>
<TD VAlign=top>
Conversion from unsigned long.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt><b>bitset</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
<A href="Assignable.html">Assignable</A>
</TD>
<TD VAlign=top>
Copy constructor.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
<A href="Assignable.html">Assignable</A>
</TD>
<TD VAlign=top>
Assignment operator.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
explicit
<b>bitset</b>(const <A href="basic_staring.html">basic_string</A><Char,Traits,Alloc>& s,
size_t pos = 0,
size_t n =
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc>::npos)
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Conversion from string.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator&=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise and.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator|=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise inclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator^=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator<<=</b>(size_t)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Left shift.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator>>=</b>(size_t)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Right shift.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator<<</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted left by <tt>n</tt> bits.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator>></b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted right by <tt>n</tt> bits.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>set()</b></tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Sets every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>flip</b>()</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Flips the value of every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator~</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> with all of its bits flipped.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>reset</b>()</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Clears every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>set</b>(size_t n, int val = 1)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Sets bit <tt>n</tt> if <tt>val</tt> is nonzero, and clears bit <tt>n</tt> if <tt>val</tt> is zero.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>reset</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Clears bit <tt>n</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>flip</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Flips bit <tt>n</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t <b>size</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns <tt>N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t <b>count</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns the number of bits that are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>any</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if any bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>none</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if no bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>test</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference <b>operator[]</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns a <tt>reference</tt> to bit <tt>n</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>operator[]</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>unsigned <b>long to_ulong</b>() const</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns an <tt>unsigned long</tt> corresponding to the bits in <tt>*this</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc> <b>to_string</b>() const
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Returns a string representation of <tt>*this</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>operator==</b>(const bitset&) const</tt>
</TD>
<TD VAlign=top>
<A href="EqualityComparable.html">Equality Comparable</A>
</TD>
<TD VAlign=top>
The equality operator.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>operator!=</b>(const bitset&) const</tt>
</TD>
<TD VAlign=top>
<A href="EqualityComparable.html">Equality Comparable</A>
</TD>
<TD VAlign=top>
The inequality operator.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator&</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise and of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator|</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise or of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator^</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_istream<Char,Traits>&
<b>operator>></b>(basic_istream<Char,Traits>&,
bitset<N>&)
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Extract a <tt>bitset</tt> from an input stream.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_ostream<Char,Traits>&
<b>operator>></b>(basic_ostream<Char,Traits>&,
const bitset<N>&)
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Output a <tt>bitset</tt> to an output stream.
</TD>
</tr>
</table>
<h3>New members</h3>
These members are not defined in the
<A href="Assignable.html">Assignable</A>, <A href="DefaultConstructible.html">Default Constructible</A>, or <A href="EqualityComparable.html">Equality Comparable</A>
requirements, but are specific to <tt>bitset</tt>.
<Table border>
<TR>
<TH>
Member
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>reference</tt>
</TD>
<TD VAlign=top>
A proxy class that acts as a reference to a single bit. It contains
an assignment operator, a conversion to <tt>bool</tt>, an <tt>operator~</tt>, and
a member function <tt>flip</tt>. It exists only as a helper class for
<tt>bitset</tt>'s <tt>operator[]</tt>. That is, it supports the expressions
<tt>x = b[i]</tt>, <tt>b[i] = x</tt>, <tt>b[i] = b[j]</tt>, <tt>x = ~b[i]</tt>, and
<tt>b[i].flip()</tt>. (Where <tt>b</tt> is a <tt>bitset</tt> and <tt>x</tt> is a <tt>bool</tt>.)
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt><b>bitset</b>(unsigned long val)</tt>
</TD>
<TD VAlign=top>
Conversion from unsigned long. Constructs a bitset, initializing
the first <tt>min(N, sizeof(unsigned long) * CHAR_BIT)</tt> bits to the
corresponding bits in <tt>val</tt> and all other bits, if any, to zero.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
explicit
<b>bitset</b>(const <A href="basic_string.html">basic_string</A><Char,Traits,Alloc>& s,
size_t pos = 0,
size_t n =
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc>::npos)
</pre>
</TD>
<TD VAlign=top>
Conversion from string. Constructs a bitset, initializing the
first <tt>M</tt> bits to the corresponding characters in <tt>s</tt>, where
<tt>M</tt> is defined as <tt>min(N, min(s.size() - pos, n))</tt>.
Note that the <i>highest</i> character position in <tt>s</tt>, not the
lowest, corresponds to the least significant bit.
That is, character position <tt>pos + M - 1 - i</tt> corresponds to bit <tt>i</tt>.
So, for example, <tt>bitset(string("1101"))</tt> is the same as
<tt>bitset(13ul)</tt>. This function throws <tt>out_of_range</tt> if
<tt>pos > s.size()</tt>, and <tt>invalid_argument</tt> if any of the characters
used to initialize the bits are anything other than <tt>0</tt> or <tt>1</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator&=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise and.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator|=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise inclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator^=</b>(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator<<=</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
Left shift, where bit <tt>0</tt> is considered the least significant bit.
Bit <tt>i</tt> takes on the previous value of bit <tt>i - n</tt>, or zero if no
such bit exists.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>operator>>=</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
Right shift, where bit <tt>0</tt> is considered the least significant bit.
Bit <tt>i</tt> takes on the previous value of bit <tt>i + n</tt>, or zero if no
such bit exists.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator<<</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted left by <tt>n</tt> bits.
Note that the expression <tt>b << n</tt> is equivalent to
constructing a temporary copy of <tt>b</tt>
and then using <tt>operator<<=</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator>></b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted right by <tt>n</tt> bits.
Note that the expression <tt>b >> n</tt> is equivalent to
constructing a temporary copy of <tt>b</tt>
and then using <tt>operator>>=</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>set</b>()</tt>
</TD>
<TD VAlign=top>
Sets every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>flip</b>()</tt>
</TD>
<TD VAlign=top>
Flips the value of every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator~</b>() const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> with all of its bits flipped.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>reset</b>()</tt>
</TD>
<TD VAlign=top>
Clears every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>set</b>(size_t n, int val = 1)</tt>
</TD>
<TD VAlign=top>
Sets bit <tt>n</tt> if <tt>val</tt> is nonzero, and clears bit <tt>n</tt> if <tt>val</tt> is zero.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& <b>reset</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
Clears bit <tt>n</tt>.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>flip</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
Flips bit <tt>n</tt>.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t <b>size</b>() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t <b>count</b>() const</tt>
</TD>
<TD VAlign=top>
Returns the number of bits that are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>any</b>() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if any bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>none</b>() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if no bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <b>test</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference <B>operator[]</b>(size_t n)</tt>
</TD>
<TD VAlign=top>
Returns a <tt>reference</tt> to bit <tt>n</tt>. Note that <tt>reference</tt> is a
proxy class with an assignment operator and a conversion to <tt>bool</tt>,
which allows you to use <tt>operator[]</tt> for assignment. That is, you
can write both <tt>x = b[n]</tt> and <tt>b[n] = x</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool <B>operator[]</b>(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>unsigned <B>long to_ulong</b>() const</tt>
</TD>
<TD VAlign=top>
Returns an <tt>unsigned long</tt> corresponding to the bits in <tt>*this</tt>.
Throws <tt>overflow_error</tt> if it is impossible to represent <tt>*this</tt> as
an <tt>unsigned long</tt>. (That is, if <tt>N</tt> is larger than the number of
bits in an <tt>unsigned long</tt> and if any of the high-order bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc> <b>to_string</b>() const
</pre>
</TD>
<TD VAlign=top>
Returns a string representation of <tt>*this</tt>: each character is
<tt>1</tt> if the corresponding bit is set, and <tt>0</tt> if it is not.
In general, character position <tt>i</tt> corresponds to bit position
<tt>N - 1 - i</tt>. Note that this member function relies on two
language features, <i>member templates</i> and <i>explicit function
template argument specification</i>, that are not yet universally
available; this member function is disabled for compilers that do
not support those features. Note also that the syntax for calling
this member function is somewhat cumbersome. To convert a bitset <tt>b</tt>
to an ordinary string, you must write
<pre>
b.template to_string<char, char_traits<char>, allocator<char> >()
</pre>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator&</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise and of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 & b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator&=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator|</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise or of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 | b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator|=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset <b>operator^</b>(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 ^ b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator^=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_istream<Char, Traits>&
<b>operator>></b>(basic_istream<Char,Traits>& is,
bitset<N>& x)
</pre>
</TD>
<TD VAlign=top>
Extract a <tt>bitset</tt> from an input stream. This function first
skips whitespace, then extracts up to <tt>N</tt> characters from the
input stream. It stops either when it has successfully
extracted <tt>N</tt> character, or when extraction fails, or when
it sees a character that is something other than <tt>1</tt> (in which
case it does not extract that character). It then assigns a
value to the <tt>bitset</tt> in the same way as if it were initializing
the <tt>bitset</tt> from a string. So, for example, if the input stream
contains the characters <tt>"1100abc"</tt>, it will assign the value
<tt>12ul</tt> to the <tt>bitset</tt>, and the next character read from the input
stream will be <tt>a</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_ostream<Char,Traits>&
<B>operator>></b>(basic_ostream<Char,Traits>& os,
const bitset<N>& x)
</pre>
</TD>
<TD VAlign=top>
Output a <tt>bitset</tt> to an output stream. This function behaves as
if it converts the <tt>bitset</tt> to a string and then writes that string
to the output stream. That is, it is equivalent to
<pre>
os << x.template to_string<Char,Traits,allocator<Char> >()
</pre>
</TD>
</tr>
</table>
<h3>Notes</h3>
<h3>See also</h3>
<tt><A href="Vector.html">vector</A></tt>, <tt><A href="bit_vector.html">bit_vector</A></tt>, <tt><A href="basic_string.html">string</A></tt>
<!--start footer-->
<HR SIZE="6">
<A href="http://www.sgi.com/"><IMG SRC="surf.gif" HEIGHT="54" WIDTH="54"
ALT="[Silicon Surf]"></A>
<A HREF="index.html"><IMG SRC="stl_home.gif"
HEIGHT="54" WIDTH="54" ALT="[STL Home]"></A>
<BR>
<FONT SIZE="-2">
<A href="http://www.sgi.com/Misc/sgi_info.html" TARGET="_top">Copyright ©
1999 Silicon Graphics, Inc.</A> All Rights Reserved.</FONT>
<FONT SIZE="-3"><a href="http://www.sgi.com/Misc/external.list.html" TARGET="_top">TrademarkInformation</A>
</FONT>
<P>
</BODY>
</HTML>
|