flyweight.html 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0.1 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  5. <title>Boost.Flyweight Documentation - flyweight reference</title>
  6. <link rel="stylesheet" href="../style.css" type="text/css">
  7. <link rel="start" href="../index.html">
  8. <link rel="prev" href="index.html">
  9. <link rel="up" href="index.html">
  10. <link rel="next" href="key_value.html">
  11. </head>
  12. <body>
  13. <h1><img src="../../../../boost.png" alt="Boost logo" align=
  14. "middle" width="277" height="86">Boost.Flyweight
  15. <code>flyweight</code> reference</h1>
  16. <div class="prev_link"><a href="index.html"><img src="../prev.gif" alt="Boost.Flyweight reference" border="0"><br>
  17. Boost.Flyweight reference
  18. </a></div>
  19. <div class="up_link"><a href="index.html"><img src="../up.gif" alt="Boost.Flyweight reference" border="0"><br>
  20. Boost.Flyweight reference
  21. </a></div>
  22. <div class="next_link"><a href="key_value.html"><img src="../next.gif" alt="key-value flyweights" border="0"><br>
  23. Key-value flyweights
  24. </a></div><br clear="all" style="clear: all;">
  25. <hr>
  26. <h2>Contents</h2>
  27. <ul>
  28. <li><a href="#flyweight_fwd_synopsis">Header
  29. <code>"boost/flyweight/flyweight_fwd.hpp"</code> synopsis</a></li>
  30. <li><a href="#synopsis">Header
  31. <code>"boost/flyweight/flyweight.hpp"</code> synopsis</a>
  32. <ul>
  33. <li><a href="#flyweight">Class template <code>flyweight</code></a>
  34. <ul>
  35. <li><a href="#instantiation_types">Instantiation types</a></li>
  36. <li><a href="#static_init">Static data initialization</a></li>
  37. <li><a href="#constructors">Constructors, copy and assignment</a></li>
  38. <li><a href="#convertibility">Convertibility to the underlying types</a></li>
  39. <li><a href="#modifiers">Modifiers</a></li>
  40. <li><a href="#comparison">Comparison operators</a></li>
  41. <li><a href="#specialized">Specialized algorithms</a></li>
  42. <li><a href="#hash">Hash support</a></li>
  43. <li><a href="#config_macros">Configuration macros</a></li>
  44. </ul>
  45. </li>
  46. </ul>
  47. </li>
  48. <li><a href="#serialize_synopsis">Header
  49. <code>"boost/flyweight/serialize.hpp"</code> synopsis</a>
  50. <ul>
  51. <li><a href="#serialization">Serialization</a></li>
  52. </ul>
  53. </li>
  54. </ul>
  55. <h2>
  56. <a name="flyweight_fwd_synopsis">Header
  57. <a href="../../../../boost/flyweight/flyweight_fwd.hpp"><code>"boost/flyweight/flyweight_fwd.hpp"</code></a>
  58. synopsis</a>
  59. </h2>
  60. <blockquote><pre>
  61. <span class=preprocessor>#include</span> <span class=special>&lt;</span><span class=identifier>boost</span><span class=special>/</span><span class=identifier>functional</span><span class=special>/</span><span class=identifier>hash_fwd</span><span class=special>.</span><span class=identifier>hpp</span><span class=special>&gt;</span>
  62. <span class=preprocessor>#include</span> <span class=special>&lt;</span><span class=identifier>iosfwd</span><span class=special>&gt;</span>
  63. <span class=keyword>namespace</span> <span class=identifier>boost</span><span class=special>{</span>
  64. <span class=keyword>namespace</span> <span class=identifier>flyweights</span><span class=special>{</span>
  65. <span class=keyword>template</span><span class=special>&lt;</span>
  66. <span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span>
  67. <span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>=</span><b>implementation defined</b><span class=special>,</span>
  68. <span class=keyword>typename</span> <span class=identifier>Arg2</span><span class=special>=</span><b>implementation defined</b><span class=special>,</span>
  69. <span class=keyword>typename</span> <span class=identifier>Arg3</span><span class=special>=</span><b>implementation defined</b><span class=special>,</span>
  70. <span class=keyword>typename</span> <span class=identifier>Arg4</span><span class=special>=</span><b>implementation defined</b><span class=special>,</span>
  71. <span class=keyword>typename</span> <span class=identifier>Arg5</span><span class=special>=</span><b>implementation defined</b>
  72. <span class=special>&gt;</span>
  73. <span class=keyword>class</span> <span class=identifier>flyweight</span><span class=special>;</span>
  74. <span class=comment>// comparison:
  75. // <b>OP</b> is any of ==,&lt;,!=,&gt;,&gt;=,&lt;=</span>
  76. <span class=keyword>template</span><span class=special>&lt;</span>
  77. <span class=keyword>typename</span> <span class=identifier>T1</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg11</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg15</span><span class=special>,</span>
  78. <span class=keyword>typename</span> <span class=identifier>T2</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg21</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg25</span>
  79. <span class=special>&gt;</span>
  80. <span class=keyword>bool</span> <span class=keyword>operator</span> <span class=identifier><b><i>OP</i></b></span><span class=special>(</span>
  81. <span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T1</span><span class=special>,</span><span class=identifier>Arg11</span><span class=special>,...,</span><span class=identifier>Arg15</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>,</span>
  82. <span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T2</span><span class=special>,</span><span class=identifier>Arg21</span><span class=special>,...,</span><span class=identifier>Arg25</span><span class=special>&gt;&amp;</span> <span class=identifier>y</span><span class=special>);</span>
  83. <span class=keyword>template</span><span class=special>&lt;</span>
  84. <span class=keyword>typename</span> <span class=identifier>T1</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg11</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg15</span><span class=special>,</span>
  85. <span class=keyword>typename</span> <span class=identifier>T2</span>
  86. <span class=special>&gt;</span>
  87. <span class=keyword>bool</span> <span class=keyword>operator</span> <span class=identifier><b><i>OP</i></b></span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T1</span><span class=special>,</span><span class=identifier>Arg11</span><span class=special>,...,</span><span class=identifier>Arg15</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>,</span><span class=keyword>const</span> <span class=identifier>T2</span><span class=special>&amp;</span> <span class=identifier>y</span><span class=special>);</span>
  88. <span class=keyword>template</span><span class=special>&lt;</span>
  89. <span class=keyword>typename</span> <span class=identifier>T1</span><span class=special>,</span>
  90. <span class=keyword>typename</span> <span class=identifier>T2</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg21</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg25</span>
  91. <span class=special>&gt;</span>
  92. <span class=keyword>bool</span> <span class=keyword>operator</span> <span class=identifier><b><i>OP</i></b></span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>T1</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>,</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T2</span><span class=special>,</span><span class=identifier>Arg21</span><span class=special>,...,</span><span class=identifier>Arg25</span><span class=special>&gt;&amp;</span> <span class=identifier>y</span><span class=special>);</span>
  93. <span class=comment>// specialized algorithms:</span>
  94. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span><span class=special>&gt;</span>
  95. <span class=keyword>inline</span> <span class=keyword>void</span> <span class=identifier>swap</span><span class=special>(</span>
  96. <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>,</span><span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;&amp;</span> <span class=identifier>y</span><span class=special>);</span>
  97. <span class=keyword>template</span><span class=special>&lt;</span>
  98. <span class=keyword>typename</span> <span class=identifier>ElemType</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Traits</span><span class=special>,</span>
  99. <span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span>
  100. <span class=special>&gt;</span>
  101. <span class=keyword>inline</span> <span class=identifier>std</span><span class=special>::</span><span class=identifier>basic_ostream</span><span class=special>&lt;</span><span class=identifier>ElemType</span><span class=special>,</span><span class=identifier>Traits</span><span class=special>&gt;&amp;</span> <span class=keyword>operator</span><span class=special>&lt;&lt;(</span>
  102. <span class=identifier>std</span><span class=special>::</span><span class=identifier>basic_ostream</span><span class=special>&lt;</span><span class=identifier>ElemType</span><span class=special>,</span><span class=identifier>Traits</span><span class=special>&gt;&amp;</span> <span class=identifier>out</span><span class=special>,</span>
  103. <span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  104. <span class=keyword>template</span><span class=special>&lt;</span>
  105. <span class=keyword>typename</span> <span class=identifier>ElemType</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Traits</span><span class=special>,</span>
  106. <span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span>
  107. <span class=special>&gt;</span>
  108. <span class=keyword>inline</span> <span class=identifier>std</span><span class=special>::</span><span class=identifier>basic_ostream</span><span class=special>&lt;</span><span class=identifier>ElemType</span><span class=special>,</span><span class=identifier>Traits</span><span class=special>&gt;&amp;</span> <span class=keyword>operator</span><span class=special>&gt;&gt;(</span>
  109. <span class=identifier>std</span><span class=special>::</span><span class=identifier>basic_istream</span><span class=special>&lt;</span><span class=identifier>ElemType</span><span class=special>,</span><span class=identifier>Traits</span><span class=special>&gt;&amp;</span> <span class=identifier>in</span><span class=special>,</span>
  110. <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  111. <span class=special>}</span> <span class=comment>// namespace boost::flyweights</span>
  112. <span class=keyword>using</span> <span class=identifier>flyweights</span><span class=special>::</span><span class=identifier>flyweight</span><span class=special>;</span>
  113. <span class=special>}</span> <span class=comment>// namespace boost</span>
  114. <span class=comment>// hash support:</span>
  115. <span class=keyword>namespace</span> <span class=identifier>std</span><span class=special>{</span>
  116. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>class</span> <span class=identifier>T</span><span class=special>&gt;</span> <span class=keyword>struct</span> <span class=identifier>hash</span><span class=special>;</span>
  117. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span><span class=special>&gt;</span>
  118. <span class=keyword>struct</span> <span class=identifier>hash</span><span class=special>&lt;</span><span class=identifier>boost</span><span class=special>::</span><span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;</span> <span class=special>&gt;;</span>
  119. <span class=special>}</span> <span class=comment>// namespace std</span>
  120. <span class=keyword>namespace</span> <span class=identifier>boost</span><span class=special>{</span>
  121. <span class=keyword>namespace</span> <span class=identifier>flyweights</span><span class=special>{</span>
  122. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,...,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span><span class=special>&gt;</span>
  123. <span class=keyword>inline</span> <span class=identifier>std</span><span class=special>::</span><span class=identifier>size_t</span> <span class=identifier>hash_value</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>,</span><span class=identifier>Arg1</span><span class=special>,...,</span><span class=identifier>Arg5</span><span class=special>&gt;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  124. <span class=special>}</span> <span class=comment>// namespace boost::flyweights</span>
  125. <span class=special>}</span> <span class=comment>// namespace boost</span>
  126. </pre></blockquote>
  127. <p>
  128. <code>flyweight_fwd.hpp</code> forward declares the class template
  129. <a href="#flyweight"><code>flyweight</code></a> and its associated global functions and class template specializations.
  130. </p>
  131. <h2>
  132. <a name="synopsis">Header
  133. <a href="../../../../boost/flyweight/flyweight.hpp"><code>"boost/flyweight/flyweight.hpp"</code></a>
  134. synopsis</a>
  135. </h2>
  136. <h3><a name="flyweight">
  137. Class template <code>flyweight</code>
  138. </a></h3>
  139. <p>
  140. Objects of type <code>flyweight&lt;...&gt;</code> provide access to immutable
  141. values of type <code>flyweight&lt;...&gt;::value_type</code>, with the following advantages over using
  142. plain <code>value_type</code> objects:
  143. <ul>
  144. <li>Flyweight objects with equivalent value share the same representation
  145. (the associated <code>value_type</code> object).
  146. </li>
  147. <li>The size of flyweights is typically that of a pointer, which is in general
  148. smaller than <code>sizeof(value_type)</code>.
  149. </li>
  150. </ul>
  151. So, if the level of redundancy (ratio of total objects to different values)
  152. is high enough, substituting a suitable instantiation of <code>flyweight</code>
  153. for <code>value_type</code> results in a reduction in memory usage.
  154. </p>
  155. <p>
  156. <code>flyweight</code> is parameterized according to some aspects:
  157. <ul>
  158. <li>Types <code>key_value</code> and <code>value_type</code>
  159. (possibly equal), where <code>key_type</code> serves as a
  160. key type to lookup and construct internal shared instances of
  161. objects of <code>value_type</code>.
  162. </li>
  163. <li>An optional <a href="tags.html#tag">tag</a> type meant to syntactically
  164. differentiate between otherwise identical instantiations.
  165. </li>
  166. <li>The <a href="factories.html#factory">factory class</a> used to store
  167. and retrieve the shared value objects.
  168. </li>
  169. <li>The type of <a href="holders.html#holder">holder</a> used to
  170. instantiate the flyweight factory and a mutex object, both of
  171. which are unique to each specialization of the <code>flyweight</code>
  172. class template.
  173. </li>
  174. <li>A <a href="locking.html#locking">locking policy</a> determining
  175. the synchronization mechanisms for internal access to shared resources.
  176. </li>
  177. <li>A <a href="tracking.html#tracking">tracking policy</a> which controls
  178. how values are treated when all their associated flyweight objects are
  179. destroyed.
  180. </li>
  181. </ul>
  182. These aspects impact the internal structure and behavior
  183. of the <code>flyweight</code> instantiation in the following manner:
  184. <ul>
  185. <li>Each instantation of <code>flyweight</code> internally owns
  186. a unique factory object and a unique synchronization
  187. <a href="locking.html#preliminary">mutex</a> object, both of which
  188. are created through the use of an associated holder type.
  189. </li>
  190. <li>The flyweight factory stores elements of an undisclosed type
  191. <code>Entry</code> that is implicitly convertible to
  192. <code>const key_type&amp;</code> and also stores a subobject of
  193. <code>value_type</code>. Every flyweight object is associated
  194. to a <code>value_type</code> subobject of some <code>Entry</code>
  195. stored in the factory.
  196. </li>
  197. <li>The associated mutex object is used to protect all invocations
  198. to the insertion and deletion functions of the internal flyweight
  199. factory.
  200. </li>
  201. <li>Each flyweight object internally stores a value of some
  202. undisclosed type <code>Handle</code>. <code>Handle</code> and
  203. the <code>Entry</code> type referred to above are obtained
  204. from invocations to the associated tracking policy, in the
  205. manner described for this concept.
  206. </li>
  207. </ul>
  208. In what follows, we implicitly assume that <code>key_type</code> equivalence
  209. refers to the equivalence relationship induced by the factory class used.
  210. Also, two values of <code>value_type</code> are considered equivalent
  211. if they are constructed from equivalent keys, or are copies of
  212. objects constructed from equivalent keys.
  213. </p>
  214. <blockquote><pre>
  215. <span class=preprocessor>#include</span> <span class=special>&lt;</span><span class=identifier>initializer_list</span><span class=special>&gt;</span>
  216. <span class=keyword>template</span><span class=special>&lt;</span>
  217. <span class=keyword>typename</span> <span class=identifier>T</span><span class=special>,</span>
  218. <span class=keyword>typename</span> <span class=identifier>Arg1</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg2</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg3</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg4</span><span class=special>,</span><span class=keyword>typename</span> <span class=identifier>Arg5</span>
  219. <span class=special>&gt;</span>
  220. <span class=keyword>class</span> <span class=identifier>flyweight</span>
  221. <span class=special>{</span>
  222. <span class=keyword>public</span><span class=special>:</span>
  223. <span class=keyword>typedef</span> <span class=identifier><b>dependent on T</b></span> <span class=identifier>key_type</span><span class=special>;</span>
  224. <span class=keyword>typedef</span> <span class=identifier><b>dependent on T</b></span> <span class=identifier>value_type</span><span class=special>;</span>
  225. <span class=comment>// static data initialization:</span>
  226. <span class=keyword>static</span> <span class=keyword>bool</span> <span class=identifier>init</span><span class=special>();</span>
  227. <span class=keyword>class</span> <span class=identifier>initializer</span><span class=special>{</span><span class=keyword>public</span><span class=special>:</span><span class=identifier>initializer</span><span class=special>();</span><span class=special>};</span>
  228. <span class=comment>// construct/copy/destroy:</span>
  229. <span class=identifier>flyweight</span><span class=special>();</span>
  230. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span><span class=special>...</span> <span class=identifier>Args</span><span class=special>&gt;</span>
  231. <span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>Args</span><span class=special>&amp;&amp;...</span> <span class=identifier>args</span><span class=special>);</span>
  232. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>V</span><span class=special>&gt;</span>
  233. <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>initializer_list</span><span class=special>&lt;</span><span class=identifier>V</span><span class=special>&gt;</span> <span class=identifier>list</span><span class=special>);</span>
  234. <span class=identifier>flyweight</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  235. <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  236. <span class=identifier>flyweight</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&amp;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  237. <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>flyweight</span><span class=special>&amp;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  238. <span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  239. <span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>value_type</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  240. <span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  241. <span class=keyword>explicit</span> <span class=identifier>flyweight</span><span class=special>(</span><span class=identifier>value_type</span><span class=special>&amp;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  242. <span class=keyword>template</span><span class=special>&lt;</span><span class=keyword>typename</span> <span class=identifier>V</span><span class=special>&gt;</span>
  243. <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=keyword>operator</span><span class=special>=(</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>initializer_list</span><span class=special>&lt;</span><span class=identifier>V</span><span class=special>&gt;</span> <span class=identifier>list</span><span class=special>);</span>
  244. <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=keyword>operator</span><span class=special>=(</span><span class=keyword>const</span> <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  245. <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=keyword>operator</span><span class=special>=(</span><span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  246. <span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=keyword>operator</span><span class=special>=(</span><span class=identifier>value_type</span><span class=special>&amp;&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  247. <span class=comment>// convertibility to underlying type:</span>
  248. <span class=keyword>const</span> <span class=identifier>key_type</span><span class=special>&amp;</span> <span class=identifier>get_key</span><span class=special>()</span><span class=keyword>const</span><span class=special>;</span>
  249. <span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;</span> <span class=identifier>get</span><span class=special>()</span><span class=keyword>const</span><span class=special>;</span>
  250. <span class=keyword>operator</span> <span class=keyword>const</span> <span class=identifier>value_type</span><span class=special>&amp;()</span><span class=keyword>const</span><span class=special>;</span>
  251. <span class=comment>// modifiers:</span>
  252. <span class=keyword>void</span> <span class=identifier>swap</span><span class=special>(</span><span class=identifier>flyweight</span><span class=special>&amp;</span> <span class=identifier>x</span><span class=special>);</span>
  253. <span class=special>};</span>
  254. </pre></blockquote>
  255. <h4><a name="instantiation_types">Instantiation types</a></h4>
  256. <p>
  257. <code>T</code> can be either:
  258. <ul>
  259. <li>An arbitrary type,</li>
  260. <li>a type of the form
  261. <a href="key_value.html#key_value_construct"><code>key_value&lt;Key,Value[,KeyFromValue]&gt;</code></a>.</li>
  262. </ul>
  263. In the first case, the nested types <code>key_type</code> and <code>value_type</code>
  264. are both equal to <code>T</code>. In the second case, <code>key_type</code>=<code>Key</code>,
  265. <code>value_type</code>=<code>Value</code>; we say then that the instantiation
  266. of <code>flyweight</code> is a <i>key-value</i> flyweight.
  267. <code>value_type</code> is the type of the values flyweight objects give access to,
  268. while value lookup is based on associated <code>key_type</code> values.
  269. <code>key_value</code> must be
  270. <a href="https://boost.org/sgi/stl/Assignable.html"><code>Assignable</code></a>
  271. and <code>value_type</code> must be constructible from <code>key_type</code>;
  272. additionally, <code>key_value</code> must
  273. conform to any extra requirements imposed by the type of factory used.
  274. For key-value flyweights, it is guaranteed that the creation or assignment of a flyweight
  275. object results in at most one construction (or copy construction in some
  276. particular cases) of an object
  277. of <code>value_type</code>, and this construction only occurs in the case that no
  278. equivalent value existed previously in the flyweight factory.
  279. </p>
  280. <p>
  281. The types <code>Arg1</code>, ... , <code>Arg5</code>, if provided, must be any
  282. of the following, in no particular order:
  283. <ul>
  284. <li>A <a href="tags.html#tag">tag</a>,</li>
  285. <li>a <a href="factories.html#factory">factory specifier</a>,</li>
  286. <li>a <a href="holders.html#holder">holder specifier</a>,</li>
  287. <li>a <a href="locking.html#locking">locking policy</a>,</li>
  288. <li>a <a href="tracking.html#tracking">tracking policy</a>.</li>
  289. </ul>
  290. No aspect can be specified twice. Each internal component of the
  291. <code>flyweight</code> instantiation is obtained through use of the
  292. corresponding specifier; for instance, the factory results from a
  293. certain (MPL) invocation of the given factory specifier, the internal
  294. mutex from the given locking policy, etc.
  295. The default configuration arguments are:
  296. <ul>
  297. <li>No tagging,</li>
  298. <li><a href="factories.html#hashed_factory"><code>hashed_factory&lt;&gt;</code></a>,</li>
  299. <li><a href="holders.html#static_holder"><code>static_holder</code></a>,</li>
  300. <li><a href="locking.html#simple_locking"><code>simple_locking</code></a>,</li>
  301. <li><a href="tracking.html#refcounted"><code>refcounted</code></a> tracking policy.</li>
  302. </ul>
  303. </p>
  304. <h4><a name="static_init">Static data initialization</a></h4>
  305. <p>
  306. The static data internal to a given <code>flyweight</code> instantiation
  307. (factory instance, etc.) is constructed during the dynamic initialization
  308. phase of the program and always before the first program-wide use of the
  309. instantiated class. The following utilities can be
  310. used when more control about the moment of construction is required.
  311. </p>
  312. <code>static bool init();</code>
  313. <blockquote>
  314. <b>Effects:</b> After execution of this function the static data associated
  315. to the instantiation of <code>flyweight</code> is guaranteed to be
  316. constructed.<br>
  317. <b>Note:</b> Concurrent execution of this function is not thread safe.
  318. </blockquote>
  319. <code>initializer::initializer();</code>
  320. <blockquote>
  321. <b>Effects:</b> Executes <code>init()</code>.
  322. </blockquote>
  323. <h4><a name="constructors">Constructors, copy and assignment</a></h4>
  324. <code>flyweight();</code>
  325. <blockquote>
  326. <b>Effects:</b> Constructs a <code>flyweight</code> object with the value
  327. <code>value_type(key_type())</code>
  328. if <code>flyweight</code> is key-value
  329. or <code>value_type()</code>
  330. otherwise.
  331. </blockquote>
  332. <a name="fwd_ctor">
  333. <code>template&lt;typename... Args&gt;<br>
  334. explicit flyweight(Args&amp;&amp;... args);</code></a>
  335. <blockquote>
  336. <b>Effects:</b> Constructs a <code>flyweight</code> object with the value
  337. <code>value_type(key_type(std::forward&lt;Args&gt;(args)...))</code>
  338. if <code>flyweight</code> is key-value
  339. or <code>value_type(std::forward&lt;Args&gt;(args)...)</code>
  340. otherwise.<br>
  341. <b>Note:</b> In compilers without variadic template support, the implementation
  342. replaces this constructor with a number of overloads accepting
  343. any combination of const/non-const lvalue/rvalue reference arguments
  344. up to a maximum number that
  345. can be globally <a href="#limit_num_ctor_args">configured</a> by the user.
  346. </blockquote>
  347. <code>template&lt;typename V&gt;<br>
  348. flyweight(std::initializer_list&lt;V&gt; list);</code>
  349. <blockquote>
  350. <b>Effects:</b> Constructs a <code>flyweight</code> object with the value
  351. <code>value_type(key_type(list))</code> if <code>flyweight</code> is key-value
  352. or <code>value_type(list)</code> otherwise.<br>
  353. <b>Note:</b> The specialization for a particular <code>std::initializer_list&lt;V'&gt;</code>
  354. of this member function template is not available unless
  355. <code>key_type</code> is constructible from
  356. <code>std::initializer_list&lt;V'&gt;</code>.
  357. </blockquote>
  358. <code>flyweight(const flyweight&amp; x);<br>
  359. flyweight(flyweight&amp; x);<br>
  360. flyweight(const flyweight&amp;&amp; x);<br>
  361. flyweight(flyweight&amp;&amp; x);</code>
  362. <blockquote>
  363. <b>Effects:</b> Constructs a <code>flyweight</code> object associated to
  364. the same value as <code>x</code>.<br>
  365. <b>Exception safety:</b> <code>nothrow</code>.
  366. </blockquote>
  367. <code>explicit flyweight(const value_type&amp; x);<br>
  368. explicit flyweight(value_type&amp; x);<br>
  369. explicit flyweight(const value_type&amp;&amp; x);<br>
  370. explicit flyweight(value_type&amp;&amp; x);</code>
  371. <blockquote>
  372. <b>Requires:</b> If <code>flyweight</code> is key-value,
  373. <code>value_type</code> is
  374. <a href="https://boost.org/sgi/stl/Assignable.html"><code>Assignable</code></a>
  375. and the
  376. <a href="key_value.html#key_extractor"><code>Key Extractor</code></a>
  377. <code>KeyFromValue</code> must have been supplied as part of the
  378. <code>key_value&lt;&gt;</code> construct.<br>
  379. <b>Effects:</b> Constructs a <code>flyweight</code> associated to a
  380. copy of <code>x</code> or with a <code>value_type</code> constructed
  381. from a key equivalent to that associated to <code>x</code>. For non-key-value
  382. flyweights, <code>x</code> is its own key; for key-value flyweights,
  383. the key is extracted through use of an object of type <code>KeyFromValue</code>.<br>
  384. </blockquote>
  385. <code>template&lt;typename V&gt;<br>
  386. flyweight&amp; operator=(std::initializer_list&lt;V&gt; list);</code>
  387. <blockquote>
  388. <b>Effects:</b> <code>*this=flyweight(list)</code>.<br>
  389. <b>Returns:</b> <code>*this</code>.<br>
  390. <b>Note:</b> The specialization for a particular <code>std::initializer_list&lt;V'&gt;</code>
  391. of this member function template is not available unless
  392. <code>key_type</code> is constructible from
  393. <code>std::initializer_list&lt;V'&gt;</code>.
  394. </blockquote>
  395. <code>flyweight&amp; operator=(const flyweight&amp; x);</code>
  396. <blockquote>
  397. <b>Effects:</b> Associates the <code>flyweight</code> object with the same value
  398. as <code>x</code>.<br>
  399. <b>Returns:</b> <code>*this</code>.<br>
  400. <b>Exception safety:</b> <code>nothrow</code>.
  401. </blockquote>
  402. <code>flyweight&amp; operator=(const value_type&amp; x);<br>
  403. flyweight&amp; operator=(value_type&amp;&amp; x);</code>
  404. <blockquote>
  405. <b>Effects:</b> <code>*this=flyweight(x)</code> (first overload),
  406. <code>*this=flyweight(std::move(x))</code> (second overload).<br>
  407. <b>Returns:</b> <code>*this</code>.<br>
  408. </blockquote>
  409. <h4><a name="convertibility">Convertibility to the underlying types</a></h4>
  410. <code>const key_type&amp; get_key()const;</code>
  411. <blockquote>
  412. <b>Returns:</b> A copy of the key used to construct the
  413. <code>value_type</code> associated to the <code>flyweight</code>
  414. object.<br>
  415. <b>Exception safety:</b> If <code>flyweight</code> is not key-value or
  416. if <code>KeyFromValue</code> was not provided, <code>nothrow</code>.
  417. </blockquote>
  418. <code>const value_type&amp; get()const;<br>
  419. operator const value_type&amp;()const;</code>
  420. <blockquote>
  421. <b>Returns:</b> The value associated to the <code>flyweight</code>
  422. object.<br>
  423. <b>Exception safety:</b> <code>nothrow</code>.
  424. </blockquote>
  425. <h4><a name="modifiers">Modifiers</a></h4>
  426. <code>void swap(flyweight&amp; x);</code>
  427. <blockquote>
  428. <b>Effects:</b> Swaps the associations to <code>value_type</code>s each
  429. flyweight object has. No swapping of <code>key_type</code> or
  430. <code>value_type</code> objects is done.<br>
  431. <b>Exception safety:</b> <code>nothrow</code>.
  432. </blockquote>
  433. <h4><a name="comparison">Comparison operators</a></h4>
  434. <code>template&lt;<br>
  435. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  436. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  437. &gt;<br>
  438. bool operator ==(<br>
  439. &nbsp;&nbsp;const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,<br>
  440. &nbsp;&nbsp;const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);</code>
  441. <blockquote>
  442. <b>Returns:</b> If <code>x</code> and <code>y</code> are of the same type, returns
  443. <code>true</code> if and only if they are associated to the same value; if
  444. <code>x</code> and <code>y</code> have different types, returns
  445. <code>x.get()==y.get()</code>.<br>
  446. <b>Exception safety:</b> If <code>x</code> and <code>y</code> are of the same type,
  447. <code>nothrow</code>.
  448. </blockquote>
  449. <code>template&lt;<br>
  450. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  451. &nbsp;&nbsp;typename T2<br>
  452. &gt;<br>
  453. bool operator ==(const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,const T2&amp; y);</code>
  454. <blockquote>
  455. <b>Returns:</b> <code>x.get()==y</code>.
  456. </blockquote>
  457. <code>template&lt;<br>
  458. &nbsp;&nbsp;typename T1,<br>
  459. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  460. &gt;<br>
  461. bool operator ==(const T1&amp; x,const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);</code>
  462. <blockquote>
  463. <b>Returns:</b> <code>x==y.get()</code>.
  464. </blockquote>
  465. <code>template&lt;<br>
  466. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  467. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  468. &gt;<br>
  469. bool operator &lt;(<br>
  470. &nbsp;&nbsp;const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,<br>
  471. &nbsp;&nbsp;const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);</code>
  472. <blockquote>
  473. <b>Returns:</b> <code>x.get()&lt;y.get()</code>.
  474. </blockquote>
  475. <code>template&lt;<br>
  476. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  477. &nbsp;&nbsp;typename T2<br>
  478. &gt;<br>
  479. bool operator &lt;(const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,const T2&amp; y);</code>
  480. <blockquote>
  481. <b>Returns:</b> <code>x.get()&lt;y</code>.
  482. </blockquote>
  483. <code>template&lt;<br>
  484. &nbsp;&nbsp;typename T1,<br>
  485. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  486. &gt;<br>
  487. bool operator &lt;(const T1&amp; x,const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);</code>
  488. <blockquote>
  489. <b>Returns:</b> <code>x&lt;y.get()</code>.
  490. </blockquote>
  491. <code>template&lt;<br>
  492. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  493. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  494. &gt;<br>
  495. bool operator <b><i>OP</i></b>(<br>
  496. &nbsp;&nbsp;const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,<br>
  497. &nbsp;&nbsp;const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);<br>
  498. template&lt;<br>
  499. &nbsp;&nbsp;typename T1,typename Arg11,...,typename Arg15,<br>
  500. &nbsp;&nbsp;typename T2<br>
  501. &gt;<br>
  502. bool operator <b><i>OP</i></b>(const flyweight&lt;T1,Arg11,...,Arg15&gt;&amp; x,const T2&amp; y);</br>
  503. template&lt;<br>
  504. &nbsp;&nbsp;typename T1,<br>
  505. &nbsp;&nbsp;typename T2,typename Arg21,...,typename Arg25<br>
  506. &gt;<br>
  507. bool operator <b><i>OP</i></b>(const T1&amp; x,const flyweight&lt;T2,Arg21,...,Arg25&gt;&amp; y);</code>
  508. <p>
  509. (<code><b><i>OP</i></b></code> is any of <code>!=</code>, <code>></code>,
  510. <code>>=</code>, <code>&lt;=</code>.)
  511. </p>
  512. <blockquote>
  513. <b>Returns:</b> <code>true</code> if and only if
  514. <blockquote>
  515. <code>!(x==y)</code> (<code><b><i>OP</i></b></code> is <code>!=</code>),<br>
  516. <code>&nbsp;&nbsp;y&lt;&nbsp;x&nbsp;</code> (<code><b><i>OP</i></b></code> is <code>>&nbsp;</code>),<br>
  517. <code>!(x&lt;&nbsp;y)</code> (<code><b><i>OP</i></b></code> is <code>>=</code>),<br>
  518. <code>!(y&lt;&nbsp;x)</code> (<code><b><i>OP</i></b></code> is <code>&lt;=</code>).
  519. </blockquote>
  520. </blockquote>
  521. <h4><a name="specialized">Specialized algorithms</a></h4>
  522. <code>template&lt;typename T,typename Arg1,...,typename Arg5&gt;<br>
  523. inline void swap(<br>
  524. &nbsp;&nbsp;flyweight&lt;T,Arg1,...,Arg5&gt;&amp; x,flyweight&lt;T,Arg1,...,Arg5&gt;&amp; y);</code>
  525. <blockquote>
  526. <b>Effects:</b> <code>x.swap(y)</code>.
  527. </blockquote>
  528. <code>template&lt;<br>
  529. &nbsp;&nbsp;typename ElemType,typename Traits, <br>
  530. &nbsp;&nbsp;typename T,typename Arg1,...,typename Arg5<br>
  531. &gt;<br>
  532. inline std::basic_ostream&lt;ElemType,Traits&gt;&amp; operator&lt;&lt;(<br>
  533. &nbsp;&nbsp;std::basic_ostream&lt;ElemType,Traits&gt;&amp; out,<br>
  534. &nbsp;&nbsp;const flyweight&lt;T,Arg1,...,Arg5&gt;&amp; x);</code>
  535. <blockquote>
  536. <b>Effects:</b> <code>out&lt;&lt;x.get()</code>.<br>
  537. <b>Returns:</b> <code>out</code>.
  538. </blockquote>
  539. <code>template&lt;<br>
  540. &nbsp;&nbsp;typename ElemType,typename Traits, <br>
  541. &nbsp;&nbsp;typename T,typename Arg1,...,typename Arg5<br>
  542. &gt;<br>
  543. inline std::basic_ostream&lt;ElemType,Traits&gt;&amp; operator&gt;&gt;(<br>
  544. &nbsp;&nbsp;std::basic_istream&lt;ElemType,Traits&gt;&amp; in,<br>
  545. &nbsp;&nbsp;flyweight&lt;T,Arg1,...,Arg5&gt;&amp; x);</code>
  546. <blockquote>
  547. <b>Requires:</b> If <code>flyweight</code> is key-value,
  548. <code>value_type</code> is
  549. <a href="https://boost.org/sgi/stl/Assignable.html"><code>Assignable</code></a>
  550. and the
  551. <a href="key_value.html#key_extractor"><code>Key Extractor</code></a>
  552. <code>KeyFromValue</code> must have been supplied as part of the
  553. <code>key_value&lt;&gt;</code> construct.<br>
  554. <b>Effects:</b> Reads an object of type <code>value_type</code> from <code>in</code>
  555. and assigns it to <code>x</code>.<br>
  556. <b>Returns:</b> <code>in</code>.
  557. </blockquote>
  558. <h4><a name="hash">Hash support</a></h4>
  559. <p>
  560. Support is provided for hashing <code>flyweight</code>s both with <code>std::hash</code> and
  561. <a href="../../../../doc/html/hash.html"><code>boost::hash</code></a>. In either case, the calculation
  562. does not involve hashing the associated <code>value_type</code> objects themselves; so, it is
  563. immaterial whether <code>value_type</code> is hashable or not.
  564. The results given by <code>std::hash</code> and <code>boost::hash</code> for the same
  565. <code>flyweight</code> object will usually differ.<br />
  566. <b>Note:</b> Hash support can be <a href="#disable_hash_support">disabled</a> to solve
  567. clashes with code where this has already been defined by the user.
  568. </p>
  569. <code>namespace std{<br>
  570. template&lt;typename T,typename Arg1,...,typename Arg5&gt;<br>
  571. struct hash&lt;boost::flyweight&lt;T,Arg1,...,Arg5&gt; &gt;;<br>
  572. }</code>
  573. <blockquote>
  574. This template specialization meets the requirements of class template <code>std::hash</code> in <b>[unord.hash]</b>.
  575. No exception is thrown when invoking instances of this specialization.
  576. </blockquote>
  577. <code>template&lt;typename T,typename Arg1,...,typename Arg5&gt;<br>
  578. inline std::size_t hash_value(const flyweight&lt;T,Arg1,...,Arg5&gt;&amp; x);</code>
  579. <blockquote>
  580. <b>Returns:</b> A hash value for <code>x</code> to be used by
  581. <a href="../../../../doc/html/hash/custom.html">Boost.Hash</a>.<br>
  582. <b>Exception safety:</b> <code>nothrow</code>.
  583. </blockquote>
  584. <h4><a name="config_macros">Configuration macros</a></h4>
  585. <a name="limit_num_ctor_args">
  586. <code>BOOST_FLYWEIGHT_LIMIT_PERFECT_FWD_ARGS</code></a>
  587. <blockquote>
  588. In compilers without variadic template support,
  589. globally define this macro to set the maximum number of
  590. arguments accepted by <code>flyweight</code>
  591. <a href="#fwd_ctor">forwarding constructor</a>, which by default
  592. is 5.
  593. </blockquote>
  594. <a name="disable_hash_support">
  595. <code>BOOST_FLYWEIGHT_DISABLE_HASH_SUPPORT</code></a>
  596. <blockquote>
  597. If defined, hash support is not provided. This can be useful to cope
  598. with legacy code where general <code>flyweight</code> hashing has already been
  599. defined by the user.
  600. </blockquote>
  601. <h2>
  602. <a name="serialize_synopsis">Header
  603. </a><a href="../../../../boost/flyweight/serialize.hpp"><code>"boost/flyweight/serialize.hpp"</code></a>
  604. synopsis
  605. </h2>
  606. <p>
  607. <code>serialize.hpp</code> includes the necessary functionality for interoperability
  608. of <code>flyweight</code> with
  609. <a href="../../../serialization/index.html">Boost.Serialization</a>.
  610. </p>
  611. <h3><a name="serialization">Serialization</a></h3>
  612. <p>
  613. <code>flyweight</code>s can be archived and retrieved by means of
  614. <a href="../../../serialization/index.html">Boost.Serialization</a>. Regular as well
  615. as XML archives are supported.
  616. Serialization is done in an efficient manner so that saving equivalent <code>flyweight</code>s
  617. result in their common <code>key_type</code> value being stored only once, regardless
  618. of whether <code>key_type</code> is
  619. <a href="../../../serialization/doc/traits.html#tracking">tracked</a> by
  620. Boost.Serialization or not.
  621. </p>
  622. Operation: saving of a <code>flyweight</code> object <code>x</code> to an
  623. output archive (XML archive) <code>ar</code>.
  624. <blockquote>
  625. <b>Requires:</b> <code>key_type</code> is serializable (XML-serializable).<br>
  626. <b>Effects:</b> The value <code>k=x.get_key()</code> is saved into <code>ar</code> as
  627. part of this operation or of a previous saving operation of a <code>flyweight</code>
  628. object with the same key.<br>
  629. <b>Exception safety:</b> Strong with respect to <code>x</code>. If an exception
  630. is thrown, <code>ar</code> may be left in an inconsistent state.
  631. </blockquote>
  632. Operation: loading of a <code>flyweight</code> <code>x'</code> from an
  633. input archive (XML archive) <code>ar</code>.
  634. <blockquote>
  635. <b>Requires:</b> <code>key_type</code> is serializable (XML-serializable).<br>
  636. <b>Effects:</b> <code>x'</code> is associated to a value constructed from a key
  637. equivalent to <code>k'</code>, a restored copy of the value <code>k</code>
  638. defined above.<br>
  639. <b>Exception safety:</b> Strong with respect to <code>x'</code>. If an exception
  640. is thrown, <code>ar</code> may be left in an inconsistent state.
  641. </blockquote>
  642. <hr>
  643. <div class="prev_link"><a href="index.html"><img src="../prev.gif" alt="Boost.Flyweight reference" border="0"><br>
  644. Boost.Flyweight reference
  645. </a></div>
  646. <div class="up_link"><a href="index.html"><img src="../up.gif" alt="Boost.Flyweight reference" border="0"><br>
  647. Boost.Flyweight reference
  648. </a></div>
  649. <div class="next_link"><a href="key_value.html"><img src="../next.gif" alt="key-value flyweights" border="0"><br>
  650. Key-value flyweights
  651. </a></div><br clear="all" style="clear: all;">
  652. <br>
  653. <p>Revised April 24th 2019</p>
  654. <p>&copy; Copyright 2006-2019 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
  655. Distributed under the Boost Software
  656. License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
  657. LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  658. http://www.boost.org/LICENSE_1_0.txt</a>)
  659. </p>
  660. </body>
  661. </html>