]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Metafunctions/Type Selection//eval_if |30 |
2 | ||
3 | eval_if | |
4 | ======= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename C | |
13 | , typename F1 | |
14 | , typename F2 | |
15 | > | |
16 | struct eval_if | |
17 | { | |
18 | typedef |unspecified| type; | |
19 | }; | |
20 | ||
21 | ||
22 | ||
23 | Description | |
24 | ----------- | |
25 | ||
26 | Evaluates one of its two |nullary metafunction| arguments, ``F1`` or ``F2``, depending | |
27 | on the value ``C``. | |
28 | ||
29 | ||
30 | Header | |
31 | ------ | |
32 | ||
33 | .. parsed-literal:: | |
34 | ||
35 | #include <boost/mpl/eval_if.hpp> | |
36 | ||
37 | ||
38 | Parameters | |
39 | ---------- | |
40 | ||
41 | +---------------+-----------------------------------+-----------------------------------------------+ | |
42 | | Parameter | Requirement | Description | | |
43 | +===============+===================================+===============================================+ | |
44 | | ``C`` | |Integral Constant| | An evaluation condition. | | |
45 | +---------------+-----------------------------------+-----------------------------------------------+ | |
46 | | ``F1``, ``F2``| Nullary |Metafunction| | Metafunctions to select for evaluation from. | | |
47 | +---------------+-----------------------------------+-----------------------------------------------+ | |
48 | ||
49 | ||
50 | Expression semantics | |
51 | -------------------- | |
52 | ||
53 | For any |Integral Constant| ``c`` and nullary |Metafunction|\ s ``f1``, ``f2``: | |
54 | ||
55 | ||
56 | .. parsed-literal:: | |
57 | ||
58 | typedef eval_if<c,f1,f2>::type t; | |
59 | ||
60 | :Return type: | |
61 | Any type. | |
62 | ||
63 | :Semantics: | |
64 | If ``c::value == true``, ``t`` is identical to ``f1::type``; otherwise ``t`` is | |
65 | identical to ``f2::type``. | |
66 | ||
67 | ||
68 | Example | |
69 | ------- | |
70 | ||
71 | .. parsed-literal:: | |
72 | ||
73 | typedef eval_if< true\_, identity<char>, identity<long> >::type t1; | |
74 | typedef eval_if< false\_, identity<char>, identity<long> >::type t2; | |
75 | ||
76 | BOOST_MPL_ASSERT(( is_same<t1,char> )); | |
77 | BOOST_MPL_ASSERT(( is_same<t2,long> )); | |
78 | ||
79 | ||
80 | See also | |
81 | -------- | |
82 | ||
83 | |Metafunctions|, |Integral Constant|, |eval_if_c|, |if_| | |
84 | ||
85 | ||
86 |