📄 bitset.html
字号:
<HTML><HEAD><TITLE><bitset></TITLE></HEAD><BODY><H1><A NAME="<bitset>"><CODE><bitset></CODE></A></H1><HR><P><B><CODE><A HREF="#bitset">bitset</A>· <A HREF="#operator&">operator&</A>· <A HREF="#operator|">operator|</A>· <A HREF="#operator^">operator^</A>· <A HREF="#operator>>">operator>></A>· <A HREF="#operator<<">operator<<</A></CODE></B></P><P>Include the standard header <B><CODE><bitset></CODE></B>to define the template class <CODE>bitset</CODE>and two supporting templates.</P><PRE>namespace std {template<size_t Bits> class <B><A HREF="#bitset">bitset</A></B>; // TEMPLATE FUNCTIONStemplate<size_t Bits> bitset<Bits> <B><A HREF="#operator&">operator&</A></B>(const bitset& left, const bitset& right);template<size_t Bits> bitset<Bits> <B><A HREF="#operator|">operator|</A></B>(const bitset& left, const bitset& right);template<size_t Bits> bitset<Bits> <B><A HREF="#operator^">operator&</A></B>(const bitset& left, const bitset& right);template<class Elem, class Tr, size_t Bits> basic_istream<Elem, Tr>& <B><A HREF="#operator>>">operator>></A></B>(basic_istream<Elem, >& istr, bitset<Bits>& right);template<class Elem, class Tr, size_t Bits> basic_ostream<Elem, Tr>& <B><A HREF="#operator<<">operator<<</A></B>(basic_ostream<Elem, Tr>& ostr, const bitset<Bits>& right); };</PRE><H2><A NAME="bitset"><CODE>bitset</CODE></A></H2><HR><P><B><CODE><A HREF="#bitset::any">any</A>· <A HREF="#bitset::bitset">bitset</A>· <A HREF="#bitset::count">count</A>· <A HREF="#bitset::element_type">element_type</A>· <A HREF="#bitset::flip">flip</A>· <A HREF="#bitset::none">none</A>· <A HREF="#bitset::operator!=">operator!=</A>· <A HREF="#bitset::operator&=">operator&=</A>· <A HREF="#bitset::operator<<">operator<<</A>· <A HREF="#bitset::operator<<=">operator<<=</A>· <A HREF="#bitset::operator==">operator==</A>· <A HREF="#bitset::operator>>">operator>></A>· <A HREF="#bitset::operator>>=">operator>>=</A>· <A HREF="#bitset::operator[]">operator[]</A>· <A HREF="#bitset::operator^=">operator^=</A>· <A HREF="#bitset::operator|=">operator|=</A>· <A HREF="#bitset::operator~">operator~</A>· <A HREF="#bitset::reference">reference</A>· <A HREF="#bitset::reset">reset</A>· <A HREF="#bitset::set">set</A>· <A HREF="#bitset::size">size</A>· <A HREF="#bitset::test">test</A>· <A HREF="#bitset::to_string">to_string</A>· <A HREF="#bitset::to_ulong">to_ulong</A></CODE></B></P><HR><PRE>template<size_t Bits> class <B>bitset</B> {public: typedef bool <B><A HREF="#bitset::element_type">element_type</A></B>; class <B><A HREF="#bitset::reference">reference</A></B>; <B><A HREF="#bitset::bitset">bitset</A></B>(); <B><A HREF="#bitset::bitset">bitset</A></B>(unsigned long val); template<class Elem, class Tr, class Alloc> explicit <B><A HREF="#bitset::bitset">bitset</A></B>(const basic_string<Elem, Tr, Alloc>& str, typename basic_string<Elem, Tr, Alloc>::size_type pos = 0, typename basic_string<Elem, Tr, Alloc>::size_type count = basic_string<Elem, Tr, Alloc>::npos); bitset<Bits>& <B><A HREF="#bitset::operator&=">operator&=</A></B>(const bitset<Bits>& right); bitset<Bits>& <B><A HREF="#bitset::operator|=">operator|=</A></B>(const bitset<Bits>& right); bitset<Bits>& <B><A HREF="#bitset::operator^=">operator^=</A></B>(const bitset<Bits>& right); bitset<Bits>& <B><A HREF="#bitset::operator<<=">operator<<=</A></B>(const bitset<Bits>& pos); bitset<Bits>& <B><A HREF="#bitset::operator>>=">operator>>=</A></B>(const bitset<Bits>& pos); bitset<Bits>& <B><A HREF="#bitset::set">set</A></B>(); bitset<Bits>& <B><A HREF="#bitset::set">set</A></B>(size_t pos, bool val = true); bitset<Bits>& <B><A HREF="#bitset::reset">reset</A></B>(); bitset<Bits>& <B><A HREF="#bitset::reset">reset</A></B>(size_t pos); bitset<Bits>& <B><A HREF="#bitset::flip">flip</A></B>(); bitset<Bits>& <B><A HREF="#bitset::flip">flip</A></B>(size_t pos); reference <B><A HREF="#bitset::operator[]">operator[]</A></B>(size_t pos); bool <B><A HREF="#bitset::operator[]">operator[]</A></B>(size_t pos) const; unsigned long <B><A HREF="#bitset::to_ulong">to_ulong</A></B>() const; template<class Elem, class Tr, class Alloc> basic_string<Elem, Tr, Alloc> <B><A HREF="#bitset::to_string">to_string</A></B>() const; size_t <B><A HREF="#bitset::count">count</A></B>() const; size_t <B><A HREF="#bitset::size">size</A></B>() const; bool <B><A HREF="#bitset::operator==">operator==</A></B>(const bitset<Bits>& right) const; bool <B><A HREF="#bitset::operator!=">operator!=</A></B>(const bitset<Bits>& right) const; bool <B><A HREF="#bitset::test">test</A></B>(size_t pos) const; bool <B><A HREF="#bitset::any">any</A></B>() const; bool <B><A HREF="#bitset::none">none</A></B>() const; bitset<Bits> <B><A HREF="#bitset::operator<<">operator<<</A></B>(size_t pos) const; bitset<Bits> <B><A HREF="#bitset::operator>>">operator>></A></B>(size_t pos) const; bitset<Bits> <B><A HREF="#bitset::operator~">operator~</A></B>() const; };</PRE><P>The template class describes an object that stores asequence of <CODE>Bits</CODE> bits. A bit is<B><A NAME="bit set">set</A></B> if its value is 1,<B><A NAME="bit reset">reset</A></B> if its value is 0.To <B><A NAME="bit flip">flip</A></B> a bit is to change its valuefrom 1 to 0 or from 0 to 1.When converting between an object ofclass <CODE>bitset<Bits></CODE> and an object of some integral type,bit position <CODE>J</CODE> corresponds to the bit value<CODE>1 << J</CODE>. The integral value corresponding to twoor more bits is the sum of their bit values.</P><H3><CODE><A NAME="bitset::any">bitset::any</A></CODE></H3><PRE>bool <B>any</B>() const;</PRE><P>The member function returns true if any bit is set in thebit sequence.</P><H3><CODE><A NAME="bitset::bitset">bitset::bitset</A></CODE></H3><PRE><B>bitset</B>();<B>bitset</B>(unsigned long val);template<class Elem, class Tr, class Alloc> explicit <B>bitset</B>(const basic_string<Elem, Tr, Alloc>& str, typename basic_string<Elem, Tr, Alloc>::size_type pos = 0, typename basic_string<Elem, Tr, Alloc>::size_type count = basic_string<Elem, Tr, Alloc>::npos);</PRE><P>The first constructor resets all bits in the bit sequence.The second constructor sets only those bits at position <CODE>J</CODE>for which <CODE>val & 1 << J</CODE> is nonzero.</P><P>The third constructor determines the initial bit values fromelements of a string determined from <CODE>str</CODE>. If<CODE>str.<A HREF="string2.html#basic_string::size">size</A>()< pos</CODE>, the constructor throws an object of class<CODE><A HREF="stdexcep.html#out_of_range">out_of_range</A></CODE>.Otherwise, the effective length of the string <CODE>rlen</CODE>is the smaller of <CODE>count</CODE> and<CODE>str.size() - pos</CODE>. If any of the <CODE>rlen</CODE>elements beginning at position <CODE>pos</CODE> is other than<CODE>0</CODE> or <CODE>1</CODE>, the constructor throws an object of class<CODE><A HREF="stdexcep.html#invalid_argument">invalid_argument</A></CODE>.Otherwise, the constructor sets only those bits at position <CODE>J</CODE>for which the element at position <CODE>pos + J</CODE> is <CODE>1</CODE>.</P><H3><CODE><A NAME="bitset::count">bitset::count</A></CODE></H3><PRE>size_t <B><A HREF="#bitset::count">count</A></B>() const;</PRE><P>The member function returns the number of bits set in thebit sequence.</P><H3><CODE><A NAME="bitset::element_type">bitset::element_type</A></CODE></H3><PRE>typedef bool <B>element_type</B>;</PRE><P>The type is a synonym for <CODE>bool</CODE>.</P><H3><CODE><A NAME="bitset::flip">bitset::flip</A></CODE></H3><PRE>bitset<Bits>& <B>flip</B>();bitset<Bits>& <B>flip</B>(size_t pos);</PRE><P>The first member function flips all bits in the bit sequence,then returns <CODE>*this</CODE>.The second member function throws<CODE><A HREF="stdexcep.html#out_of_range">out_of_range</A></CODE> if<CODE><A HREF="#bitset::size">size</A>()<= pos</CODE>. Otherwise, it flips the bitat position <CODE>pos</CODE>, then returns <CODE>*this</CODE>.</P><H3><CODE><A NAME="bitset::none">bitset::none</A></CODE></H3><PRE>bool <B><A HREF="#bitset::none">none</A></B>() const;</PRE><P>The member function returns true if none of the bits are setin the bit sequence.</P><H3><CODE><A NAME="bitset::operator!=">bitset::operator!=</A></CODE></H3><PRE>bool <B>operator !=</B>(const bitset<Bits>& right) const;</PRE><P>The member operator function returns trueonly if the bit sequence stored in<CODE>*this</CODE> differs from the one stored in <CODE>right</CODE>.</P><H3><CODE><A NAME="bitset::operator&=">bitset::operator&=</A></CODE></H3><PRE>bitset<Bits>& <B>operator&=</B>(const bitset<Bits>& right);</PRE><P>The member operator function replaces each element of the bit sequence storedin <CODE>*this</CODE> with the logical AND of its previous value andthe corresponding bit in <CODE>right</CODE>.The function returns <CODE>*this</CODE>.</P><H3><CODE><A NAME="bitset::operator<<">bitset::operator<<</A></CODE></H3><PRE>bitset<Bits> <B>operator<<</B>(const bitset<Bits>& pos);</PRE><P>The member operator function returns <CODE>bitset(*this)<A HREF="#bitset::operator<<="><<=</A> pos</CODE>.</P><H3><CODE><A NAME="bitset::operator<<=">bitset::operator<<=</A></CODE></H3><PRE>bitset<Bits>& <B>operator<<=</B>(const bitset<Bits>& pos);</PRE><P>The member operator function replaceseach element of the bit sequence storedin <CODE>*this</CODE> with the element <CODE>pos</CODE> positions earlierin the sequence. If no such earlier element exists, the function clearsthe bit. The function returns <CODE>*this</CODE>.</P><H3><CODE><A NAME="bitset::operator==">bitset::operator==</A></CODE></H3><PRE>bool <B>operator ==</B>(const bitset<Bits>& right) const;</PRE><P>The member operator function returns trueonly if the bit sequence stored in<CODE>*this</CODE> is the same as the one stored in <CODE>right</CODE>.</P><H3><CODE><A NAME="bitset::operator>>">bitset::operator>></A></CODE></H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -