📄 bitset.html
字号:
<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 TEXT="#000000" LINK="#006600" ALINK="#003300" VLINK="#7C7F87" BGCOLOR="#FFFFFF"><A HREF="/"><IMG SRC="/images/common/sgilogo_small.gif" ALT="SGI Logo" WIDTH="80" HEIGHT="72" BORDER="0"></A><P><!--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 = "38" ></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 providesconstant-time access to each bit. There are two main differencesbetween <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 specifiesthe 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 interfaceresembles that of unsigned integers. It defines bitwise arithmeticoperators 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 themost 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>bitset()</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>bitset(unsigned long val)</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Conversion from unsigned long.</TD></TR><TR><TD VAlign=top><tt>bitset(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& operator=(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>explicitbitset(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><tt>bitset</tt></TD><TD VAlign=top>Conversion from string.</TD></TR><TR><TD VAlign=top><tt>bitset& operator&=(const bitset&)</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Bitwise and.</TD></TR><TR><TD VAlign=top><tt>bitset& operator|=(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& operator^=(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& operator<<=(size_t)</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Left shift.</TD></TR><TR><TD VAlign=top><tt>bitset& operator>>=(size_t)</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Right shift.</TD></TR><TR><TD VAlign=top><tt>bitset operator<<(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 operator>>(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& set()</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Sets every bit.</TD></TR><TR><TD VAlign=top><tt>bitset& flip()</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 operator~() 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& reset()</tt></TD><TD VAlign=top><tt>bitset</tt></TD><TD VAlign=top>Clears every bit.</TD></TR><TR><TD VAlign=top><tt>bitset& set(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& reset(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 flip(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 size() 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 count() 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 any() 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 none() 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 test(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 operator[](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 operator[](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 long to_ulong() 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> to_string() 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 operator==(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 operator!=(const bitset&) const</tt></TD><TD VAlign=top> <A href="EqualityComparable.html">Equality Comparable</A></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -