1.. Metafunctions/Miscellaneous//inherit |30 2 3inherit 4======= 5 6Synopsis 7-------- 8 9.. parsed-literal:: 10 11 template< 12 typename T1, typename T2 13 > 14 struct inherit\ ``2`` 15 { 16 typedef |unspecified| type; 17 }; 18 19 |...| 20 21 template< 22 typename T1, typename T2,\ |...| typename T\ *n* 23 > 24 struct inherit\ *n* 25 { 26 typedef |unspecified| type; 27 }; 28 29 template< 30 typename T1 31 , typename T2 32 |...| 33 , typename T\ *n* = |unspecified| 34 > 35 struct inherit 36 { 37 typedef |unspecified| type; 38 }; 39 40 41Description 42----------- 43 44Returns an unspecified class type publically derived from |T1...Tn|. 45Guarantees that derivation from |empty_base| is always a no-op, 46regardless of the position and number of |empty_base| classes in 47|T1...Tn|. 48 49 50Header 51------ 52 53.. parsed-literal:: 54 55 #include <boost/mpl/inherit.hpp> 56 57 58Model of 59-------- 60 61|Metafunction| 62 63 64Parameters 65---------- 66 67+---------------+-------------------+-----------------------------------+ 68| Parameter | Requirement | Description | 69+===============+===================+===================================+ 70| |T1...Tn| | A class type | Classes to derived from. | 71+---------------+-------------------+-----------------------------------+ 72 73 74Expression semantics 75-------------------- 76 77For artibrary class types |t1...tn|: 78 79.. parsed-literal:: 80 81 typedef inherit2<t1,t2>::type r; 82 83:Return type: 84 A class type. 85 86:Precondition: 87 ``t1`` and ``t2`` are complete types. 88 89:Semantics: 90 If both ``t1`` and ``t2`` are identical to ``empty_base``, equivalent to 91 92 .. parsed-literal:: 93 94 typedef empty_base r; 95 96 97 otherwise, if ``t1`` is identical to ``empty_base``, equivalent to 98 99 .. parsed-literal:: 100 101 typedef t2 r; 102 103 104 otherwise, if ``t2`` is identical to ``empty_base``, equivalent to 105 106 .. parsed-literal:: 107 108 typedef t1 r; 109 110 111 otherwise equivalent to 112 113 .. parsed-literal:: 114 115 struct r : t1, t2 {}; 116 117.. ........................................................................... 118 119.. parsed-literal:: 120 121 typedef inherit\ *n*\<t1,t2,\ |...|\ t\ *n*\ >::type r; 122 123:Return type: 124 A class type. 125 126:Precondition: 127 |t1...tn| are complete types. 128 129:Semantics: 130 Equivalent to 131 132 .. parsed-literal:: 133 134 struct r 135 : inherit\ ``2``\< 136 inherit\ *n-1*\<t1,t2,\ |...|\ t\ *n-1*\>::type 137 , t\ *n* 138 > 139 { 140 }; 141 142 143.. ........................................................................... 144 145 146.. parsed-literal:: 147 148 typedef inherit<t1,t2,\ |...|\ t\ *n*\ >::type r; 149 150:Precondition: 151 |t1...tn| are complete types. 152 153:Return type: 154 A class type. 155 156:Semantics: 157 Equivalent to 158 159 .. parsed-literal:: 160 161 typedef inherit\ *n*\<t1,t2,\ |...|\ t\ *n*\ >::type r; 162 163 164 165Complexity 166---------- 167 168Amortized constant time. 169 170 171Example 172------- 173 174.. parsed-literal:: 175 176 struct udt1 { int n; }; 177 struct udt2 {}; 178 179 typedef inherit<udt1,udt2>::type r1; 180 typedef inherit<empty_base,udt1>::type r2; 181 typedef inherit<empty_base,udt1,empty_base,empty_base>::type r3; 182 typedef inherit<udt1,empty_base,udt2>::type r4; 183 typedef inherit<empty_base,empty_base>::type r5; 184 185 BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r1> )); 186 BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r1> )); 187 BOOST_MPL_ASSERT(( is_same< r2, udt1> )); 188 BOOST_MPL_ASSERT(( is_same< r3, udt1 > )); 189 BOOST_MPL_ASSERT(( is_base_and_derived< udt1, r4 > )); 190 BOOST_MPL_ASSERT(( is_base_and_derived< udt2, r4 > )); 191 BOOST_MPL_ASSERT(( is_same< r5, empty_base > )); 192 193 194See also 195-------- 196 197|Metafunctions|, |empty_base|, |inherit_linearly|, |identity| 198 199 200.. copyright:: Copyright � 2001-2009 Aleksey Gurtovoy and David Abrahams 201 Distributed under the Boost Software License, Version 1.0. (See accompanying 202 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 203