494 lines
19 KiB
HTML
494 lines
19 KiB
HTML
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed
|
|
with this work for additional information regarding copyright
|
|
ownership. The ASF licenses this file to you under the Apache
|
|
License, Version 2.0 (the License); you may not use this file
|
|
except in compliance with the License. You may obtain a copy of
|
|
the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
implied. See the License for the specific language governing
|
|
permissions and limitations under the License.
|
|
|
|
Copyright 1999-2007 Rogue Wave Software, Inc.
|
|
-->
|
|
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>bitset</TITLE>
|
|
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
|
|
<BODY BGCOLOR=#FFFFFF>
|
|
<A HREF="bitmasktypes.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="cerr.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV>
|
|
<H2>bitset</H2>
|
|
<P><B>Library:</B> <A HREF="2-7.html">Containers</A></P>
|
|
|
|
<PRE><HR><B><I>Does not inherit</I></B><HR></PRE>
|
|
|
|
<UL>
|
|
<LI><A HREF="#sec1">Local Index</A></LI>
|
|
<LI><A HREF="#sec2">Summary</A></LI>
|
|
<LI><A HREF="#sec3">Synopsis</A></LI>
|
|
<LI><A HREF="#sec4">Description</A></LI>
|
|
<LI><A HREF="#sec5">Errors and Exceptions</A></LI>
|
|
<LI><A HREF="#sec6">Interface</A></LI>
|
|
<LI><A HREF="#sec7">Constructors</A></LI>
|
|
<LI><A HREF="#sec8">Assignment Operators</A></LI>
|
|
<LI><A HREF="#sec9">Operators</A></LI>
|
|
<LI><A HREF="#sec10">Member Functions</A></LI>
|
|
<LI><A HREF="#sec11">Example</A></LI>
|
|
<LI><A HREF="#sec12">See Also</A></LI>
|
|
<LI><A HREF="#sec13">Standards Conformance</A></LI>
|
|
</UL>
|
|
<A NAME="sec1"><H3>Local Index</H3></A>
|
|
<H4>Members</H4>
|
|
<UL><TABLE CELLPADDING=3>
|
|
<TR><TD VALIGN=top>
|
|
<A HREF="#idx446">any()</A><BR>
|
|
<A HREF="#idx426">bitset()</A><BR>
|
|
<A HREF="#idx447">count()</A><BR>
|
|
<A HREF="#idx448">flip()</A><BR>
|
|
<A HREF="#idx450">none()</A><BR>
|
|
<A HREF="#idx432">operator!=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx441">operator&()</A><BR>
|
|
<A HREF="#idx433">operator&=()</A><BR>
|
|
<A HREF="#idx438">operator>>()</A><BR>
|
|
<A HREF="#idx437">operator>>=()</A><BR>
|
|
<A HREF="#idx439">operator<<()</A><BR>
|
|
<A HREF="#idx436">operator<<=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx430">operator=()</A><BR>
|
|
<A HREF="#idx431">operator==()</A><BR>
|
|
<A HREF="#idx443">operator^()</A><BR>
|
|
<A HREF="#idx435">operator^=()</A><BR>
|
|
<A HREF="#idx442">operator|()</A><BR>
|
|
<A HREF="#idx434">operator|=()</A><BR>
|
|
</TD>
|
|
<TD VALIGN=top><A HREF="#idx440">operator~()</A><BR>
|
|
<A HREF="#idx451">reset()</A><BR>
|
|
<A HREF="#idx453">set()</A><BR>
|
|
<A HREF="#idx455">size()</A><BR>
|
|
<A HREF="#idx456">test()</A><BR>
|
|
<A HREF="#idx457">to_ulong()</A><BR>
|
|
</TD></TR>
|
|
</TABLE></UL>
|
|
|
|
<A NAME="sec2"><H3>Summary</H3></A>
|
|
<P>A class template and related functions for storing and manipulating fixed-size sequences of bits</P>
|
|
<A NAME="sec3"><H3>Synopsis</H3></A>
|
|
|
|
<PRE>#include <bitset>
|
|
|
|
namespace std {
|
|
template <size_t N>
|
|
class bitset;
|
|
}
|
|
</PRE>
|
|
<A NAME="sec4"><H3>Description</H3></A>
|
|
<P><B><I>bitset</I></B> is a class that describes objects that can store a sequence consisting of a fixed number of bits,<SAMP> N.</SAMP> Each bit represents either the value zero (<SAMP>reset</SAMP>) or one (<SAMP>set</SAMP>) and has a non-negative position <SAMP>pos</SAMP>. </P>
|
|
<A NAME="sec5"><H3>Errors and Exceptions</H3></A>
|
|
<P>Bitset constructors and member functions may throw the following exceptions:</P>
|
|
<UL>
|
|
<LI><P CLASS="LIST"><B><I><A HREF="invalid-argument.html">invalid_argument</A></I></B></P></LI>
|
|
<LI><P CLASS="LIST"><B><I><A HREF="out-of-range.html">out_of_range</A></I></B></P></LI>
|
|
<LI><P CLASS="LIST"><B><I><A HREF="overflow-error.html">overflow_error</A></I></B></P></LI>
|
|
</UL>
|
|
<P>If exceptions are not supported on your compiler, you get an assertion failure instead of an exception.</P>
|
|
<A NAME="sec6"><H3>Interface</H3></A>
|
|
|
|
<UL><PRE>namespace std {
|
|
|
|
template <size_t N>
|
|
class bitset {
|
|
|
|
public:
|
|
|
|
// bit reference:
|
|
|
|
class reference {
|
|
friend class bitset;
|
|
public:
|
|
|
|
~reference();
|
|
reference& operator= (bool);
|
|
reference& operator= (const reference&);
|
|
bool operator~() const;
|
|
operator bool() const;
|
|
reference& flip();
|
|
};
|
|
|
|
|
|
// Constructors
|
|
bitset ();
|
|
bitset (unsigned long);
|
|
template<class charT, class traits, class Allocator>
|
|
explicit bitset
|
|
(const basic_string<charT, traits, Allocator>,
|
|
typename basic_string<charT, traits,
|
|
Allocator>::size_type=0,
|
|
typename basic_string<charT, traits
|
|
Allocator>::size_type=
|
|
basic_string<charT, traits, Allocator>::npos);
|
|
bitset (const bitset<N>&);
|
|
bitset<N>& operator= (const bitset<N>&);
|
|
|
|
// Bitwise Operators and Bitwise Operator Assignment
|
|
bitset<N>& operator&= (const bitset<N>&);
|
|
bitset<N>& operator|= (const bitset<N>&);
|
|
bitset<N>& operator^= (const bitset<N>&);
|
|
bitset<N>& operator<<= (size_t);
|
|
bitset<N>& operator>>= (size_t);
|
|
|
|
// Set, Reset, Flip
|
|
bitset<N>& set ();
|
|
bitset<N>& set (size_t, int = true);
|
|
bitset<N>& reset ();
|
|
bitset<N>& reset (size_t);
|
|
bitset<N> operator~() const;
|
|
bitset<N>& flip ();
|
|
bitset<N>& flip (size_t);
|
|
|
|
// element access
|
|
reference operator[] (size_t);
|
|
unsigned long to_ulong() const;
|
|
template<class charT, class traits, class Allocator>
|
|
basic_string<charT, traits, Allocator> to_string() const;
|
|
size_t count() const;
|
|
size_t size() const;
|
|
bool operator== (const bitset<N>&) const;
|
|
bool operator!= (const bitset<N>&) const;
|
|
bool test (size_t) const;
|
|
bool any() const;
|
|
bool none() const;
|
|
bitset<N> operator<< (size_t) const;
|
|
bitset<N> operator>> (size_t) const;
|
|
|
|
};
|
|
|
|
// Nonmember operators
|
|
template <size_t N>
|
|
bitset<N> operator& (const bitset<N>&, const bitset<N>&);
|
|
|
|
template <size_t N>
|
|
bitset<N> operator|(const bitset<N>&, const bitset<N>&);
|
|
|
|
template <size_t N>
|
|
bitset<N> operator^(const bitset<N>&, const bitset<N>&);
|
|
|
|
template <size_t N>
|
|
basic_istream<charT, traits>&
|
|
operator>>(basic_istream<charT, traits>&,
|
|
bitset<N>&);
|
|
|
|
template <size_t N>
|
|
basic_ostream<charT, traits>&
|
|
operator<<(basic_ostream<charT, traits>&,
|
|
const bitset<N>&);
|
|
}
|
|
</PRE></UL>
|
|
<A NAME="sec7"><H3>Constructors</H3></A>
|
|
|
|
<A NAME="idx426"></A><PRE><B>bitset</B>();</PRE>
|
|
<UL>
|
|
<P>Constructs an object of class <SAMP>bitset<N></SAMP>, initializing all bit values to zero.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx427"></A><PRE><B>bitset</B>(unsigned long val);</PRE>
|
|
<UL>
|
|
<P>Constructs an object of class <B><I>bitset</I></B>, initializing the first <SAMP>M</SAMP> bit values to the corresponding bits in <SAMP>val</SAMP>. <SAMP>M</SAMP> is the smaller of <SAMP>N</SAMP> and the value <SAMP>CHAR_BIT * sizeof(unsigned long)</SAMP>. If <SAMP>M < N</SAMP>, remaining bit positions are initialized to zero. Note: <SAMP>CHAR_BIT</SAMP> is defined in <SAMP><climits></SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx428"></A><PRE>template<class charT, class traits, class Allocator>
|
|
explicit
|
|
<B>bitset</B> (const basic_string<charT, traits, Allocator>,
|
|
typename basic_string<charT, traits,
|
|
Allocator>::size_type=0,
|
|
typename basic_string<charT, traits,
|
|
Allocator>::size_type=
|
|
basic_string<charT, traits, Allocator>::npos);</PRE>
|
|
<UL>
|
|
<P>Determines the effective length <SAMP>rlen</SAMP> of the initializing string as the smaller of <SAMP>n</SAMP> and <SAMP>str.size() - pos</SAMP>. The function throws an <B><I><A HREF="invalid-argument.html">invalid_argument</A></I></B> exception if any of the <SAMP>rlen</SAMP> characters in <SAMP>str</SAMP>, beginning at position <SAMP>pos</SAMP>, is other than <SAMP>0</SAMP> or <SAMP>1</SAMP>. Otherwise, the function constructs an object of class <B><I>bitset</I></B>, initializing the first <SAMP>M</SAMP> bit positions to values determined from the corresponding characters in the string <SAMP>str</SAMP>. <SAMP>M</SAMP> is the smaller of <SAMP>N</SAMP> and <SAMP>rlen</SAMP>. This constructor expects <SAMP>pos <= str.size()</SAMP>. If that is not <SAMP>true</SAMP>, the constructor throws an <B><I><A HREF="out-of-range.html">out_of_range</A></I></B> exception.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx429"></A><PRE><B>bitset</B>(const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P>Creates a copy of <SAMP>rhs</SAMP>.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec8"><H3>Assignment Operators</H3></A>
|
|
|
|
<A NAME="idx430"></A><PRE>bitset<N>&
|
|
<B>operator=</B>(const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P>Erases all bits in self, then inserts into self a copy of each bit in <SAMP>rhs</SAMP>. Returns a reference to <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec9"><H3>Operators</H3></A>
|
|
|
|
<A NAME="idx431"></A><PRE>bool
|
|
<B>operator==</B>(const bitset<N>& rhs) const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>true</SAMP> if the value of each bit in <SAMP>*this</SAMP> equals the value of each corresponding bit in <SAMP>rhs</SAMP>. Otherwise returns <SAMP>false</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx432"></A><PRE>bool
|
|
<B>operator!=</B>(const bitset<N>& rhs) const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>true</SAMP> if the value of any bit in <SAMP>*this</SAMP> is not equal to the value of the corresponding bit in <SAMP>rhs</SAMP>. Otherwise returns <SAMP>false</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx433"></A><PRE>bitset<N>&
|
|
<B>operator&=</B>(const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P>Clears each bit in <SAMP>*this</SAMP> for which the corresponding bit in <SAMP>rhs</SAMP> is clear and leaves all other bits unchanged. Returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx434"></A><PRE>bitset<N>&
|
|
<B>operator|=</B>(const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P>Sets each bit in <SAMP>*this</SAMP> for which the corresponding bit in <SAMP>rhs</SAMP> is set, and leaves all other bits unchanged. Returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx435"></A><PRE>bitset<N>&
|
|
<B>operator^=</B>(const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P>Toggles each bit in <SAMP>*this</SAMP> for which the corresponding bit in <SAMP>rhs</SAMP> is set, and leaves all other bits unchanged. Returns <SAMP>*this</SAMP>. </P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx436"></A><PRE>bitset<N>&
|
|
<B>operator<<=</B>(size_t pos);</PRE>
|
|
<UL>
|
|
<P>Replaces each bit at position <SAMP>I</SAMP> with <SAMP>0</SAMP> if <SAMP>I < pos</SAMP> or with the value of the bit at<SAMP> I - pos</SAMP> if <SAMP>I >= pos</SAMP>. Returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx437"></A><PRE>bitset<N>&
|
|
<B>operator>>=</B>(size_t pos);</PRE>
|
|
<UL>
|
|
<P>Replaces each bit at position <SAMP>I</SAMP> with <SAMP>0</SAMP> if <SAMP>pos >= N-I</SAMP> or with the value of the bit at position <SAMP>I + pos</SAMP> if <SAMP>pos < N-I</SAMP>. Returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx438"></A><PRE>bitset<N>&
|
|
<B>operator>></B>(size_t pos) const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>bitset<N>(*this) >>= pos</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx439"></A><PRE>bitset<N>&
|
|
<B>operator<<</B>(size_t pos) const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>bitset<N>(*this) <<= pos</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx440"></A><PRE>bitset<N>
|
|
<B>operator~</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns the <B><I>bitset</I></B> that is the logical complement of each bit in <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx441"></A><PRE>bitset<N>
|
|
<B>operator&</B>(const bitset<N>& lhs,
|
|
const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P><SAMP>lhs</SAMP> gets logical <SAMP>AND</SAMP> of <SAMP>lhs</SAMP> with <SAMP>rhs</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx442"></A><PRE>bitset<N>
|
|
<B>operator|</B>(const bitset<N>& lhs,
|
|
const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P><SAMP>lhs</SAMP> gets logical <SAMP>OR</SAMP> of <SAMP>lhs</SAMP> with <SAMP>rhs</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx443"></A><PRE>bitset<N>
|
|
<B>operator^</B>(const bitset<N>& lhs,
|
|
const bitset<N>& rhs);</PRE>
|
|
<UL>
|
|
<P><SAMP>lhs</SAMP> gets logical <SAMP>XOR</SAMP> of <SAMP>lhs</SAMP> with <SAMP>rhs</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx444"></A><PRE>template <size_t N>
|
|
basic_istream<charT, traits>m&
|
|
<B>operator>></B>(basic_istream<charT, traits>& is, bitset<N>& x);</PRE>
|
|
<UL>
|
|
<P>Extracts up to <SAMP>N</SAMP> characters (single-byte) from <SAMP>is</SAMP>. Stores these characters in a temporary object <SAMP>str</SAMP> of type <SAMP>string</SAMP>, then evaluates the expression <SAMP>x = bitset<N>(str)</SAMP>. Characters are extracted and stored until any of the following occurs:</P>
|
|
<UL>
|
|
<LI><P CLASS="LIST"><SAMP>N</SAMP> characters have been extracted and stored</P></LI>
|
|
<LI><P CLASS="LIST">An end-of-file is reached on the input sequence</P></LI>
|
|
<LI><P CLASS="LIST">The next character is neither '0' nor '1'. In this case, the character is not extracted</P></LI>
|
|
</UL>
|
|
<P>Returns <SAMP>is</SAMP>. If no characters are extracted and stored, calls <SAMP>is.setstate(ios::failbit)</SAMP> (which may throw <B><I><A HREF="ios-base.html#failure">ios_base::failure</A></I></B>).</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx445"></A><PRE>template <size_t N>
|
|
basic_ostream<charT, traits>&
|
|
<B>operator<<</B>(basic_ostream<charT, traits>& os, const bitset<N>& x);</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>os << x.to_string()</SAMP>.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec10"><H3>Member Functions</H3></A>
|
|
|
|
<A NAME="idx446"></A><PRE>bool
|
|
<B>any</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>true</SAMP> if any bit in <SAMP>*this</SAMP> is set. Otherwise returns <SAMP>false</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx447"></A><PRE>size_t
|
|
<B>count</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns a count of the number of bits set in <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx448"></A><PRE>bitset<N>&
|
|
<B>flip</B>();</PRE>
|
|
<UL>
|
|
<P>Flips all bits in <SAMP>*this</SAMP>, and returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx449"></A><PRE>bitset<N>&
|
|
<B>flip</B>(size_t pos);</PRE>
|
|
<UL>
|
|
<P>Flips the bit at position <SAMP>pos</SAMP> in <SAMP>*this</SAMP> and returns <SAMP>*this</SAMP>. Throws an <B><I><A HREF="out-of-range.html">out_of_range</A></I></B> exception if <SAMP>pos</SAMP> does not correspond to a valid bit position.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx450"></A><PRE>bool
|
|
<B>none</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>true</SAMP> if no bit in <SAMP>*this</SAMP> is set. Otherwise returns <SAMP>false</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx451"></A><PRE>bitset<N>&
|
|
<B>reset</B>();</PRE>
|
|
<UL>
|
|
<P>Resets all bits in <SAMP>*this</SAMP>, and returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx452"></A><PRE>bitset<N>&
|
|
<B>reset</B>(size_t pos);</PRE>
|
|
<UL>
|
|
<P>Resets the bit at position <SAMP>pos</SAMP> in <SAMP>*this</SAMP>. Throws an <B><I><A HREF="out-of-range.html">out_of_range</A></I></B> exception if <SAMP>pos</SAMP> does not correspond to a valid bit position.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx453"></A><PRE>bitset<N>&
|
|
<B>set</B>();</PRE>
|
|
<UL>
|
|
<P>Sets all bits in <SAMP>*this</SAMP>, and returns <SAMP>*this</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx454"></A><PRE>bitset<N>&
|
|
<B>set</B>(size_t pos, bool val = true);</PRE>
|
|
<UL>
|
|
<P>Stores a new value in the bit at position <SAMP>pos</SAMP> in <SAMP>*this.</SAMP> If <SAMP>val</SAMP> is nonzero, the stored value is one, otherwise it is zero. Throws an <B><I><A HREF="out-of-range.html">out_of_range</A></I></B> exception if <SAMP>pos</SAMP> does not correspond to a valid bit position.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx455"></A><PRE>size_t
|
|
<B>size</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns the template parameter <SAMP>N</SAMP>.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx456"></A><PRE>bool
|
|
<B>test</B>(size_t pos) const;</PRE>
|
|
<UL>
|
|
<P>Returns <SAMP>true</SAMP> if the bit at position <SAMP>pos</SAMP> is set. Throws an <B><I><A HREF="out-of-range.html">out_of_range</A></I></B> exception if <SAMP>pos</SAMP> does not correspond to a valid bit position.</P>
|
|
|
|
<UL><PRE>template<class charT, class traits, class Allocator>
|
|
basic_string<charT, traits, Allocator>
|
|
<B>to_string</B>() const;
|
|
</PRE></UL>
|
|
<P>Returns an object of type <SAMP>basic_string</SAMP>, <SAMP>N</SAMP> characters long.</P>
|
|
<P>Each position in the new string is initialized with a character ('0' for zero and '1' for one) representing the value stored in the corresponding bit position of <SAMP>*this</SAMP>. Character position <SAMP>N - 1</SAMP> corresponds to bit position 0. Subsequent decreasing character positions correspond to increasing bit positions.</P>
|
|
</UL>
|
|
|
|
|
|
<A NAME="idx457"></A><PRE>unsigned long
|
|
<B>to_ulong</B>() const;</PRE>
|
|
<UL>
|
|
<P>Returns the integral value corresponding to the bits in <SAMP>*this</SAMP>. Throws an <B><I><A HREF="overflow-error.html">overflow_error</A></I></B> if these bits cannot be represented as type <SAMP>unsigned long</SAMP>.</P>
|
|
</UL>
|
|
|
|
<A NAME="sec11"><H3>Example</H3></A>
|
|
|
|
<UL><PRE>//
|
|
// bitset.cpp
|
|
//
|
|
|
|
#include <bitset> // for bitset
|
|
#include <iostream> // for cout, endl
|
|
|
|
|
|
int main ()
|
|
{
|
|
// Construct a bitset with 8 elements
|
|
// all initioalized to 0.
|
|
std::bitset<8> b;
|
|
|
|
// Bitwise or bitset with 5.
|
|
b |= 5;
|
|
|
|
// Write bitset to cout.
|
|
std::cout << b << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
Program Output:
|
|
</PRE></UL>
|
|
<UL><PRE></PRE></UL>
|
|
<P>00000101</P>
|
|
<A NAME="sec12"><H3>See Also</H3></A>
|
|
<P><A HREF="containers.html">Containers</A></P>
|
|
<A NAME="sec13"><H3>Standards Conformance</H3></A>
|
|
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 23.3.5</I></P>
|
|
|
|
|
|
<BR>
|
|
<HR>
|
|
<A HREF="bitmasktypes.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="cerr.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
|
|
|
|
<!-- Google Analytics tracking code -->
|
|
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
|
</script>
|
|
<script type="text/javascript">
|
|
_uacct = "UA-1775151-1";
|
|
urchinTracker();
|
|
</script>
|
|
<!-- end of Google Analytics tracking code -->
|
|
|
|
</BODY>
|
|
</HTML>
|