dynamic_bitset.html 60 KB

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