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