Apply patch for [CVE-2012-2677][boost] ordered_malloc() overflow
[external/boost.git] / libs / dynamic_bitset / dynamic_bitset.html
1 <?xml version="1.0" encoding="ascii"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
5
6 <!--
7                      Copyright (c) 2001 Jeremy Siek
8               Copyright (c) 2003-2004, 2008 Gennaro Prota
9
10        Distributed under the Boost Software License, Version 1.0.
11           (See accompanying file LICENSE_1_0.txt or copy at
12                 http://www.boost.org/LICENSE_1_0.txt)
13 -->
14
15 <!--
16    Copyright (c) 1996-1999
17    Silicon Graphics Computer Systems, Inc.
18
19    Permission to use, copy, modify, distribute and sell this software
20    and its documentation for any purpose is hereby granted without fee,
21    provided that the above copyright notice appears in all copies and
22    that both that copyright notice and this permission notice appear
23    in supporting documentation.  Silicon Graphics makes no
24    representations about the suitability of this software for any
25    purpose.  It is provided "as is" without express or implied warranty.
26
27    Copyright (c) 1994
28    Hewlett-Packard Company
29
30    Permission to use, copy, modify, distribute and sell this software
31    and its documentation for any purpose is hereby granted without fee,
32    provided that the above copyright notice appears in all copies and
33    that both that copyright notice and this permission notice appear
34    in supporting documentation.  Hewlett-Packard Company makes no
35    representations about the suitability of this software for any
36    purpose.  It is provided "as is" without express or implied warranty.
37
38   -->
39 <head>
40 <title>dynamic_bitset&lt;Block, Allocator&gt;</title>
41 <link rel="stylesheet" type="text/css" href="../../rst.css" />
42 </head>
43
44 <body>
45 <div id="body">
46 <div id="body-inner">
47 <div id="content">
48 <div class="section" id="docs">
49 <div class="section-0">
50 <div class="section-body">
51
52 <div id="boost-logo"><img src="../../boost.png" alt="Boost C++ Libraries" /></div>
53 <h1>dynamic_bitset&lt;Block, Allocator&gt;</h1>
54 <h2>Contents</h2>
55
56 <dl class="index">
57 <dt><a href="#description">Description</a></dt>
58 <dt><a href="#synopsis">Synopsis</a></dt>
59 <dt><a href="#definitions">Definitions</a></dt>
60 <dt><a href="#examples">Examples</a></dt>
61 <dt><a href="#rationale">Rationale</a></dt>
62 <dt><a href="#header-files">Header Files</a></dt>
63 <dt><a href="#template-parameters">Template Parameters</a></dt>
64 <dt><a href="#concepts-modeled">Concepts modeled</a></dt>
65
66 <dt><a href="#type-requirements">Type requirements</a></dt>
67 <dt><a href="#public-base-classes">Public base classes</a></dt>
68 <dt><a href="#nested-type-names">Nested type names</a></dt>
69 <dt><a href="#public-data-members">Public data members</a></dt>
70 <dt><a href="#constructors">Constructors</a></dt>
71 <dt><a href="#destructor">Destructor</a></dt>
72 <dt><a href="#member-functions">Member functions</a></dt>
73 <dt><a href="#non-member-functions">Non-member functions</a></dt>
74 <dt><a href="#exception-guarantees">Exception guarantees</a></dt>
75
76 <dt><a href="#changes-from-previous-ver"><b>Changes from previous version(s)</b></a></dt>
77 <dt><a href="#see-also">See also</a></dt>
78 <dt><a href="#acknowledgements">Acknowledgements</a></dt>
79 </dl>
80 <h3><a id="description">Description</a></h3>
81 <p>The <tt>dynamic_bitset</tt> class represents a set of bits. It
82 provides accesses to the value of individual bits via an
83 <tt>operator[]</tt> and provides all of the bitwise operators
84 that one can apply to builtin integers, such as
85 <tt>operator&amp;</tt> and <tt>operator&lt;&lt;</tt>. The number
86 of bits in the set is specified at runtime via a parameter to the
87 constructor of the <tt>dynamic_bitset</tt>.</p>
88
89 <p>The <tt>dynamic_bitset</tt> class is nearly identical to the
90 <a href=
91 "http://www.sgi.com/tech/stl/bitset.html"><tt>std::bitset</tt></a>
92 class. The difference is that the size of the
93 <tt>dynamic_bitset</tt> (the number of bits) is specified at
94 run-time during the construction of a <tt>dynamic_bitset</tt>
95 object, whereas the size of a <tt>std::bitset</tt> is specified
96 at compile-time through an integer template parameter.</p>
97
98 <p>The main problem that <tt>dynamic_bitset</tt> is designed to
99 solve is that of representing a subset of a finite set. Each bit
100 represents whether an element of the finite set is in the subset
101 or not. As such the bitwise operations of
102 <tt>dynamic_bitset</tt>, such as <tt>operator&amp;</tt> and
103 <tt>operator|</tt>, correspond to set operations, such as
104 intersection and union.</p>
105 <h3><a id ="synopsis">Synopsis</a></h3>
106 <pre>
107 namespace boost {
108
109 template &lt;typename Block, typename Allocator&gt;
110 class dynamic_bitset
111 {
112 public:
113     typedef Block <a href="#block_type">block_type</a>;
114     typedef Allocator <a href="#allocator_type">allocator_type</a>;
115     typedef <i>implementation-defined</i> <a href="#size_type">size_type</a>;
116
117     static const int <a href=
118        "#bits_per_block">bits_per_block</a> = <i>implementation-defined</i>;
119     static const size_type <a href=
120           "#npos">npos</a> = <i>implementation-defined</i>;
121
122     class <a href="#reference">reference</a>
123     {
124         void operator&amp;(); // not defined
125
126     public:
127         // An automatically generated copy constructor.
128
129         reference&amp; operator=(bool value);
130         reference&amp; operator=(const reference&amp; rhs);
131
132         reference&amp; operator|=(bool value);
133         reference&amp; operator&amp;=(bool value);
134         reference&amp; operator^=(bool value);
135         reference&amp; operator-=(bool value);
136
137         bool operator~() const;
138         operator bool() const;
139         reference&amp; flip();
140     };
141
142     typedef bool <a href="#const_reference">const_reference</a>;
143
144     explicit <a href=
145 "#cons1">dynamic_bitset</a>(const Allocator&amp; alloc = Allocator());
146
147     explicit <a href=
148 "#cons2">dynamic_bitset</a>(size_type num_bits, unsigned long value = 0,
149                             const Allocator&amp; alloc = Allocator());
150
151     template &lt;typename CharT, typename Traits, typename Alloc&gt;
152     explicit <a href=
153 "#cons3">dynamic_bitset</a>(const std::basic_string&lt;CharT, Traits, Alloc&gt;&amp; s,
154         typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type pos = 0,
155         typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type n = std::basic_string&lt;CharT, Traits, Alloc&gt;::npos,
156         const Allocator&amp; alloc = Allocator());
157
158     template &lt;typename BlockInputIterator&gt;
159     <a href=
160 "#cons4">dynamic_bitset</a>(BlockInputIterator first, BlockInputIterator last,
161                    const Allocator&amp; alloc = Allocator());
162
163     <a href=
164 "#cons5">dynamic_bitset</a>(const dynamic_bitset&amp; b);
165
166     void <a href="#swap">swap</a>(dynamic_bitset&amp; b);
167
168     dynamic_bitset&amp; <a href=
169 "#assign">operator=</a>(const dynamic_bitset&amp; b);
170
171     allocator_type <a href="#get_allocator">get_allocator()</a> const;
172
173     void <a href=
174 "#resize">resize</a>(size_type num_bits, bool value = false);
175     void <a href="#clear">clear</a>();
176     void <a href="#push_back">push_back</a>(bool bit);
177     void <a href="#append1">append</a>(Block block);
178
179     template &lt;typename BlockInputIterator&gt;
180     void <a href="#append2">append</a>(BlockInputIterator first, BlockInputIterator last);
181
182     dynamic_bitset&amp; <a href="#op-and-assign">operator&amp;=</a>(const dynamic_bitset&amp; b);
183     dynamic_bitset&amp; <a href="#op-or-assign">operator|=</a>(const dynamic_bitset&amp; b);
184     dynamic_bitset&amp; <a href="#op-xor-assign">operator^=</a>(const dynamic_bitset&amp; b);
185     dynamic_bitset&amp; <a href="#op-sub-assign">operator-=</a>(const dynamic_bitset&amp; b);
186     dynamic_bitset&amp; <a href="#op-sl-assign">operator&lt;&lt;=</a>(size_type n);
187     dynamic_bitset&amp; <a href="#op-sr-assign">operator&gt;&gt;=</a>(size_type n);
188     dynamic_bitset <a href="#op-sl">operator&lt;&lt;</a>(size_type n) const;
189     dynamic_bitset <a href="#op-sr">operator&gt;&gt;</a>(size_type n) const;
190
191     dynamic_bitset&amp; <a href="#set2">set</a>(size_type n, bool val = true);
192     dynamic_bitset&amp; <a href="#set1">set</a>();
193     dynamic_bitset&amp; <a href="#reset2">reset</a>(size_type n);
194     dynamic_bitset&amp; <a href="#reset1">reset</a>();
195     dynamic_bitset&amp; <a href="#flip2">flip</a>(size_type n);
196     dynamic_bitset&amp; <a href="#flip1">flip</a>();
197     bool <a href="#test">test</a>(size_type n) const;
198     bool <a href="#any">any</a>() const;
199     bool <a href="#none">none</a>() const;
200     dynamic_bitset <a href="#op-not">operator~</a>() const;
201     size_type <a href="#count">count</a>() const;
202
203     reference <a href="#bracket">operator[]</a>(size_type pos);
204     bool <a href="#const-bracket">operator[]</a>(size_type pos) const;
205
206     unsigned long <a href="#to_ulong">to_ulong</a>() const;
207
208     size_type <a href="#size">size</a>() const;
209     size_type <a href="#num_blocks">num_blocks</a>() const;
210     size_type <a href="#max_size">max_size</a>() const;
211     bool <a href="#empty">empty</a>() const;
212
213     bool <a href="#is_subset_of">is_subset_of</a>(const dynamic_bitset&amp; a) const;
214     bool <a href="#is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset&amp; a) const;
215     bool <a href="#intersects">intersects</a>(const dynamic_bitset&amp; a) const;
216
217     size_type <a href="#find_first">find_first</a>() const;
218     size_type <a href="#find_next">find_next</a>(size_type pos) const;
219
220 };
221
222
223 template &lt;typename B, typename A&gt;
224 bool <a href=
225 "#op-equal">operator==</a>(const dynamic_bitset&lt;B, A&gt;&amp; a, const dynamic_bitset&lt;B, A&gt;&amp; b);
226
227 template &lt;typename Block, typename Allocator&gt;
228 bool <a href=
229 "#op-not-equal">operator!=</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; a, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
230
231 template &lt;typename B, typename A&gt;
232 bool <a href=
233 "#op-less">operator&lt;</a>(const dynamic_bitset&lt;B, A&gt;&amp; a, const dynamic_bitset&lt;B, A&gt;&amp; b);
234
235 template &lt;typename Block, typename Allocator&gt;
236 bool <a href=
237 "#op-less-equal">operator&lt;=</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; a, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
238
239 template &lt;typename Block, typename Allocator&gt;
240 bool <a href=
241 "#op-greater">operator&gt;</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; a, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
242
243 template &lt;typename Block, typename Allocator&gt;
244 bool <a href=
245 "#op-greater-equal">operator&gt;=</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; a, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
246
247 template &lt;typename Block, typename Allocator&gt;
248 dynamic_bitset&lt;Block, Allocator&gt;
249 <a href=
250 "#op-and">operator&amp;</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b1, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b2);
251
252 template &lt;typename Block, typename Allocator&gt;
253 dynamic_bitset&lt;Block, Allocator&gt;
254 <a href=
255 "#op-or">operator|</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b1, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b2);
256
257 template &lt;typename Block, typename Allocator&gt;
258 dynamic_bitset&lt;Block, Allocator&gt;
259 <a href=
260 "#op-xor">operator^</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b1, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b2);
261
262 template &lt;typename Block, typename Allocator&gt;
263 dynamic_bitset&lt;Block, Allocator&gt;
264 <a href=
265 "#op-sub">operator-</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b1, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b2);
266
267 template &lt;typename Block, typename Allocator, typename CharT, typename Alloc&gt;
268 void <a href=
269 "#to_string">to_string</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b,
270           std::basic_string&lt;CharT, Alloc&gt;&amp; s);
271
272 template &lt;typename Block, typename Allocator, typename BlockOutputIterator&gt;
273 void <a href=
274 "#to_block_range">to_block_range</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b,
275                     BlockOutputIterator result);
276
277 template &lt;typename CharT, typename Traits, typename Block, typename Allocator&gt;
278 std::basic_ostream&lt;CharT, Traits&gt;&amp;
279 <a href=
280 "#op-out">operator&lt;&lt;</a>(std::basic_ostream&lt;CharT, Traits&gt;&amp; os, const dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
281
282 template &lt;typename CharT, typename Traits, typename Block, typename Allocator&gt;
283 std::basic_istream&lt;CharT, Traits&gt;&amp;
284 <a href=
285 "#op-in">operator&gt;&gt;</a>(std::basic_istream&lt;CharT, Traits&gt;&amp; is, dynamic_bitset&lt;Block, Allocator&gt;&amp; b);
286
287 } // namespace boost
288 </pre>
289
290 <h3><a id="definitions">Definitions</a></h3>
291
292 <p>Each bit represents either the Boolean value true or false (1
293 or 0). To <i>set</i> a bit is to assign it 1. To <i>clear</i> or
294 <i>reset</i> a bit is to assign it 0. To <i>flip</i> a bit is to
295 change the value to 1 if it was 0 and to 0 if it was 1. Each bit
296 has a non-negative <i>position</i>. A bitset <tt>x</tt> contains
297 <tt>x.size()</tt> bits, with each bit assigned a unique position
298 in the range <tt>[0,x.size())</tt>. The bit at position 0 is
299 called the <i>least significant bit</i> and the bit at position
300 <tt>size() - 1</tt> is the <i>most significant bit</i>. When
301 converting an instance of <tt>dynamic_bitset</tt> to or from an
302 unsigned long <tt>n</tt>, the bit at position <tt>i</tt> of the
303 bitset has the same value as <tt>(n &gt;&gt; i) &amp; 1</tt>.</p>
304
305 <h3><a id="examples">Examples</a></h3>
306
307 <p>
308 <a href="./example/example1.cpp">Example 1</a> (setting
309 and reading some bits)
310 </p>
311 <p>
312 <a href="./example/example2.cpp">Example 2</a> (creating
313 some bitsets from integers)
314 </p>
315
316 <p>
317 <a href="./example/example3.cpp">Example 3</a> (performing
318 input/output and some bitwise operations).
319 </p>
320
321
322 <h3><a id="rationale">Rationale</a></h3>
323 <p>
324 <tt>dynamic_bitset</tt> is not a <a href=
325 "http://www.sgi.com/tech/stl/Container.html">Container</a> and
326 does not provide iterators for the following reason:
327 </p>
328
329 <ul>
330 <li>A container with a proxy <tt>reference</tt> type can not
331 fulfill the container requirements as specified in the C++
332 standard (unless one resorts to strange iterator semantics).
333 <tt>std::vector&lt;bool&gt;</tt> has a proxy <tt>reference</tt>
334 type and does not fulfill the container requirements and as a
335 result has caused many problems. One common problem is when
336 people try to use iterators from <tt>std::vector&lt;bool&gt;</tt>
337 with a Standard algorithm such as <tt>std::search</tt>. The
338 <tt>std::search</tt> requirements say that the iterator must be a
339 <a href=
340 "http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
341 Iterator</a>, but the <tt>std::vector&lt;bool&gt;::iterator</tt>
342 does not meet this requirement because of the proxy reference.
343 Depending on the implementation, they may or not be a compile
344 error or even a run-time error due to this misuse. For further
345 discussion of the problem see <i>Effective STL</i> by Scott
346 Meyers). So <tt>dynamic_bitset</tt> tries to avoid these problems
347 by not pretending to be a container.</li>
348 </ul>
349
350 <p>Some people prefer the name "toggle" to "flip". The name
351 "flip" was chosen because that is the name used in <a href=
352 "http://www.sgi.com/tech/stl/bitset.html"><tt>std::bitset</tt></a>.
353 In fact, most of the function names for <tt>dynamic_bitset</tt>
354 were chosen for this reason.</p>
355
356 <p><tt>dynamic_bitset</tt> does not throw exceptions when a
357 precondition is violated (as is done in <tt>std::bitset</tt>).
358 Instead <tt>assert</tt> is used. See the guidelines for <a href=
359 "http://www.boost.org/more/error_handling.html">Error and Exception Handling</a>
360 for the explanation.</p>
361
362 <h3><a id="header-files">Header Files</a></h3>
363
364 <p>The class <tt>dynamic_bitset</tt> is defined in the header <a
365 href=
366 "../../boost/dynamic_bitset.hpp">boost/dynamic_bitset.hpp</a>.
367 Also, there is a forward declaration for <tt>dynamic_bitset</tt>
368 in the header <a href=
369 "../../boost/dynamic_bitset_fwd.hpp">boost/dynamic_bitset_fwd.hpp</a>.</p>
370
371 <h3><a id="template-parameters">Template parameters</a></h3>
372
373 <table summary=
374 "Describes the meaning of the template parameters and lists their corresponding default arguments">
375 <tr>
376 <th>Parameter</th>
377 <th>Description</th>
378 <th>Default</th>
379 </tr>
380 <tr>
381 <td><tt>Block</tt></td>
382 <td>The integer type in which the bits are stored.</td>
383 <td><tt>unsigned long</tt></td>
384 </tr>
385 <tr>
386
387 <td><tt>Allocator</tt></td>
388 <td>The allocator type used for all internal memory management.</td>
389 <td><tt>std::allocator&lt;Block&gt;</tt></td>
390 </tr>
391 </table>
392 <h3><a id="concepts-modeled">Concepts Modeled</a></h3>
393 <a href=
394 "http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>, <a
395 href=
396 "http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
397 Constructible</a>, <a href=
398 "http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
399 Comparable</a>, <a href=
400 "http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
401 Comparable</a>.
402
403 <h3><a id="type-requirements">Type requirements</a></h3>
404
405 <tt>Block</tt> is an unsigned integer type. <tt>Allocator</tt>
406 satisfies the Standard requirements for an allocator.
407
408 <h3><a id="public-base-classes">Public base classes</a></h3>
409
410 None.
411 <h3><a id="nested-type-names">Nested type names</a></h3>
412 <hr />
413
414 <pre>
415 <a id="reference">dynamic_bitset::reference</a>
416 </pre>
417
418 <p>A proxy class that acts as a reference to a single bit. It
419 contains an assignment operator, a conversion to <tt>bool</tt>,
420 an <tt>operator~</tt>, and a member function <tt>flip</tt>. It
421 exists only as a helper class for <tt>dynamic_bitset</tt>'s
422 <tt>operator[]</tt>. The following table describes the valid
423 operations on the <tt>reference</tt> type. Assume that <tt>b</tt>
424 is an instance of <tt>dynamic_bitset</tt>, <tt>i, j</tt> are of
425 <tt>size_type</tt> and in the range <tt>[0,b.size())</tt>. Also,
426 note that when we write <tt>b[i]</tt> we mean an object of type
427 <tt>reference</tt> that was initialized from <tt>b[i]</tt>. The
428 variable <tt>x</tt> is a <tt>bool</tt>.</p>
429
430 <table border="1" summary=
431 "Semantics of several expressions involving usage of dynamic_bitset::reference">
432 <tr>
433 <th>Expression</th>
434 <th>Semantics</th>
435 </tr>
436 <tr>
437 <td><tt>x = b[i]</tt></td>
438 <td>Assign the ith bit of <tt>b</tt> to <tt>x</tt>.</td>
439 </tr>
440 <tr>
441 <td><tt>(bool)b[i]</tt></td>
442 <td>Return the ith bit of <tt>b</tt>.</td>
443 </tr>
444 <tr>
445 <td><tt>b[i] = x</tt></td>
446 <td>Set the ith bit of <tt>b</tt> to the value of <tt>x</tt> and
447 return <tt>b[i]</tt>.</td>
448 </tr>
449 <tr>
450 <td><tt>b[i] |= x</tt></td>
451 <td>Or the ith bit of <tt>b</tt> with the value of <tt>x</tt> and
452 return <tt>b[i]</tt>.</td>
453 </tr>
454 <tr>
455 <td><tt>b[i] &amp;= x</tt></td>
456 <td>And the ith bit of <tt>b</tt> with the value of <tt>x</tt>
457 and return <tt>b[i]</tt>.</td>
458 </tr>
459
460 <tr>
461 <td><tt>b[i] ^= x</tt></td>
462 <td>Exclusive-Or the ith bit of <tt>b</tt> with the value of
463 <tt>x</tt> and return <tt>b[i]</tt>.</td>
464 </tr>
465
466 <tr>
467 <td><tt>b[i] -= x</tt></td>
468 <td>If <tt>x==true</tt>, clear the ith bit of <tt>b</tt>. Returns
469 <tt>b[i]</tt>.</td>
470 </tr>
471
472 <tr>
473 <td><tt>b[i] = b[j]</tt></td>
474 <td>Set the ith bit of <tt>b</tt> to the value of the jth bit of
475 <tt>b</tt> and return <tt>b[i]</tt>.</td>
476 </tr>
477
478 <tr>
479 <td><tt>b[i] |= b[j]</tt></td>
480 <td>Or the ith bit of <tt>b</tt> with the jth bit of <tt>b</tt>
481 and return <tt>b[i]</tt>.</td>
482 </tr>
483
484 <tr>
485 <td><tt>b[i] &amp;= b[j]</tt></td>
486 <td>And the ith bit of <tt>b</tt> with the jth bit of <tt>b</tt> and return <tt>b[i]</tt>.</td>
487 </tr>
488 <tr>
489 <td><tt>b[i] ^= b[j]</tt></td>
490 <td>Exclusive-Or the ith bit of <tt>b</tt> with the jth bit of <tt>b</tt> and return <tt>b[i]</tt>.</td>
491
492 </tr>
493 <tr>
494 <td><tt>b[i] -= b[j]</tt></td>
495 <td>If the jth bit of <tt>b</tt> is set, clear the ith bit of <tt>b</tt>. Returns <tt>b[i]</tt>.</td>
496 </tr>
497 <tr>
498 <td><tt>x = ~b[i]</tt></td>
499
500 <td>Assign the opposite of the ith bit of <tt>b</tt> to <tt>x</tt>.</td>
501 </tr>
502 <tr>
503 <td><tt>(bool)~b[i]</tt></td>
504 <td>Return the opposite of the ith bit of <tt>b</tt>.</td>
505 </tr>
506 <tr>
507
508 <td><tt>b[i].flip()</tt></td>
509 <td>Flip the ith bit of <tt>b</tt> and return <tt>b[i]</tt>.</td>
510 </tr>
511 </table>
512 <hr />
513 <pre>
514 <a id="const_reference">dynamic_bitset::const_reference</a>
515 </pre>
516 The type <tt>bool</tt>.
517
518 <pre>
519 <a id="size_type">dynamic_bitset::size_type</a>
520 </pre>
521 The unsigned integer type for representing the size of the bit set.
522
523 <pre>
524 <a id="block_type">dynamic_bitset::block_type</a>
525 </pre>
526 The same type as <tt>Block</tt>.
527
528 <pre>
529 <a id="allocator_type">dynamic_bitset::allocator_type;</a>
530 </pre>
531 The same type as <tt>Allocator</tt>.
532
533
534 <hr />
535 <h3><a id="public-data-members">Public data members</a></h3>
536
537 <pre>
538 <a id="bits_per_block">dynamic_bitset::bits_per_block</a>
539 </pre>
540 The number of bits the type <tt>Block</tt> uses to represent values,
541 excluding any padding bits. Numerically equal
542 to <tt>std::numeric_limits&lt;Block&gt;::digits</tt>.
543
544 <pre>
545 <a id="npos">dynamic_bitset::npos</a>
546 </pre>
547 The maximum value of <tt>size_type</tt>.
548
549 <hr />
550 <h3><a id="constructors">Constructors</a></h3>
551
552 <hr />
553 <pre>
554 <a id=
555 "cons1">dynamic_bitset</a>(const Allocator&amp; alloc = Allocator())
556 </pre>
557
558 <b>Effects:</b> Constructs a bitset of size zero. A copy of the
559 <tt>alloc</tt> object will be used in subsequent bitset
560 operations such as <tt>resize</tt> to allocate memory.<br />
561  <b>Postconditions:</b> <tt>this-&gt;size() == 0</tt>.<br />
562  <b>Throws:</b> An allocation error if memory is exhausted
563 (<tt>std::bad_alloc</tt> if
564 <tt>Allocator=std::allocator</tt>).<br />
565  (Required by <a href=
566 "http://www.sgi.com/tech/stl/DefaultConstructible.html">Default
567 Constructible</a>.)
568
569 <hr />
570 <pre>
571 <a id="cons2">dynamic_bitset</a>(size_type num_bits,
572                unsigned long value = 0,
573                const Allocator&amp; alloc = Allocator())
574 </pre>
575
576 <b>Effects:</b> Constructs a bitset from an integer. The first
577 <tt>M</tt> bits are initialized to the corresponding bits in
578 <tt>value</tt> and all other bits, if any, to zero (where <tt>M =
579 min(num_bits, std::numeric_limits&lt;unsigned long&gt;::digits)</tt>). A copy of
580 the <tt>alloc</tt> object will be used in subsequent bitset
581 operations such as <tt>resize</tt> to allocate memory. Note that, e.g., the
582 following
583 <br /><br />
584 <tt>
585 dynamic_bitset b<>( 16, 7 );
586 </tt><br /><br />
587 will match the <a href="#cons4">constructor from an iterator range</a> (not this
588 one), but the underlying implementation will still "do the right thing" and
589 construct a bitset of 16 bits, from the value 7.
590 <br />
591 <b>Postconditions:</b>
592
593 <ul>
594 <li><tt>this-&gt;size() == num_bits</tt></li>
595
596 <li>For all <tt>i</tt> in the range <tt>[0,M)</tt>,
597 <tt>(*this)[i] == (value &gt;&gt; i) &amp; 1</tt>.</li>
598
599 <li>For all <tt>i</tt> in the range <tt>[M,num_bits)</tt>,
600 <tt>(*this)[i] == false</tt>.</li>
601 </ul>
602
603 <b>Throws:</b> An allocation error if memory is exhausted
604 (<tt>std::bad_alloc</tt> if
605 <tt>Allocator=std::allocator</tt>).<br />
606
607
608 <hr />
609 <pre>
610 <a id="cons5">dynamic_bitset</a>(const dynamic_bitset&amp; x)
611 </pre>
612
613 <b>Effects:</b> Constructs a bitset that is a copy of the bitset
614 <tt>x</tt>. The allocator for this bitset is a copy of the
615 allocator in <tt>x</tt>. <br />
616  <b>Postconditions:</b> For all <tt>i</tt> in the range
617 <tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br />
618  <b>Throws:</b> An allocation error if memory is exhausted
619 (<tt>std::bad_alloc</tt> if
620 <tt>Allocator=std::allocator</tt>).<br />
621  (Required by <a href=
622 "http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
623
624 <hr />
625 <pre>
626 template &lt;typename BlockInputIterator&gt;
627 explicit
628 <a id=
629 "cons4">dynamic_bitset</a>(BlockInputIterator first, BlockInputIterator last,
630                const Allocator&amp; alloc = Allocator());
631 </pre>
632
633 <b>Effects:</b>
634 <ul>
635 <li>
636 If this constructor is called with a type <tt>BlockInputIterator</tt> which
637 <i>is actually an integral type</i>, the library behaves as if the constructor
638 from <tt>unsigned long</tt> were called, with arguments
639 <tt>static_cast&lt;size_type&gt;(first), last and alloc</tt>, in that order.
640 <br /><br />
641 Example:
642 <pre>
643 // b is constructed as if by calling the constructor
644 //
645 //   dynamic_bitset(size_type num_bits,
646 //                  unsigned long value = 0,
647 //                  const Allocator&amp; alloc = Allocator())
648 //
649 // with arguments
650 //
651 //   static_cast&lt;dynamic_bitset&lt;unsigned short&gt;::size_type&gt;(8),
652 //   7,
653 //   Allocator()
654 //
655 dynamic_bitset&lt;unsigned short&gt; b(8, 7);
656 </pre><br />
657 <i>Note:</i><br/>
658 At the time of writing (October 2008) this is aligned with the
659 proposed resolution for <a href=
660     "http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#438">library
661     issue 438</a>. That is a <em>post <tt>C++03</tt></em>
662 change, and is currently in the working paper for
663 <tt>C++0x</tt>. Informally speaking, the critical changes with
664 respect to <tt>C++03</tt> are the drop of a <tt>static_cast</tt>
665 on the second argument, and more leeway as to <em>when</em> the
666 templated constructor should have the same effect as the (size,
667 value) one: only when <tt>InputIterator</tt> is an integral
668 type, in <tt>C++03</tt>; when it is either an integral type or
669 any other type that the implementation might detect as
670 impossible to be an input iterator, with the proposed
671 resolution. For the purposes of <tt>dynamic_bitset</tt> we limit
672 ourselves to the first of these two changes.<br /><br />
673 </li>
674 <li>
675 <i>Otherwise</i> (<i>i.e.</i> if the template argument is not an
676 integral type), constructs&mdash;under the condition in the
677 <tt>requires</tt> clause&mdash;a bitset based on a range of
678 blocks. Let <tt>*first</tt> be block number 0, <tt>*++first</tt>
679 block number 1, etc. Block number <tt>b</tt> is used to
680 initialize the bits of the dynamic_bitset in the position range
681 <tt>[b*bits_per_block, (b+1)*bits_per_block)</tt>. For each
682 block number <tt>b</tt> with value <tt>bval</tt>, the bit
683 <tt>(bval &gt;&gt; i) &amp; 1</tt> corresponds to the bit at
684 position <tt>(b * bits_per_block + i)</tt> in the bitset (where
685 <tt>i</tt> goes through the range <tt>[0, bits_per_block)</tt>).
686 </li>
687 </ul>
688 <br />
689 <b>Requires:</b> <tt>BlockInputIterator</tt> must be either an
690 integral type or a model of <a href=
691     "http://www.sgi.com/tech/stl/InputIterator.html">Input
692     Iterator</a> whose <tt>value_type</tt> is the same type as
693 <tt>Block</tt>.<br /> <b>Throws:</b> An allocation error if
694 memory is exhausted (<tt>std::bad_alloc</tt> if
695 <tt>Allocator=std::allocator</tt>).<br />
696
697 <hr />
698 <pre>
699 template&lt;typename Char, typename Traits, typename Alloc&gt;
700 explicit
701 <a id="cons3">dynamic_bitset</a>(const <a href=
702 "http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s,
703                typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type pos = 0,
704                typename std::basic_string&lt;CharT, Traits, Alloc&gt;::size_type n = <a
705  href=
706 "http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;::npos,
707                const Allocator&amp; alloc = Allocator())
708 </pre>
709
710 <b>Precondition:</b> <tt>pos &lt;= s.size()</tt> and the
711 characters used to initialize the bits must be <tt>0</tt> or
712 <tt>1</tt>.<br />
713  <b>Effects:</b> Constructs a bitset from a string of 0's and
714 1's. The first <tt>M</tt> bits are initialized to the
715 corresponding characters in <tt>s</tt>, where <tt>M =
716 min(s.size() - pos, n)</tt>. Note that the <i>highest</i>
717 character position in <tt>s</tt>, not the lowest, corresponds to
718 the least significant bit. That is, character position <tt>pos +
719 M - 1 - i</tt> corresponds to bit <tt>i</tt>. So, for example,
720 <tt>dynamic_bitset(string("1101"))</tt> is the same as
721 <tt>dynamic_bitset(13ul)</tt>.<br />
722  <b>Throws:</b> an allocation error if memory is exhausted
723 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
724
725 <hr />
726 <h3><a id="destructor">Destructor</a></h3>
727
728 <hr />
729 <pre>
730 ~dynamic_bitset()
731 </pre>
732
733 <b>Effects:</b> Releases the memory associated with this bitset
734 and destroys the bitset object itself.<br />
735  <b>Throws:</b> nothing.
736
737 <hr />
738 <h3><a id="member-functions">Member Functions</a></h3>
739
740 <hr />
741 <pre>
742 void <a id="swap">swap</a>(dynamic_bitset&amp; b);
743 </pre>
744
745 <b>Effects:</b> The contents of this bitset and bitset <tt>b</tt>
746 are exchanged.<br />
747 <b>Postconditions:</b> This bitset is equal to the original
748 <tt>b</tt>, and <tt>b</tt> is equal to the previous version of
749 this bitset.<br />
750 <b>Throws:</b> nothing.
751
752 <hr />
753 <pre>
754 dynamic_bitset&amp; <a id=
755 "assign">operator=</a>(const dynamic_bitset&amp; x)
756 </pre>
757
758 <b>Effects:</b> This bitset becomes a copy of the bitset
759 <tt>x</tt>.<br />
760  <b>Postconditions:</b> For all <tt>i</tt> in the range
761 <tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br />
762  <b>Returns:</b> <tt>*this</tt>.<br />
763  <b>Throws:</b> nothing. <br />
764 (Required by <a href=
765 "http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.)
766
767 <hr />
768 <pre>
769 allocator_type <a id="get_allocator">get_allocator()</a> const;
770 </pre>
771  <b>Returns:</b> A copy of the allocator object used to construct <tt>*this</tt>.
772
773 <hr />
774 <pre>
775 void <a id=
776 "resize">resize</a>(size_type num_bits, bool value = false);
777 </pre>
778
779 <b>Effects:</b> Changes the number of bits of the bitset to
780 <tt>num_bits</tt>. If <tt>num_bits &gt; size()</tt> then the bits
781 in the range <tt>[0,size())</tt> remain the same, and the bits in
782 <tt>[size(),num_bits)</tt> are all set to <tt>value</tt>. If
783 <tt>num_bits &lt; size()</tt> then the bits in the range
784 <tt>[0,num_bits)</tt> stay the same (and the remaining bits are
785 discarded).<br />
786  <b>Postconditions:</b> <tt>this-&gt;size() == num_bits</tt>.<br />
787  <b>Throws:</b> An allocation error if memory is exhausted
788 (<tt>std::bad_alloc</tt> if
789 <tt>Allocator=std::allocator</tt>).<br />
790
791
792 <hr />
793 <pre>
794 void <a id="clear">clear</a>()
795 </pre>
796
797 <b>Effects:</b> The size of the bitset becomes zero.<br />
798  <b>Throws:</b> nothing.
799
800 <hr />
801 <pre>
802 void <a id="push_back">push_back</a>(bool value);
803 </pre>
804
805 <b>Effects:</b> Increases the size of the bitset by one, and sets
806 the value of the new most-significant bit to <tt>value</tt>.<br />
807  <b>Throws:</b> An allocation error if memory is exhausted
808 (<tt>std::bad_alloc</tt> if
809 <tt>Allocator=std::allocator</tt>).<br />
810
811
812 <hr />
813 <pre>
814 void <a id="append1">append</a>(Block value);
815 </pre>
816
817 <b>Effects:</b> Appends the bits in <tt>value</tt> to the bitset
818 (appends to the most-significant end). This increases the size of
819 the bitset by <tt>bits_per_block</tt>. Let <tt>s</tt> be the old
820 size of the bitset, then for <tt>i</tt> in the range
821 <tt>[0,bits_per_block)</tt>, the bit at position <tt>(s + i)</tt>
822 is set to <tt>((value &gt;&gt; i) &amp; 1)</tt>.<br />
823  <b>Throws:</b> An allocation error if memory is exhausted
824 (<tt>std::bad_alloc</tt> if
825 <tt>Allocator=std::allocator</tt>).<br />
826
827
828 <hr />
829 <pre>
830 template &lt;typename BlockInputIterator&gt;
831 void <a id=
832 "append2">append</a>(BlockInputIterator first, BlockInputIterator last);
833 </pre>
834
835 <b>Effects:</b> This function provides the same end result as the
836 following code, but is typically more efficient.
837
838 <pre>
839 for (; first != last; ++first)
840   append(*first);
841 </pre>
842
843 <b>Requires:</b> The <tt>BlockInputIterator</tt> type must be a
844 model of <a href=
845 "http://www.sgi.com/tech/stl/InputIterator.html">Input
846 Iterator</a> and the <tt>value_type</tt> must be the same type as
847 <tt>Block</tt>.<br />
848  <b>Throws:</b> An allocation error if memory is exhausted
849 (<tt>std::bad_alloc</tt> if
850 <tt>Allocator=std::allocator</tt>).<br />
851
852
853 <hr />
854 <pre>
855 dynamic_bitset&amp; <a id=
856 "op-and-assign">operator&amp;=</a>(const dynamic_bitset&amp; rhs)
857 </pre>
858
859 <b>Requires:</b> <tt>this-&gt;size() == rhs.size()</tt>.<br />
860  <b>Effects:</b> Bitwise-AND all the bits in <tt>rhs</tt> with
861 the bits in this bitset. This is equivalent to:
862
863 <pre>
864 for (size_type i = 0; i != this-&gt;size(); ++i)
865   (*this)[i] = (*this)[i] &amp; rhs[i];
866 </pre>
867
868 <b>Returns:</b> <tt>*this</tt>.<br />
869  <b>Throws:</b> nothing.
870
871 <hr />
872 <pre>
873 dynamic_bitset&amp; <a id=
874 "op-or-assign">operator|=</a>(const dynamic_bitset&amp; rhs)
875 </pre>
876
877 <b>Requires:</b> <tt>this-&gt;size() == rhs.size()</tt>.<br />
878  <b>Effects:</b> Bitwise-OR's all the bits in <tt>rhs</tt> with
879 the bits in this bitset. This is equivalent to:
880
881 <pre>
882 for (size_type i = 0; i != this-&gt;size(); ++i)
883   (*this)[i] = (*this)[i] | rhs[i];
884 </pre>
885
886 <b>Returns:</b> <tt>*this</tt>.<br />
887  <b>Throws:</b> nothing.
888
889 <hr />
890 <pre>
891 dynamic_bitset&amp; <a id=
892 "op-xor-assign">operator^=</a>(const dynamic_bitset&amp; rhs)
893 </pre>
894
895 <b>Requires:</b> <tt>this-&gt;size() == rhs.size()</tt>.<br />
896  <b>Effects:</b> Bitwise-XOR's all the bits in <tt>rhs</tt> with
897 the bits in this bitset. This is equivalent to:
898
899 <pre>
900 for (size_type i = 0; i != this-&gt;size(); ++i)
901   (*this)[i] = (*this)[i] ^ rhs[i];
902 </pre>
903
904 <b>Returns:</b> <tt>*this</tt>.<br />
905  <b>Throws:</b> nothing.
906
907 <hr />
908 <pre>
909 dynamic_bitset&amp; <a id=
910 "op-sub-assign">operator-=</a>(const dynamic_bitset&amp; rhs)
911 </pre>
912
913 <b>Requires:</b> <tt>this-&gt;size() == rhs.size()</tt>.<br />
914  <b>Effects:</b> Computes the set difference of this bitset and
915 the <tt>rhs</tt> bitset. This is equivalent to:
916
917 <pre>
918 for (size_type i = 0; i != this-&gt;size(); ++i)
919   (*this)[i] = (*this)[i] &amp;&amp; !rhs[i];
920 </pre>
921
922 <b>Returns:</b> <tt>*this</tt>.<br />
923  <b>Throws:</b> nothing.
924
925 <hr />
926 <pre>
927 dynamic_bitset&amp; <a id=
928 "op-sl-assign">operator&lt;&lt;=</a>(size_type n)
929 </pre>
930
931 <b>Effects:</b> Shifts the bits in this bitset to the left by
932 <tt>n</tt> bits. For each bit in the bitset, the bit at position
933 pos takes on the previous value of the bit at position <tt>pos -
934 n</tt>, or zero if no such bit exists.<br />
935  <b>Returns:</b> <tt>*this</tt>.<br />
936  <b>Throws:</b> nothing.
937
938 <hr />
939 <pre>
940 dynamic_bitset&amp; <a id=
941 "op-sr-assign">operator&gt;&gt;=</a>(size_type n)
942 </pre>
943
944 <b>Effects:</b> Shifts the bits in this bitset to the right by
945 <tt>n</tt> bits. For each bit in the bitset, the bit at position
946 <tt>pos</tt> takes on the previous value of bit <tt>pos + n</tt>,
947 or zero if no such bit exists.<br />
948  <b>Returns:</b> <tt>*this</tt>.<br />
949  <b>Throws:</b> nothing.
950
951 <hr />
952 <pre>
953 dynamic_bitset <a id=
954 "op-sl">operator&lt;&lt;</a>(size_type n) const
955 </pre>
956
957 <b>Returns:</b> a copy of <tt>*this</tt> shifted to the left by
958 <tt>n</tt> bits. For each bit in the returned bitset, the bit at
959 position pos takes on the value of the bit at position <tt>pos -
960 n</tt> of this bitset, or zero if no such bit exists.<br />
961  <b>Throws:</b> An allocation error if memory is exhausted
962 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
963
964 <hr />
965 <pre>
966 dynamic_bitset <a id=
967 "op-sr">operator&gt;&gt;</a>(size_type n) const
968 </pre>
969
970 <b>Returns:</b> a copy of <tt>*this</tt> shifted to the right by
971 <tt>n</tt> bits. For each bit in the returned bitset, the bit at
972 position pos takes on the value of the bit at position <tt>pos +
973 n</tt> of this bitset, or zero if no such bit exists.<br />
974  <b>Throws:</b> An allocation error if memory is exhausted
975 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
976
977 <hr />
978 <pre>
979 dynamic_bitset&amp; <a id="set1">set</a>()
980 </pre>
981
982 <b>Effects:</b> Sets every bit in this bitset to 1.<br />
983 <b>Returns:</b> <tt>*this</tt><br />
984 <b>Throws:</b> nothing.
985
986 <hr />
987 <pre>
988 dynamic_bitset&amp; <a id="flip1">flip</a>()
989 </pre>
990
991 <b>Effects:</b> Flips the value of every bit in this bitset.<br />
992 <b>Returns:</b> <tt>*this</tt><br />
993 <b>Throws:</b> nothing.
994
995 <hr />
996 <pre>
997 dynamic_bitset <a id="op-not">operator~</a>() const
998 </pre>
999
1000 <b>Returns:</b> a copy of <tt>*this</tt> with all of its bits
1001 flipped.<br />
1002 <b>Throws:</b> An allocation error if memory is exhausted
1003 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1004
1005 <hr />
1006 <pre>
1007 dynamic_bitset&amp; <a id="reset1">reset</a>()
1008 </pre>
1009
1010 <b>Effects:</b> Clears every bit in this bitset.<br />
1011 <b>Returns:</b> <tt>*this</tt><br />
1012 <b>Throws:</b> nothing.
1013
1014 <hr />
1015 <pre>
1016 dynamic_bitset&amp; <a id=
1017 "set2">set</a>(size_type n, bool val = true)
1018 </pre>
1019
1020 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1021  <b>Effects:</b> Sets bit <tt>n</tt> if <tt>val</tt> is
1022 <tt>true</tt>, and clears bit <tt>n</tt> if <tt>val</tt> is
1023 <tt>false</tt>. <br />
1024  <b>Returns:</b> <tt>*this</tt>
1025
1026 <hr />
1027 <pre>
1028 dynamic_bitset&amp; <a id="reset2">reset</a>(size_type n)
1029 </pre>
1030
1031 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1032 <b>Effects:</b> Clears bit <tt>n</tt>.<br />
1033 <b>Returns:</b> <tt>*this</tt>
1034
1035 <hr />
1036 <pre>
1037 dynamic_bitset&amp; <a id="flip2">flip</a>(size_type n)
1038 </pre>
1039
1040 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1041 <b>Effects:</b> Flips bit <tt>n</tt>.<br />
1042 <b>Returns:</b> <tt>*this</tt>
1043
1044 <hr />
1045 <pre>
1046 size_type <a id="size">size</a>() const
1047 </pre>
1048
1049 <b>Returns:</b> the number of bits in this bitset.<br />
1050 <b>Throws:</b> nothing.
1051
1052 <hr />
1053 <pre>
1054 size_type <a id="num_blocks">num_blocks</a>() const
1055 </pre>
1056
1057 <b>Returns:</b> the number of blocks in this bitset.<br />
1058 <b>Throws:</b> nothing.
1059
1060 <hr />
1061 <pre>
1062 size_type <a id="max_size">max_size</a>() const;
1063 </pre>
1064
1065 <b>Returns:</b> the maximum size of a <tt>dynamic_bitset</tt>
1066 object having the same type as <tt>*this</tt>. Note that if
1067 any <tt>dynamic_bitset</tt> operation causes <tt>size()</tt> to
1068 exceed <tt>max_size()</tt> then the <i>behavior is undefined</i>.
1069 <br /><br />[The semantics of this function could change slightly
1070 when lib issue 197 will be closed]<br />
1071
1072 <hr />
1073 <pre>
1074 bool <a id="empty">empty</a>() const;
1075 </pre>
1076
1077 <b>Returns:</b> <tt>true</tt> if <tt>this->size() == 0</tt>, <tt>false</tt>
1078 otherwise. <i>Note</i>: not to be confused with <tt>none()</tt>, that has
1079 different semantics.
1080
1081 <hr />
1082 <pre>
1083 size_type <a id="count">count</a>() const
1084 </pre>
1085
1086 <b>Returns:</b> the number of bits in this bitset that are
1087 set.<br />
1088 <b>Throws:</b> nothing.
1089
1090 <hr />
1091 <pre>
1092 bool <a id="any">any</a>() const
1093 </pre>
1094
1095 <b>Returns:</b> <tt>true</tt> if any bits in this bitset are set,
1096 and otherwise returns <tt>false</tt>.<br />
1097 <b>Throws:</b> nothing.
1098
1099 <hr />
1100 <pre>
1101 bool <a id="none">none</a>() const
1102 </pre>
1103
1104 <b>Returns:</b> <tt>true</tt> if no bits are set, and otherwise
1105 returns <tt>false</tt>.<br />
1106 <b>Throws:</b> nothing.
1107
1108 <hr />
1109 <pre>
1110 bool <a id="test">test</a>(size_type n) const
1111 </pre>
1112
1113 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1114  <b>Returns:</b> <tt>true</tt> if bit <tt>n</tt> is set and
1115 <tt>false</tt> is bit <tt>n</tt> is 0.
1116
1117 <hr />
1118 <pre>
1119 reference <a id="bracket">operator[]</a>(size_type n)
1120 </pre>
1121
1122 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1123  <b>Returns:</b> a <tt>reference</tt> to bit <tt>n</tt>. Note
1124 that <tt>reference</tt> is a proxy class with an assignment
1125 operator and a conversion to <tt>bool</tt>, which allows you to
1126 use <tt>operator[]</tt> for assignment. That is, you can write
1127 both <tt>x = b[n]</tt> and <tt>b[n] = x</tt>. However, in many
1128 other respects the proxy is not the same as the true reference
1129 type <tt>bool&amp;</tt>.
1130
1131 <hr />
1132 <pre>
1133 bool <a id="const-bracket">operator[]</a>(size_type n) const
1134 </pre>
1135
1136 <b>Precondition:</b> <tt>n &lt; this-&gt;size()</tt>.<br />
1137 <b>Returns:</b> The same as <tt>test(n)</tt>.
1138
1139 <hr />
1140 <pre>
1141 unsigned long <a id="to_ulong">to_ulong</a>() const
1142 </pre>
1143
1144 <b>Returns:</b> The numeric value corresponding to the bits in <tt>*this</tt>.
1145 <br />
1146 <b>Throws:</b> <tt>std::overflow_error</tt> if that value is too large to
1147 be represented in an <tt>unsigned long</tt>, i.e. if <tt>*this</tt> has
1148 any non-zero bit at a position <tt>&gt;=
1149 std::numeric_limits&lt;unsigned long&gt;::digits</tt>.
1150
1151 <hr />
1152 <pre>
1153 bool <a id=
1154 "is_subset_of">is_subset_of</a>(const dynamic_bitset&amp; a) const
1155 </pre>
1156
1157 <b>Requires:</b> <tt>this-&gt;size() == a.size()</tt><br />
1158 <b>Returns:</b> true if this bitset is a subset of bitset
1159 <tt>a</tt>. That is, it returns true if, for every bit that is
1160 set in this bitset, the corresponding bit in bitset <tt>a</tt> is
1161 also set. Otherwise this function returns false.<br />
1162 <b>Throws:</b> nothing.
1163
1164 <hr />
1165 <pre>
1166 bool <a id=
1167 "is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset&amp; a) const
1168 </pre>
1169
1170 <b>Requires:</b> <tt>this-&gt;size() == a.size()</tt><br />
1171 <b>Returns:</b> true if this bitset is a proper subset of bitset
1172 <tt>a</tt>. That is, it returns true if, for every bit that is
1173 set in this bitset, the corresponding bit in bitset <tt>a</tt> is
1174 also set and if <tt>this-&gt;count() &lt; a.count()</tt>.
1175 Otherwise this function returns false.<br />
1176 <b>Throws:</b> nothing.
1177
1178 <hr />
1179 <pre>
1180 bool <a id=
1181 "intersects">intersects</a>(const dynamic_bitset&amp; a) const
1182 </pre>
1183
1184 <b>Requires:</b> <tt>this-&gt;size() == a.size()</tt><br />
1185 <b>Returns:</b> true if this bitset and <tt>a</tt> intersect.
1186 That is, it returns true if, there is a bit which is set in this
1187 bitset, such that the corresponding bit in bitset <tt>a</tt> is
1188 also set. Otherwise this function returns false.<br />
1189 <b>Throws:</b> nothing.
1190
1191 <hr />
1192 <pre>
1193 size_type <a id = "find_first">find_first</a>() const;
1194 </pre>
1195
1196 <b>Returns:</b> the lowest index <tt>i</tt> such as bit <tt>i</tt>
1197 is set, or <tt>npos</tt> if <tt>*this</tt> has no on bits.
1198
1199 <hr />
1200 <pre>
1201 size_type <a id="find_next">find_next</a>(size_type pos) const;
1202 </pre>
1203
1204 <b>Returns:</b> the lowest index <tt>i</tt> greater than
1205 <tt>pos</tt> such as bit <tt>i</tt> is set, or <tt>npos</tt> if
1206 no such index exists.
1207
1208 <hr />
1209 <pre>
1210 bool <a id=
1211 "op-equal">operator==</a>(const dynamic_bitset&amp; rhs) const
1212 </pre>
1213
1214 <b>Returns:</b> <tt>true</tt> if <tt>this-&gt;size() ==
1215 rhs.size()</tt> and if for all <tt>i</tt> in the range
1216 <tt>[0,rhs.size())</tt>, <tt>(*this)[i] == rhs[i]</tt>. Otherwise
1217 returns <tt>false</tt>.<br />
1218  <b>Throws:</b> nothing.<br />
1219  (Required by <a href=
1220 "http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
1221 Comparable</a>.)
1222
1223 <hr />
1224 <pre>
1225 bool <a id=
1226 "op-not-equal">operator!=</a>(const dynamic_bitset&amp; rhs) const
1227 </pre>
1228
1229 <b>Returns:</b> <tt>!((*this) == rhs)</tt><br />
1230 <b>Throws:</b> nothing.<br />
1231 (Required by <a href=
1232 "http://www.sgi.com/tech/stl/EqualityComparable.html">Equality
1233 Comparable</a>.)
1234
1235 <hr />
1236 <pre>
1237 bool <a id=
1238 "op-less">operator&lt;</a>(const dynamic_bitset&amp; rhs) const
1239 </pre>
1240
1241 <b>Returns:</b> <tt>true</tt> if this bitset is lexicographically
1242 less than <tt>rhs</tt>, and returns <tt>false</tt> otherwise.
1243 (See the description of <a href=
1244 "http://www.sgi.com/tech/stl/lexicographical_compare.html">lexicographical_compare</a>
1245 for a definition of lexicographic ordering). <br />
1246 <b>Throws:</b> nothing.<br />
1247 (Required by <a href=
1248 "http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
1249 Comparable</a>.)
1250
1251 <hr />
1252 <pre>
1253 bool <a id=
1254 "op-greater">operator&gt;</a>(const dynamic_bitset&amp; rhs) const
1255 </pre>
1256
1257 <b>Returns:</b> <tt>!((*this) &lt; rhs || (*this) ==
1258 rhs)</tt><br />
1259 <b>Throws:</b> nothing.<br />
1260 (Required by <a href=
1261 "http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
1262 Comparable</a>.)
1263
1264 <hr />
1265 <pre>
1266 bool <a id=
1267 "op-less-equal">operator&lt;=</a>(const dynamic_bitset&amp; rhs) const
1268 </pre>
1269
1270 <b>Returns:</b> <tt>(*this) &lt; rhs || (*this) == rhs</tt><br />
1271 <b>Throws:</b> nothing.<br />
1272 (Required by <a href=
1273 "http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
1274 Comparable</a>.)
1275
1276 <hr />
1277 <pre>
1278 bool <a id=
1279 "op-greater-equal">operator&gt;=</a>(const dynamic_bitset&amp; rhs) const
1280 </pre>
1281
1282 <b>Returns:</b> <tt>(*this) &gt; rhs || (*this) == rhs</tt><br />
1283 <b>Throws:</b> nothing.<br />
1284 (Required by <a href=
1285 "http://www.sgi.com/tech/stl/LessThanComparable.html">Less Than
1286 Comparable</a>.)
1287
1288 <hr />
1289 <h3><a id="non-member-functions">Non-Member Functions</a></h3>
1290
1291 <hr />
1292 <pre>
1293 dynamic_bitset <a id=
1294 "op-and">operator&amp;</a>(const dynamic_bitset&amp; a, const dynamic_bitset&amp; b)
1295 </pre>
1296
1297 <b>Requires:</b> <tt>a.size() == b.size()</tt><br />
1298 <b>Returns:</b> A new bitset that is the bitwise-AND of the
1299 bitsets <tt>a</tt> and <tt>b</tt>.<br />
1300 <b>Throws:</b> An allocation error if memory is exhausted
1301 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1302
1303 <hr />
1304 <pre>
1305 dynamic_bitset <a id=
1306 "op-or">operator|</a>(const dynamic_bitset&amp; a, const dynamic_bitset&amp; b)
1307 </pre>
1308
1309 <b>Requires:</b> <tt>a.size() == b.size()</tt><br />
1310 <b>Returns:</b> A new bitset that is the bitwise-OR of the
1311 bitsets <tt>a</tt> and <tt>b</tt>.<br />
1312 <b>Throws:</b> An allocation error if memory is exhausted
1313 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1314
1315 <hr />
1316 <pre>
1317 dynamic_bitset <a id=
1318 "op-xor">operator^</a>(const dynamic_bitset&amp; a, const dynamic_bitset&amp; b)
1319 </pre>
1320
1321 <b>Requires:</b> <tt>a.size() == b.size()</tt><br />
1322 <b>Returns:</b> A new bitset that is the bitwise-XOR of the
1323 bitsets <tt>a</tt> and <tt>b</tt>.<br />
1324 <b>Throws:</b> An allocation error if memory is exhausted
1325 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1326
1327 <hr />
1328 <pre>
1329 dynamic_bitset <a id=
1330 "op-sub">operator-</a>(const dynamic_bitset&amp; a, const dynamic_bitset&amp; b)
1331 </pre>
1332
1333 <b>Requires:</b> <tt>a.size() == b.size()</tt><br />
1334 <b>Returns:</b> A new bitset that is the set difference of the
1335 bitsets <tt>a</tt> and <tt>b</tt>.<br />
1336 <b>Throws:</b> An allocation error if memory is exhausted
1337 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1338
1339 <hr />
1340 <pre>
1341 template &lt;typename CharT, typename Alloc&gt;
1342 void <a id=
1343 "to_string">to_string</a>(const dynamic_bitset&lt;Block, Allocator&gt;&amp; b,
1344                <a href=
1345 "http://www.sgi.com/tech/stl/basic_string.html">std::basic_string</a>&lt;Char,Traits,Alloc&gt;&amp; s)
1346 </pre>
1347
1348 <b>Effects:</b> Copies a representation of <tt>b</tt> into the
1349 string <tt>s</tt>. A character in the string is <tt>'1'</tt> if
1350 the corresponding bit is set, and <tt>'0'</tt> if it is not.
1351 Character position <tt>i</tt> in the string corresponds to bit
1352 position <tt>b.size() - 1 - i</tt>. <br />
1353  <b>Throws:</b> If memory is exhausted, the string will throw an
1354 allocation error.<br />
1355  <b>Rationale:</b> This function is not a member function taking
1356 zero arguments and returning a string for a couple reasons.
1357 First, this version can be slighly more efficient because the
1358 string is not copied (due to being passed by value). Second, as a
1359 member function, to allow for flexibility with regards to the
1360 template parameters of <tt>basic_string</tt>, the member function
1361 would require explicit template parameters. Few C++ programmers
1362 are familiar with explicit template parameters, and some C++
1363 compilers do not handle them properly.
1364
1365 <hr />
1366 <pre>
1367 template &lt;typename Block, typename Alloc, typename BlockOutputIterator&gt;
1368 void <a id=
1369 "to_block_range">to_block_range</a>(const dynamic_bitset&lt;Block, Alloc&gt;&amp; b, BlockOutputIterator result)
1370 </pre>
1371
1372 <b>Effects:</b> Writes the bits of the bitset into the iterator
1373 <tt>result</tt> a block at a time. The first block written
1374 represents the bits in the position range
1375 <tt>[0,bits_per_block)</tt> in the bitset, the second block
1376 written the bits in the range
1377 <tt>[bits_pre_block,2*bits_per_block)</tt>, and so on. For each
1378 block <tt>bval</tt> written, the bit <tt>(bval &gt;&gt; i) &amp;
1379 1</tt> corresponds to the bit at position <tt>(b * bits_per_block
1380 + i)</tt> in the bitset.<br />
1381  <b>Requires:</b> The type <tt>BlockOutputIterator</tt> must be a
1382 model of <a href=
1383 "http://www.sgi.com/tech/stl/OutputIterator.html">Output
1384 Iterator</a> and its <tt>value_type</tt> must be the same type as
1385 <tt>Block</tt>. Further, the size of the output range must be
1386 greater or equal <tt>b.num_blocks()</tt>.
1387
1388 <hr />
1389 <pre>
1390 template &lt;typename BlockIterator, typename Block, typename Alloc&gt;
1391 void <a id=
1392 "from_block_range">from_block_range</a>(BlockIterator first,
1393     BlockIterator last, const dynamic_bitset&lt;Block, Alloc&gt;&amp; b)
1394 </pre>
1395
1396 <b>Effects:</b> Reads blocks from the iterator range into the
1397 bitset. <br />
1398  <b>Requires:</b> The type <tt>BlockIterator</tt> must be a model
1399 of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input
1400 Iterator</a> and its <tt>value_type</tt> must be the same type as
1401 <tt>Block</tt>. The size of the iterator range must be less or
1402 equal to <tt>b.num_blocks()</tt>.
1403
1404 <hr />
1405 <pre>
1406 template &lt;typename Char, typename Traits, typename Block, typename Alloc&gt;
1407 basic_ostream&lt;Char, Traits&gt;&amp;
1408 <a id=
1409 "op-out">operator&lt;&lt;</a>(basic_ostream&lt;Char, Traits&gt;&amp; os, const dynamic_bitset&lt;Block, Alloc&gt;&amp; b)
1410 </pre>
1411
1412 <b>Effects:</b> Inserts a textual representation of b into the stream
1413 <tt>os</tt> (highest bit first). Informally, the output is the same as doing
1414
1415 <pre>
1416 std::basic_string&lt;Char, Traits&gt; s;
1417 boost::to_string(x, s):
1418 os &lt;&lt; s;
1419 </pre>
1420
1421 except that the stream inserter takes into accout the locale imbued into
1422 <tt>os</tt>, which <tt>boost::to_string()</tt> can't do. Here is a more
1423 precise specification, given in terms of "as if" rule: first, for each
1424 valid position i into the bitset <tt>b</tt> let's put:
1425
1426  <tt>character_of(b[i)]) = b[i]? os.widen('1') : os.widen('0');</tt>
1427
1428 Let also <tt>s</tt> be a <tt>std::basic_string&lt;Char, Traits&gt;</tt>
1429 object, having length <tt>b.size()</tt> and such as, for each <tt>i</tt>
1430 in <tt>[0, b.size())</tt>,
1431
1432  <tt>s[i] is character_of(b[i])</tt>
1433
1434 Then, the output, the effects on <tt>os</tt> and the exception behavior
1435 is the same as outputting the object <tt>s</tt> to <tt>os</tt> (same
1436 width, same exception mask, same padding, same setstate() logic)
1437 <br />
1438 <b>Returns:</b> os <br />
1439 <b>Throws:</b> <tt>std::ios_base::failure</tt> if there is a
1440 problem writing to the stream.
1441
1442 <hr />
1443 <pre>
1444 template &lt;typename Char, typename Traits, typename Block, typename Alloc&gt;
1445 std::basic_istream&lt;Char,Traits&gt;&amp;
1446 <a id=
1447 "op-in">operator&gt;&gt;</a>(std::basic_istream&lt;Char,Traits&gt;&amp; is, dynamic_bitset&lt;Block, Alloc&gt;&amp; b)
1448 </pre>
1449
1450 <b>Effects:</b> Extracts a <tt>dynamic_bitset</tt> from an input stream.
1451 <br /><br />
1452  <i>Definitions:</i><br /><br />
1453  Let <i>Tr</i> be the traits_type of <i>is</i>. Then:
1454  <ol>
1455  <li>
1456  A (non-eof) character <tt>c</tt> extracted from <tt>is</tt>
1457  is a <i>bitset digit</i> if and only if either Tr::eq(c, is.widen('0')) or
1458  Tr::eq(c, is.widen('1')) return true.
1459  </li>
1460  <li>If c is a bitset digit, it's <i>corresponding bit value</i> is 0 if
1461  Tr::eq(c, is.widen('0')) is true, 1 otherwise.
1462  </li>
1463  </ol>
1464
1465 The function begins by constructing a <tt>sentry</tt> object <tt>k</tt> as if <tt>k</tt>
1466 were constructed by
1467
1468  <tt>typename std::basic_istream&lt;Char, Traits&gt;::sentry k(is)</tt>.
1469
1470 If <tt>bool(k)</tt> is true, it calls <tt>b.clear()</tt>
1471 then attempts to extract characters from <tt>is</tt>. For each character c
1472 that is a <i>bitset digit</i> the <i>corresponding bit value</i> is
1473 appended to the less significant end of <tt>b</tt> (appending may throw).
1474 If <tt>is.width()</tt> is greater than zero and smaller than <tt>b.max_size()</tt>
1475 then the maximum number <tt>n</tt> of bits appended is <tt>is.width()</tt>;
1476 otherwise <tt>n</tt> = <tt>b.max_size()</tt>.
1477
1478 Unless the extractor is exited via an exception, characters are extracted (and
1479 corresponding bits appended) until any of the following occurs:<br />
1480
1481 <ul>
1482 <li> <tt>n</tt> bits are stored into the bitset;</li>
1483 <li> end-of-file, or an error, occurs on the input sequence;</li>
1484 <li> the next available input character isn't a bitset digit</li>
1485 </ul>
1486 <br /> If no exception caused the function to exit then <tt>is.width(0)</tt> is
1487      called, regardless of how many characters were actually extracted. The
1488      sentry object k is destroyed.
1489 <br />
1490 <br />If the function extracts no characters[???], it calls is.setstate(std::ios::failbit),
1491      which may throw <tt>std::ios_base::failure</tt>.
1492
1493
1494 <br />------
1495
1496
1497 <br />
1498 <b>Throws:</b> An allocation error if memory is exhausted
1499 (<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
1500 A <tt>std::ios_base::failure</tt> if there is a problem reading
1501 from the stream.
1502
1503 <hr />
1504 <h3><a id="exception-guarantees">Exception guarantees</a></h3>
1505
1506 All of <tt>dynamic_bitset</tt> functions offer at least the basic
1507 exception guarantee.
1508
1509 <hr />
1510 <h3><a id="changes-from-previous-ver">Changes from previous version(s)</a></h3>
1511
1512 <h4><i>Changes in Boost 1.37.0</i></h4>
1513 <ul>
1514 <li>The constructor from a block range implements a "do the right thing"
1515 behavior, a la standard sequences.</li>
1516 </ul>
1517
1518 <!-- Changes from Boost 1.31.0 -->
1519 <h4><i>Changes from Boost 1.31.0</i></h4>
1520 <ul>
1521 <li>
1522 The stream extractor has completely different semantics: as natural
1523 for a dynamic structure, it now expands the bitset as needed during
1524 extraction. The new behaviour mimics that of the <tt>basic_string</tt>
1525 extractor but there are some differences the user should be aware of;
1526 so, please, check the <a href="#op-in">documentation</a>. (One
1527 difference concerns the case where <code>stream.width() &gt;
1528     bitset.max_size() &gt; 0</code>. In that circumstance the
1529 extractor of <tt>dynamic_bitset</tt> never attempts to extract more
1530 than <tt>max_size()</tt> characters, whereas the extractor of
1531 <tt>basic_string</tt> goes on and, on conforming implementations,
1532 eventually throws a <tt>length_error</tt> exception. Note: That's what
1533 the standard mandates -see especially <a
1534     href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#83">library
1535     issue 83</a>- but not all implementations conform)
1536 <br /><br />
1537 The stream extractor is now also "exception-aware" in the sense that
1538 it works correctly when setting exception masks on the stream.
1539 <br /><br />
1540 </li>
1541 <li>
1542 Several member functions (<tt>empty()</tt>, <tt>find_first()</tt>
1543 , <tt>find_next()</tt>, <tt>get_allocator()</tt>, <tt>intersects()</tt>
1544 , <tt>max_size()</tt> <!--, <tt>reserve()</tt>, <tt>capacity()</tt> -->)
1545 have been added.
1546 </li>
1547 <li>
1548 The constructor from <tt>basic_string</tt> has a new parameter that was totally
1549 forgotten before.
1550 </li>
1551
1552 </ul>
1553 <i>Technicalities and minor changes</i>
1554 <ul>
1555 <li>
1556 The class <tt>reference</tt> has been reimplemented so that
1557 dynamic_bitset's references behave more like references to standard
1558 container elements. In particular it is now guaranteed that they
1559 cannot be invalidated from a standard library swap() function
1560 applied to their corresponding <tt>dynamic_bitset</tt>s.
1561 </li>
1562 </ul>
1563 <i>General improvements</i>
1564 <br /><br />
1565 Several optimizations to member and non-member functions and to the
1566 nested class <tt>reference</tt>.
1567
1568 <hr />
1569 <h3><a id="see-also">See also</a></h3>
1570
1571 <tt><a href=
1572 "http://www.sgi.com/tech/stl/bitset.html">std::bitset</a></tt>,
1573 <tt><a href=
1574 "http://www.sgi.com/tech/stl/Vector.html">std::vector</a></tt>,
1575
1576 <h3><a id="acknowledgements">Acknowledgements</a></h3>
1577
1578 <p>We would like to thank the Boost community for putting in the
1579 time to review and accept this library. This library is much
1580 better than it ever would have been due to all the suggestions
1581 from Boost members. We especially thank Matt Marcus for taking on
1582 the task of review manager. Also, a special thanks goes to
1583 James Kanze for his invaluable help with the internationalization
1584 issues.</p>
1585
1586 <table summary="Copyright"> <tr> <td>Copyright &copy; 2001</td>
1587 <td><a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy
1588 Siek</a>, Indiana University (<a
1589 href="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</a>)<br /> <a
1590 href="http://freshsources.com">Chuck Allison</a>, Senior Editor,
1591 C/C++ Users Journal (<a
1592 href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br
1593 /></td> </tr> <tr>
1594 <td>Copyright &copy; 2003-2004, 2008</td> <td><a
1595         href="http://gennaro-prota.50webs.com/">Gennaro Prota</a>
1596     (name.surname yahoo.com)</td>
1597 </tr>
1598 </table>
1599 <br />
1600 <div class="legalnotice">
1601     Distributed under the Boost Software License, Version 1.0.
1602     (See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
1603     or copy at <a class="ulink" href="http://www.boost.org/LICENSE_1_0.txt">
1604 http://www.boost.org/LICENSE_1_0.txt</a>)
1605 </div>
1606
1607
1608 </div>
1609 </div>
1610 </div>
1611 </div>
1612 </div>
1613 </div>
1614 </body>
1615 <!--  LocalWords:  dynamic bitset alt gif iostream hpp int bitsets const ul ulong -->
1616 <!--  LocalWords:  STL LessThan alloc num typename BlockInputIterator html pos    -->
1617 <!--  LocalWords:  npos bool rhs OR's XOR's val CharT istream ostream os siek     -->
1618 <!--  LocalWords:  htm namespace enum sizeof BlockOutputIterator fwd ith jth      -->
1619 </html>