inherit.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" />
  7. <title>The MPL Reference Manual: inherit</title>
  8. <link rel="stylesheet" href="../style.css" type="text/css" />
  9. </head>
  10. <body class="docframe refmanual">
  11. <table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./always.html" class="navigation-link">Prev</a>&nbsp;<a href="./inherit-linearly.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./always.html" class="navigation-link">Back</a>&nbsp;<a href="./inherit-linearly.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
  12. <td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./metafunctions.html" class="navigation-link">Metafunctions</a> / <a href="./miscellaneous.html" class="navigation-link">Miscellaneous</a> / <a href="./inherit.html" class="navigation-link">inherit</a></td>
  13. </tr></table><div class="header-separator"></div>
  14. <div class="section" id="inherit">
  15. <h1><a class="toc-backref" href="./miscellaneous.html#id1566">inherit</a></h1>
  16. <div class="section" id="id1163">
  17. <h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3>
  18. <pre class="literal-block">
  19. template&lt;
  20. typename T1, typename T2
  21. &gt;
  22. struct <a href="./inherit.html" class="identifier">inherit</a><tt class="literal"><span class="pre">2</span></tt>
  23. {
  24. typedef <em>unspecified</em> type;
  25. };
  26. <em>...</em>
  27. template&lt;
  28. typename T1, typename T2,<em>...</em> typename T<em>n</em>
  29. &gt;
  30. struct <a href="./inherit.html" class="identifier">inherit</a><em>n</em>
  31. {
  32. typedef <em>unspecified</em> type;
  33. };
  34. template&lt;
  35. typename T1
  36. , typename T2
  37. <em>...</em>
  38. , typename T<em>n</em> = <em>unspecified</em>
  39. &gt;
  40. struct <a href="./inherit.html" class="identifier">inherit</a>
  41. {
  42. typedef <em>unspecified</em> type;
  43. };
  44. </pre>
  45. </div>
  46. <div class="section" id="id1164">
  47. <h3><a class="subsection-title" href="#description" name="description">Description</a></h3>
  48. <p>Returns an unspecified class type publically derived from <tt class="literal"><span class="pre">T1</span></tt>, <tt class="literal"><span class="pre">T2</span></tt>,... <tt class="literal"><span class="pre">Tn</span></tt>.
  49. Guarantees that derivation from <a class="reference internal" href="./empty-base.html">empty_base</a> is always a no-op,
  50. regardless of the position and number of <a class="reference internal" href="./empty-base.html">empty_base</a> classes in
  51. <tt class="literal"><span class="pre">T1</span></tt>, <tt class="literal"><span class="pre">T2</span></tt>,... <tt class="literal"><span class="pre">Tn</span></tt>.</p>
  52. </div>
  53. <div class="section" id="id1165">
  54. <h3><a class="subsection-title" href="#header" name="header">Header</a></h3>
  55. <pre class="literal-block">
  56. #include &lt;<a href="../../../../boost/mpl/inherit.hpp" class="header">boost/mpl/inherit.hpp</a>&gt;
  57. </pre>
  58. </div>
  59. <div class="section" id="id1166">
  60. <h3><a class="subsection-title" href="#model-of" name="model-of">Model of</a></h3>
  61. <p><a class="reference internal" href="./metafunction.html">Metafunction</a></p>
  62. </div>
  63. <div class="section" id="id1167">
  64. <h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3>
  65. <table border="1" class="docutils table">
  66. <colgroup>
  67. <col width="22%" />
  68. <col width="28%" />
  69. <col width="51%" />
  70. </colgroup>
  71. <thead valign="bottom">
  72. <tr><th class="head">Parameter</th>
  73. <th class="head">Requirement</th>
  74. <th class="head">Description</th>
  75. </tr>
  76. </thead>
  77. <tbody valign="top">
  78. <tr><td><tt class="literal"><span class="pre">T1</span></tt>, <tt class="literal"><span class="pre">T2</span></tt>,... <tt class="literal"><span class="pre">Tn</span></tt></td>
  79. <td>A class type</td>
  80. <td>Classes to derived from.</td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. <div class="section" id="id1168">
  86. <h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3>
  87. <p>For artibrary class types <em>t</em><sub>1</sub>,<em>t</em><sub>2</sub>,... <em>t</em><sub>n</sub>:</p>
  88. <pre class="literal-block">
  89. typedef inherit2&lt;t1,t2&gt;::type r;
  90. </pre>
  91. <table class="docutils field-list" frame="void" rules="none">
  92. <col class="field-name" />
  93. <col class="field-body" />
  94. <tbody valign="top">
  95. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p>
  96. </td>
  97. </tr>
  98. <tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><p class="first"><tt class="literal"><span class="pre">t1</span></tt> and <tt class="literal"><span class="pre">t2</span></tt> are complete types.</p>
  99. </td>
  100. </tr>
  101. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">If both <tt class="literal"><span class="pre">t1</span></tt> and <tt class="literal"><span class="pre">t2</span></tt> are identical to <tt class="literal"><span class="pre"><a href="./empty-base.html" class="identifier">empty_base</a></span></tt>, equivalent to</p>
  102. <pre class="literal-block">
  103. typedef <a href="./empty-base.html" class="identifier">empty_base</a> r;
  104. </pre>
  105. <p>otherwise, if <tt class="literal"><span class="pre">t1</span></tt> is identical to <tt class="literal"><span class="pre"><a href="./empty-base.html" class="identifier">empty_base</a></span></tt>, equivalent to</p>
  106. <pre class="literal-block">
  107. typedef t2 r;
  108. </pre>
  109. <p>otherwise, if <tt class="literal"><span class="pre">t2</span></tt> is identical to <tt class="literal"><span class="pre"><a href="./empty-base.html" class="identifier">empty_base</a></span></tt>, equivalent to</p>
  110. <pre class="literal-block">
  111. typedef t1 r;
  112. </pre>
  113. <p>otherwise equivalent to</p>
  114. <pre class="last literal-block">
  115. struct r : t1, t2 {};
  116. </pre>
  117. </td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. <!-- ........................................................................... -->
  122. <pre class="literal-block">
  123. typedef <a href="./inherit.html" class="identifier">inherit</a><em>n</em>&lt;t1,t2,<em>...</em>t<em>n</em>&gt;::type r;
  124. </pre>
  125. <table class="docutils field-list" frame="void" rules="none">
  126. <col class="field-name" />
  127. <col class="field-body" />
  128. <tbody valign="top">
  129. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p>
  130. </td>
  131. </tr>
  132. <tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><p class="first"><em>t</em><sub>1</sub>,<em>t</em><sub>2</sub>,... <em>t</em><sub>n</sub> are complete types.</p>
  133. </td>
  134. </tr>
  135. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p>
  136. <pre class="last literal-block">
  137. struct r
  138. : <a href="./inherit.html" class="identifier">inherit</a><tt class="literal"><span class="pre">2</span></tt>&lt;
  139. <a href="./inherit.html" class="identifier">inherit</a><em>n-1</em>&lt;t1,t2,<em>...</em>t<em>n-1</em>&gt;::type
  140. , t<em>n</em>
  141. &gt;
  142. {
  143. };
  144. </pre>
  145. </td>
  146. </tr>
  147. </tbody>
  148. </table>
  149. <!-- ........................................................................... -->
  150. <pre class="literal-block">
  151. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;t1,t2,<em>...</em>t<em>n</em>&gt;::type r;
  152. </pre>
  153. <table class="docutils field-list" frame="void" rules="none">
  154. <col class="field-name" />
  155. <col class="field-body" />
  156. <tbody valign="top">
  157. <tr class="field"><th class="field-name">Precondition:</th><td class="field-body"><p class="first"><em>t</em><sub>1</sub>,<em>t</em><sub>2</sub>,... <em>t</em><sub>n</sub> are complete types.</p>
  158. </td>
  159. </tr>
  160. <tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p>
  161. </td>
  162. </tr>
  163. <tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p>
  164. <pre class="last literal-block">
  165. typedef <a href="./inherit.html" class="identifier">inherit</a><em>n</em>&lt;t1,t2,<em>...</em>t<em>n</em>&gt;::type r;
  166. </pre>
  167. </td>
  168. </tr>
  169. </tbody>
  170. </table>
  171. </div>
  172. <div class="section" id="id1169">
  173. <h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3>
  174. <p>Amortized constant time.</p>
  175. </div>
  176. <div class="section" id="id1170">
  177. <h3><a class="subsection-title" href="#example" name="example">Example</a></h3>
  178. <pre class="literal-block">
  179. struct udt1 { int n; };
  180. struct udt2 {};
  181. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;udt1,udt2&gt;::type r1;
  182. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;<a href="./empty-base.html" class="identifier">empty_base</a>,udt1&gt;::type r2;
  183. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;<a href="./empty-base.html" class="identifier">empty_base</a>,udt1,<a href="./empty-base.html" class="identifier">empty_base</a>,<a href="./empty-base.html" class="identifier">empty_base</a>&gt;::type r3;
  184. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;udt1,<a href="./empty-base.html" class="identifier">empty_base</a>,udt2&gt;::type r4;
  185. typedef <a href="./inherit.html" class="identifier">inherit</a>&lt;<a href="./empty-base.html" class="identifier">empty_base</a>,<a href="./empty-base.html" class="identifier">empty_base</a>&gt;::type r5;
  186. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived&lt; udt1, r1&gt; ));
  187. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived&lt; udt2, r1&gt; ));
  188. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same&lt; r2, udt1&gt; ));
  189. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same&lt; r3, udt1 &gt; ));
  190. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived&lt; udt1, r4 &gt; ));
  191. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived&lt; udt2, r4 &gt; ));
  192. <a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same&lt; r5, <a href="./empty-base.html" class="identifier">empty_base</a> > ));
  193. </pre>
  194. </div>
  195. <div class="section" id="id1171">
  196. <h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3>
  197. <p><a class="reference internal" href="./metafunctions.html">Metafunctions</a>, <a class="reference internal" href="./empty-base.html">empty_base</a>, <a class="reference internal" href="./inherit-linearly.html">inherit_linearly</a>, <a class="reference internal" href="./identity.html">identity</a></p>
  198. <!-- Metafunctions/Miscellaneous//inherit_linearly |40 -->
  199. </div>
  200. </div>
  201. <div class="footer-separator"></div>
  202. <table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./always.html" class="navigation-link">Prev</a>&nbsp;<a href="./inherit-linearly.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./always.html" class="navigation-link">Back</a>&nbsp;<a href="./inherit-linearly.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Up</a>&nbsp;<a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td>
  203. <td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div>
  204. Distributed under the Boost Software License, Version 1.0. (See accompanying
  205. file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body>
  206. </html>