deconstruct.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE header PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
  3. "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
  4. <!--
  5. Copyright Frank Mori Hess 2009
  6. Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <header name="boost/signals2/deconstruct.hpp" last-revision="$Date: 2007-03-06 16:51:55 -0500 (Tue, 06 Mar 2007) $">
  10. <using-namespace name="boost::signals2"/>
  11. <using-namespace name="boost"/>
  12. <namespace name="boost">
  13. <namespace name="signals2">
  14. <overloaded-function name="deconstruct">
  15. <signature>
  16. <template>
  17. <template-type-parameter name="T"/>
  18. </template>
  19. <type><classname>postconstructor_invoker</classname>&lt;T&gt;</type>
  20. </signature>
  21. <signature>
  22. <template>
  23. <template-type-parameter name="T"/>
  24. <template-type-parameter name="A1"/>
  25. </template>
  26. <type><classname>postconstructor_invoker</classname>&lt;T&gt;</type>
  27. <parameter name="arg1"><paramtype>const A1 &amp;</paramtype></parameter>
  28. </signature>
  29. <signature>
  30. <template>
  31. <template-type-parameter name="T"/>
  32. <template-type-parameter name="A1"/>
  33. <template-type-parameter name="A2"/>
  34. </template>
  35. <type><classname>postconstructor_invoker</classname>&lt;T&gt;</type>
  36. <parameter name="arg1"><paramtype>const A1 &amp;</paramtype></parameter>
  37. <parameter name="arg2"><paramtype>const A2 &amp;</paramtype></parameter>
  38. </signature>
  39. <signature>
  40. <template>
  41. <template-type-parameter name="T"/>
  42. <template-type-parameter name="A1"/>
  43. <template-type-parameter name="A2, ..."/>
  44. <template-type-parameter name="AN"/>
  45. </template>
  46. <type><classname>postconstructor_invoker</classname>&lt;T&gt;</type>
  47. <parameter name="arg1"><paramtype>const A1 &amp;</paramtype></parameter>
  48. <parameter name="arg2"><paramtype>const A2 &amp;</paramtype></parameter>
  49. <parameter name=""><paramtype>...</paramtype></parameter>
  50. <parameter name="argN"><paramtype>const AN &amp;</paramtype></parameter>
  51. </signature>
  52. <purpose>Create a <code>shared_ptr</code> with support for post-constructors and pre-destructors.</purpose>
  53. <description>
  54. <para>Creates an object and its owning <code>shared_ptr&lt;T&gt;</code>
  55. (wrapped inside a <classname>postconstructor_invoker</classname>)
  56. using only a single allocation,
  57. in a manner similar
  58. to that of <functionname>boost::make_shared()</functionname>. In addition, <code>deconstruct</code>
  59. supports postconstructors and predestructors. The returned
  60. <classname>shared_ptr</classname> is wrapped inside a <classname>postconstructor_invoker</classname>
  61. in order to provide the user with an opportunity to pass arguments to a postconstructor,
  62. while insuring the postconstructor is run before the wrapped
  63. <classname>shared_ptr</classname> is accessible.
  64. </para>
  65. <para>
  66. In order to use <code>deconstruct</code> you must define a postconstructor for your class.
  67. More specifically, you must define
  68. an <code>adl_postconstruct</code> function which can be found via argument-dependent
  69. lookup. Typically, this means defining an <code>adl_postconstruct</code> function
  70. in the same namespace as its associated class. See the reference for
  71. <classname>postconstructor_invoker</classname>
  72. for a specification of what arguments are passed to the <code>adl_postconstruct</code>
  73. call.
  74. </para>
  75. <para>
  76. Optionally, you may define a predestructor for your class. This is done by
  77. defining an <code>adl_predestruct</code> function which may be found
  78. by argument-dependent lookup. The deleter of the <classname>shared_ptr</classname>
  79. created by <code>deconstruct</code> will make an unqualified call to
  80. <code>adl_predestruct</code> with a single
  81. argument: a pointer to the object which is about to be deleted.
  82. As a convenience, the pointer will always be cast to point to a non-const type
  83. before being passed to <code>adl_predestruct</code>.
  84. If no user-defined <code>adl_predestruct</code> function is found via
  85. argument-dependent lookup, a default function (which does nothing) will
  86. be used. After <code>adl_predestruct</code> is called, the deleter
  87. will delete the object with
  88. <functionname>checked_delete</functionname>.
  89. </para>
  90. <para>
  91. Any arguments passed to a
  92. <code>deconstruct()</code> call are forwarded to the matching constructor of the
  93. template type
  94. <code>T</code>. Arguments may also be passed to the class' associated
  95. <code>adl_postconstruct</code> function by using the
  96. <methodname>postconstructor_invoker::postconstruct()</methodname> methods.
  97. </para>
  98. </description>
  99. <notes>
  100. <para>If your compiler supports the C++11 features of rvalue references
  101. and variadic templates, then <code>deconstruct</code> will perform perfect
  102. forwarding of arguments to the <code>T</code> constructor, using
  103. a prototype of:
  104. </para>
  105. <programlisting>template&lt; typename T, typename... Args > postconstructor_invoker&lt; T &gt; deconstruct( Args &amp;&amp; ... args );</programlisting>
  106. <para>Otherwise, argument forwarding is performed via const references, as specified in
  107. the synopsis. In order to pass non-const references to a constructor, you will need
  108. to wrap them in reference wrappers using <functionname>boost::ref</functionname>.
  109. </para>
  110. <para>You may give all the <code>deconstruct</code> overloads access to your class'
  111. private and protected constructors by
  112. declaring <classname>deconstruct_access</classname> a friend. Using private
  113. constructors in conjunction with <classname>deconstruct_access</classname>
  114. can be useful to
  115. ensure your objects are only created by <code>deconstruct</code>, and thus
  116. their postconstructors or predestructors will always be called.
  117. </para>
  118. </notes>
  119. <returns><para>A <code>postconstructor_invoker&lt;T&gt;</code> owning a newly allocated object of
  120. type <code>T</code>.</para>
  121. </returns>
  122. </overloaded-function>
  123. <class name="deconstruct_access">
  124. <purpose>Gives <functionname>deconstruct</functionname> access to private/protected constructors.</purpose>
  125. <description>
  126. <para>
  127. Declaring <code>deconstruct_access</code> a friend to your class will give the
  128. <functionname>deconstruct</functionname> factory function access to your class' private and
  129. protected constructors. Using private
  130. constructors in conjunction with <code>deconstruct_access</code>
  131. can be useful to
  132. ensure <classname>postconstructible</classname> or <classname>predestructible</classname>
  133. objects are always created
  134. properly using <code>deconstruct</code>.
  135. </para>
  136. </description>
  137. </class>
  138. <class name="postconstructor_invoker">
  139. <method-group name="public methods">
  140. <method name="conversion-operator">
  141. <type>const shared_ptr&lt;T&gt; &amp;</type>
  142. <description>
  143. <para>
  144. The conversion operator has the same effect as explicitly calling
  145. the <methodname>postconstruct</methodname> method with no arguments.
  146. </para>
  147. </description>
  148. </method>
  149. <overloaded-method name="postconstruct" cv="const">
  150. <signature>
  151. <type>const shared_ptr&lt;T&gt; &amp;</type>
  152. </signature>
  153. <signature>
  154. <template>
  155. <template-type-parameter name="A1"/>
  156. </template>
  157. <type>const shared_ptr&lt;T&gt; &amp;</type>
  158. <parameter name="a1"><paramtype>A1</paramtype></parameter>
  159. </signature>
  160. <signature>
  161. <template>
  162. <template-type-parameter name="A1"/>
  163. <template-type-parameter name="A2"/>
  164. </template>
  165. <type>const shared_ptr&lt;T&gt; &amp;</type>
  166. <parameter name="a1"><paramtype>A1</paramtype></parameter>
  167. <parameter name="a2"><paramtype>A1</paramtype></parameter>
  168. </signature>
  169. <signature>
  170. <template>
  171. <template-type-parameter name="A1"/>
  172. <template-type-parameter name="A2, ..."/>
  173. <template-type-parameter name="AN"/>
  174. </template>
  175. <type>const shared_ptr&lt;T&gt; &amp;</type>
  176. <parameter name="a1"><paramtype>A1</paramtype></parameter>
  177. <parameter name="a2"><paramtype>A1</paramtype></parameter>
  178. <parameter name=""><paramtype>...</paramtype></parameter>
  179. <parameter name="aN"><paramtype>A1</paramtype></parameter>
  180. </signature>
  181. <description>
  182. <para>
  183. The <code>postconstruct</code> methods make an unqualified call to
  184. <code>adl_postconstruct()</code> and then return the <classname>shared_ptr</classname>
  185. which was wrapped inside the <code>postconstructor_invoker</code>
  186. object by <functionname>deconstruct()</functionname>.
  187. The first two arguments passed to the
  188. <code>adl_postconstruct()</code> call are always the <classname>shared_ptr</classname>
  189. owning the object created by <functionname>deconstruct()</functionname>,
  190. followed by a ordinary pointer to the same object. As a convenience,
  191. the ordinary pointer
  192. will always be cast to point to a non-const type before being passed
  193. to <code>adl_postconstruct</code>. The remaining arguments passed to
  194. <code>adl_postconstruct</code> are whatever arguments the user may have
  195. passed to the <code>postconstruct</code>
  196. method.
  197. </para>
  198. </description>
  199. </overloaded-method>
  200. </method-group>
  201. <purpose>Pass arguments to and run postconstructors for objects created with <functionname>deconstruct()</functionname>.</purpose>
  202. <description>
  203. <para>
  204. Objects of type <code>postconstructor_invoker</code> are returned by calls to the
  205. <functionname>deconstruct()</functionname> factory function. These objects are intended
  206. to either be immediately assigned to a <classname>shared_ptr</classname> (in which case the
  207. class' conversion operator will perform the conversion by calling the
  208. <methodname>postconstruct</methodname> with no arguments), or to be converted
  209. to <classname>shared_ptr</classname> explicitly by the user calling one of
  210. the <methodname>postconstruct</methodname> methods.
  211. </para>
  212. </description>
  213. </class>
  214. </namespace>
  215. </namespace>
  216. </header>