]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Metafunctions/Composition and Argument Binding//_1,_2,..._n |10 |
2 | ||
3 | Placeholders | |
4 | ============ | |
5 | .. _`placeholder`: | |
6 | ||
7 | ||
8 | Synopsis | |
9 | -------- | |
10 | ||
11 | .. parsed-literal:: | |
12 | ||
13 | namespace placeholders { | |
14 | typedef |unspecified| _; | |
15 | typedef arg<1> _1; | |
16 | typedef arg<2> _2; | |
17 | |...| | |
18 | typedef arg<\ *n*\ > _\ *n*\ ; | |
19 | } | |
20 | ||
21 | using placeholders::_; | |
22 | using placeholders::_1; | |
23 | using placeholders::_2; | |
24 | |...| | |
25 | using placeholders::_\ *n*\ ; | |
26 | ||
27 | ||
28 | Description | |
29 | ----------- | |
30 | ||
31 | A placeholder in a form ``_``\ *n* is simply a synonym for the corresponding | |
32 | ``arg<n>`` specialization. The unnamed placeholder ``_`` (underscore) carries | |
33 | `special meaning`__ in bind and lambda expressions, and does not have | |
34 | defined semantics outside of these contexts. | |
35 | ||
36 | Placeholder names can be made available in the user namespace through | |
37 | ``using namespace mpl::placeholders;`` directive. | |
38 | ||
39 | __ `bind semantics`_ | |
40 | ||
41 | Header | |
42 | ------ | |
43 | ||
44 | .. parsed-literal:: | |
45 | ||
46 | #include <boost/mpl/placeholders.hpp> | |
47 | ||
48 | |Note:| The include might be omitted when using placeholders to construct a |Lambda | |
49 | Expression| for passing it to MPL's own algorithm or metafunction: any library | |
50 | component that is documented to accept a lambda expression makes the placeholders | |
51 | implicitly available for the user code |-- end note| | |
52 | ||
53 | ||
54 | Parameters | |
55 | ---------- | |
56 | ||
57 | None. | |
58 | ||
59 | ||
60 | Expression semantics | |
61 | -------------------- | |
62 | ||
63 | For any integral constant ``n`` in the range [1, |BOOST_MPL_LIMIT_METAFUNCTION_ARITY|\] and | |
64 | arbitrary types |a1...an|: | |
65 | ||
66 | ||
67 | .. parsed-literal:: | |
68 | ||
69 | typedef apply_wrap\ *n*\<_\ *n*\,a1,\ |...|\a\ *n*\ >::type x; | |
70 | ||
71 | :Return type: | |
72 | A type. | |
73 | ||
74 | :Semantics: | |
75 | Equivalent to | |
76 | ||
77 | .. parsed-literal:: | |
78 | ||
79 | typedef apply_wrap\ *n*\< arg<\ *n*\ >,a1,\ |...|\a\ *n* >::type x; | |
80 | ||
81 | ||
82 | Example | |
83 | ------- | |
84 | ||
85 | .. parsed-literal:: | |
86 | ||
87 | typedef apply_wrap\ ``5``\< _1,bool,char,short,int,long >::type t1; | |
88 | typedef apply_wrap\ ``5``\< _3,bool,char,short,int,long >::type t3; | |
89 | ||
90 | BOOST_MPL_ASSERT(( is_same< t1, bool > )); | |
91 | BOOST_MPL_ASSERT(( is_same< t3, short > )); | |
92 | ||
93 | ||
94 | See also | |
95 | -------- | |
96 | ||
97 | |Composition and Argument Binding|, |arg|, |lambda|, |bind|, |apply|, |apply_wrap| | |
98 | ||
99 | ||
100 | .. |placeholder| replace:: `placeholder`_ | |
101 | ||
102 | .. |_1| replace:: `_1`_ | |
103 | .. |_2| replace:: `_2`_ | |
104 | .. |_3| replace:: `_3`_ | |
105 | .. |_4| replace:: `_4`_ | |
106 | .. |_5| replace:: `_5`_ | |
107 | ||
108 | .. _`_1`: `Placeholders`_ | |
109 | .. _`_2`: `Placeholders`_ | |
110 | .. _`_3`: `Placeholders`_ | |
111 | .. _`_4`: `Placeholders`_ | |
112 | .. _`_5`: `Placeholders`_ | |
113 | ||
114 | .. |_1,_2,..._n| replace:: |_1|, |_2|, |_3|,\ |...| | |
115 | ||
116 | ||
117 |