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