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> <a href="./inherit-linearly.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./always.html" class="navigation-link">Back</a> <a href="./inherit-linearly.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </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"> 19template< 20 typename T1, typename T2 21 > 22struct <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 27<em>...</em> 28 29template< 30 typename T1, typename T2,<em>...</em> typename T<em>n</em> 31 > 32struct <a href="./inherit.html" class="identifier">inherit</a><em>n</em> 33{ 34 typedef <em>unspecified</em> type; 35}; 36 37template< 38 typename T1 39 , typename T2 40 <em>...</em> 41 , typename T<em>n</em> = <em>unspecified</em> 42 > 43struct <a href="./inherit.html" class="identifier">inherit</a> 44{ 45 typedef <em>unspecified</em> type; 46}; 47</pre> 48</div> 49<div class="section" id="id1164"> 50<h3><a class="subsection-title" href="#description" name="description">Description</a></h3> 51<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>. 52Guarantees that derivation from <a class="reference internal" href="./empty-base.html">empty_base</a> is always a no-op, 53regardless of the position and number of <a class="reference internal" href="./empty-base.html">empty_base</a> classes in 54<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> 55</div> 56<div class="section" id="id1165"> 57<h3><a class="subsection-title" href="#header" name="header">Header</a></h3> 58<pre class="literal-block"> 59#include <<a href="../../../../boost/mpl/inherit.hpp" class="header">boost/mpl/inherit.hpp</a>> 60</pre> 61</div> 62<div class="section" id="id1166"> 63<h3><a class="subsection-title" href="#model-of" name="model-of">Model of</a></h3> 64<p><a class="reference internal" href="./metafunction.html">Metafunction</a></p> 65</div> 66<div class="section" id="id1167"> 67<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3> 68<table border="1" class="docutils table"> 69<colgroup> 70<col width="22%" /> 71<col width="28%" /> 72<col width="51%" /> 73</colgroup> 74<thead valign="bottom"> 75<tr><th class="head">Parameter</th> 76<th class="head">Requirement</th> 77<th class="head">Description</th> 78</tr> 79</thead> 80<tbody valign="top"> 81<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> 82<td>A class type</td> 83<td>Classes to derived from.</td> 84</tr> 85</tbody> 86</table> 87</div> 88<div class="section" id="id1168"> 89<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> 90<p>For artibrary class types <em>t</em><sub>1</sub>,<em>t</em><sub>2</sub>,... <em>t</em><sub>n</sub>:</p> 91<pre class="literal-block"> 92typedef inherit2<t1,t2>::type r; 93</pre> 94<table class="docutils field-list" frame="void" rules="none"> 95<col class="field-name" /> 96<col class="field-body" /> 97<tbody valign="top"> 98<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p> 99</td> 100</tr> 101<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> 102</td> 103</tr> 104<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> 105<pre class="literal-block"> 106typedef <a href="./empty-base.html" class="identifier">empty_base</a> r; 107</pre> 108<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> 109<pre class="literal-block"> 110typedef t2 r; 111</pre> 112<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> 113<pre class="literal-block"> 114typedef t1 r; 115</pre> 116<p>otherwise equivalent to</p> 117<pre class="last literal-block"> 118struct r : t1, t2 {}; 119</pre> 120</td> 121</tr> 122</tbody> 123</table> 124<!-- ........................................................................... --> 125<pre class="literal-block"> 126typedef <a href="./inherit.html" class="identifier">inherit</a><em>n</em><t1,t2,<em>...</em>t<em>n</em>>::type r; 127</pre> 128<table class="docutils field-list" frame="void" rules="none"> 129<col class="field-name" /> 130<col class="field-body" /> 131<tbody valign="top"> 132<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p> 133</td> 134</tr> 135<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> 136</td> 137</tr> 138<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p> 139<pre class="last literal-block"> 140struct r 141 : <a href="./inherit.html" class="identifier">inherit</a><tt class="literal"><span class="pre">2</span></tt>< 142 <a href="./inherit.html" class="identifier">inherit</a><em>n-1</em><t1,t2,<em>...</em>t<em>n-1</em>>::type 143 , t<em>n</em> 144 > 145{ 146}; 147</pre> 148</td> 149</tr> 150</tbody> 151</table> 152<!-- ........................................................................... --> 153<pre class="literal-block"> 154typedef <a href="./inherit.html" class="identifier">inherit</a><t1,t2,<em>...</em>t<em>n</em>>::type r; 155</pre> 156<table class="docutils field-list" frame="void" rules="none"> 157<col class="field-name" /> 158<col class="field-body" /> 159<tbody valign="top"> 160<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> 161</td> 162</tr> 163<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A class type.</p> 164</td> 165</tr> 166<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p> 167<pre class="last literal-block"> 168typedef <a href="./inherit.html" class="identifier">inherit</a><em>n</em><t1,t2,<em>...</em>t<em>n</em>>::type r; 169</pre> 170</td> 171</tr> 172</tbody> 173</table> 174</div> 175<div class="section" id="id1169"> 176<h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3> 177<p>Amortized constant time.</p> 178</div> 179<div class="section" id="id1170"> 180<h3><a class="subsection-title" href="#example" name="example">Example</a></h3> 181<pre class="literal-block"> 182struct udt1 { int n; }; 183struct udt2 {}; 184 185typedef <a href="./inherit.html" class="identifier">inherit</a><udt1,udt2>::type r1; 186typedef <a href="./inherit.html" class="identifier">inherit</a><<a href="./empty-base.html" class="identifier">empty_base</a>,udt1>::type r2; 187typedef <a href="./inherit.html" class="identifier">inherit</a><<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>>::type r3; 188typedef <a href="./inherit.html" class="identifier">inherit</a><udt1,<a href="./empty-base.html" class="identifier">empty_base</a>,udt2>::type r4; 189typedef <a href="./inherit.html" class="identifier">inherit</a><<a href="./empty-base.html" class="identifier">empty_base</a>,<a href="./empty-base.html" class="identifier">empty_base</a>>::type r5; 190 191<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived< udt1, r1> )); 192<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived< udt2, r1> )); 193<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same< r2, udt1> )); 194<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same< r3, udt1 > )); 195<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived< udt1, r4 > )); 196<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_base_and_derived< udt2, r4 > )); 197<a href="./assert.html" class="identifier">BOOST_MPL_ASSERT</a>(( is_same< r5, <a href="./empty-base.html" class="identifier">empty_base</a> > )); 198</pre> 199</div> 200<div class="section" id="id1171"> 201<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> 202<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> 203<!-- Metafunctions/Miscellaneous//inherit_linearly |40 --> 204</div> 205</div> 206 207<div class="footer-separator"></div> 208<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> <a href="./inherit-linearly.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./always.html" class="navigation-link">Back</a> <a href="./inherit-linearly.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./miscellaneous.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> 209<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> 210Distributed under the Boost Software License, Version 1.0. (See accompanying 211file 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> 212</html> 213