1.. Metafunctions/Type Selection//if_ |10 2 3if\_ 4==== 5 6Synopsis 7-------- 8 9.. parsed-literal:: 10 11 template< 12 typename C 13 , typename T1 14 , typename T2 15 > 16 struct if\_ 17 { 18 typedef |unspecified| type; 19 }; 20 21 22 23Description 24----------- 25 26Returns one of its two arguments, ``T1`` or ``T2``, depending on the value ``C``. 27 28 29Header 30------ 31 32.. parsed-literal:: 33 34 #include <boost/mpl/if.hpp> 35 36 37Parameters 38---------- 39 40+---------------+-----------------------------------+-----------------------------------------------+ 41| Parameter | Requirement | Description | 42+===============+===================================+===============================================+ 43| ``C`` | |Integral Constant| | A selection condition. | 44+---------------+-----------------------------------+-----------------------------------------------+ 45| ``T1``, ``T2``| Any type | Types to select from. | 46+---------------+-----------------------------------+-----------------------------------------------+ 47 48 49Expression semantics 50-------------------- 51 52For any |Integral Constant| ``c`` and arbitrary types ``t1``, ``t2``: 53 54 55.. parsed-literal:: 56 57 typedef if_<c,t1,t2>::type t; 58 59:Return type: 60 Any type. 61 62:Semantics: 63 If ``c::value == true``, ``t`` is identical to ``t1``; otherwise ``t`` is 64 identical to ``t2``. 65 66 67Example 68------- 69 70.. parsed-literal:: 71 72 typedef if\_<true\_,char,long>::type t1; 73 typedef if\_<false\_,char,long>::type t2; 74 75 BOOST_MPL_ASSERT(( is_same<t1, char> )); 76 BOOST_MPL_ASSERT(( is_same<t2, long> )); 77 78 79.. parsed-literal:: 80 81 // allocates space for an object of class T on heap or "inplace" 82 // depending on its size 83 template< typename T > struct lightweight 84 { 85 // ... 86 typedef typename if\_< 87 less_equal< sizeof\_<T>, sizeof\_<T*> > 88 , inplace_storage<T> 89 , heap_storage<T> 90 >::type impl_t; 91 92 impl_t impl; 93 }; 94 95 96See also 97-------- 98 99|Metafunctions|, |Integral Constant|, |if_c|, |eval_if| 100 101 102.. copyright:: Copyright � 2001-2009 Aleksey Gurtovoy and David Abrahams 103 Distributed under the Boost Software License, Version 1.0. (See accompanying 104 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 105