📄 bitset.html
字号:
<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 function replaces each element of the bit sequence storedin <CODE>*this</CODE> with the element <CODE>pos</CODE> positions laterin the sequence. If no such later 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>(size_type pos) const;reference <B>operator[]</B>(size_type pos);</PRE><P>The member function returns an object of class<CODE><A HREF="#bitset::reference">reference</A></CODE>,which designates the bit at position <CODE>pos</CODE>,if the object can be modified. Otherwise, it returnsthe value of the bit at position <CODE>pos</CODE>in the bit sequence. If that position isinvalid, the behavior is undefined.</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 logicalEXCLUSIVE OR 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>& right);</PRE><P>The member operator function replaces each element of the bit sequence storedin <CODE>*this</CODE> with the logical OR 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;</PRE><P>The member operator function returns<CODE>bitset(*this).<A HREF="#bitset::flip">flip</A>()</CODE>.</P><H3><CODE><A NAME="bitset::reference">bitset::reference</A></CODE></H3><PRE>class <B>reference</B> {public: reference& <B>operator=</B>(bool val}; reference& <B>operator=</B>(const reference& bitref); bool <B>operator~</B>() const; <B>operator bool</B>() const; reference& <B>flip</B>(); };</PRE><P>The member class describes an object that designates anindividual bit within the bit sequence. Thus, for <CODE>val</CODE>an object of type <CODE>bool</CODE>, <CODE>bs</CODE> and <CODE>bs2</CODE>objects of type <CODE>bitset<Bits></CODE>, and<CODE>I</CODE> and <CODE>J</CODE>valid positions within such an object, the member functionsof class <CODE>reference</CODE> ensure that (in order):</P><UL><LI><B><CODE>bs[I] = val</CODE></B> stores <CODE>val</CODE> at bit position<CODE>I</CODE> in <CODE>bs</CODE></LI><LI><B><CODE>bs[I] = bs2[J]</CODE></B> stores the value of the bit<CODE>bs2[J]</CODE> at bit position<CODE>I</CODE> in <CODE>bs</CODE></LI><LI><B><CODE>val = ~bs[I]</CODE></B> stores the flipped value of the bit<CODE>bs[I]</CODE> in <CODE>val</CODE></LI><LI><B><CODE>val = bs[I]</CODE></B> stores the value of the bit<CODE>bs[I]</CODE> in <CODE>val</CODE></LI><LI><B><CODE>bs[I].flip()</CODE></B> stores the flipped value of the bit<CODE>bs[I]</CODE> back at bit position<CODE>I</CODE> in <CODE>bs</CODE></LI></UL><H3><CODE><A NAME="bitset::reset">bitset::reset</A></CODE></H3><PRE>bitset<Bits>& <B>reset</B>();bitset<Bits>& <B>reset</B>(size_t pos);</PRE><P>The first member function resets (or clears) 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 resets the bitat position <CODE>pos</CODE>, then returns <CODE>*this</CODE>.</P><H3><CODE><A NAME="bitset::set">bitset::set</A></CODE></H3><PRE>bitset<Bits>& <B>set</B>();bitset<Bits>& <B>set</B>(size_t pos, bool val = true);</PRE><P>The first member function sets 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 stores <CODE>val</CODE> in the bitat position <CODE>pos</CODE>, then returns <CODE>*this</CODE>.</P><H3><CODE><A NAME="bitset::size">bitset::size</A></CODE></H3><PRE>size_t <B>size</B>() const;</PRE><P>The member function returns <CODE>Bits</CODE>.</P><H3><CODE><A NAME="bitset::test">bitset::test</A></CODE></H3><PRE>bool <B>test</B>(size_t pos);</PRE><P>The 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 returns true only if the bitat position <CODE>pos</CODE> is set.</P><H3><CODE><A NAME="bitset::to_string">bitset::to_string</A></CODE></H3><PRE>template<class Elem, class Tr, class Alloc> basic_string<Elem, Tr, Alloc> <B><A HREF="#bitset::to_string">to_string</A></B>() const;</PRE><P>The member function constructs <CODE>str</CODE>, an object of class<CODE>basic_string<Elem, Tr, Alloc></CODE>.For each bit in the bit sequence, the functionappends <CODE>1</CODE> if the bit is set, otherwise <CODE>0</CODE>.The <I>last</I> element appended to <CODE>str</CODE> corresponds tobit position zero. The function returns <CODE>str</CODE>.</P><H3><CODE><A NAME="bitset::to_ulong">bitset::to_ulong</A></CODE></H3><PRE>unsigned long <B>to_ulong</B>() const;</PRE><P>The member function throws<CODE><A HREF="stdexcep.html#overflow_error">overflow_error</A></CODE>if any bit in the bit sequence has a bit value that cannot berepresented as a value of type <I>unsigned long.</I> Otherwise,it returns the sum of the bit values in the bit sequence.</P><H2><A NAME="operator&"><CODE>operator&</CODE></A></H2><PRE>template<size_t Bits> bitset<Bits> <B>operator&</B>(const bitset& left, const bitset& right);</PRE><P>The template function returns <CODE>(temp = left) &= right</CODE>,where <CODE>temp</CODE> has type <CODE>bitset<Bits></CODE>.</P><H2><A NAME="operator|"><CODE>operator|</CODE></A></H2><PRE>template<size_t Bits> bitset<Bits> <B>operator|</B>(const bitset& left, const bitset& right);</PRE><P>The template function returns <CODE>(temp = left) |= right</CODE>,where <CODE>temp</CODE> has type <CODE>bitset<Bits></CODE>.</P><H2><A NAME="operator^"><CODE>operator^</CODE></A></H2><PRE>template<size_t Bits> bitset<Bits> <B>operator^</B>(const bitset& left, const bitset& right);</PRE><P>The template function returns <CODE>(temp = left) ^= right</CODE>,where <CODE>temp</CODE> has type <CODE>bitset<Bits></CODE>.</P><H2><A NAME="operator<<"><CODE>operator<<</CODE></A></H2><PRE>template<class Elem, class Tr, size_t Bits> basic_ostream<Elem, Tr>& <B>operator<<</B>(basic_ostream<Elem, Tr>& ostr, const bitset<Bits>& right);</PRE><P>The template function overloads <CODE>operator<<</CODE>to insert a text representation of the bit sequence in <CODE>ostr</CODE>.It effectively executes <CODE>ostr <<right.<A HREF="#bitset::to_string">to_string</A><Elem,Tr, allocator<Elem> >()</CODE>,then returns <CODE>ostr</CODE>.</P><H2><A NAME="operator>>"><CODE>operator>></CODE></A></H2><PRE>template<class Elem, class Tr, size_t Bits> basic_istream<Elem, Tr>& <B>operator>></B>(basic_istream<Elem, Tr>& istr, bitset<Bits>& right);</PRE><P>The template function overloads <CODE>operator>></CODE>to store in <CODE>right</CODE> the value<CODE>bitset(str)</CODE>, where<CODE>str</CODE> is an object of type<CODE><A HREF="string2.html#basic_string">basic_string</A><Elem,Tr, allocator<Elem> >&</CODE> extractedfrom <CODE>istr</CODE>. The function extracts elements and appendsthem to <CODE>str</CODE> until:</P><UL><LI><CODE>Bits</CODE> elements have been extracted and stored</LI><LI>end-of-file occurs on the input sequence</LI><LI>the next input element is neither <CODE>0</CODE> nor <CODE>1</CODE>,in which case the input element is not extracted</LI></UL><P>If the function stores no characters in <CODE>str</CODE>, it calls<CODE>istr.<A HREF="ios.html#basic_ios::setstate">setstate</A>(ios_base::failbit)</CODE>.In any case, it returns <CODE>istr</CODE>.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pjp.html">Copyright</A> © 1992-2002by P.J. Plauger. All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -