1 .. Metafunctions/Composition and Argument Binding//bind |30
21 typename F, typename A1
32 typename F, typename A1,\ |...| typename An
42 , typename A1 = |unspecified|
44 , typename An = |unspecified|
56 ``bind`` is a higher-order primitive for |Metafunction Class| composition
57 and argument binding. In essence, it's a compile-time counterpart of
58 the similar run-time functionality provided by |Boost.Bind| and |Boost.Lambda|
67 #include <boost/mpl/bind.hpp>
79 +---------------+-----------------------------------+-----------------------------------------------+
80 | Parameter | Requirement | Description |
81 +===============+===================================+===============================================+
82 | ``F`` | |Metafunction Class| | An metafunction class to perform binding on. |
83 +---------------+-----------------------------------+-----------------------------------------------+
84 | |A1...An| | Any type | Arguments to bind. |
85 +---------------+-----------------------------------+-----------------------------------------------+
91 For any |Metafunction Class| ``f`` and arbitrary types |a1...an|:
95 typedef bind<f,a1,...a\ *n*\ > g;
96 typedef bind\ *n*\ <f,a1,...a\ *n*\ > g;
101 .. _`bind semantics`:
111 typename U1 = |unspecified|
113 , typename U\ *n* = |unspecified|
117 typename h0<f,U1,\ |...|\ U\ *n*>::type
118 , typename h1<a1,U1,\ |...|\ U\ *n*>::type
120 , typename h\ *n*\ <a\ *n*\ ,U1,\ |...|\ U\ *n*>::type
126 where ``h``\ *k* is equivalent to
130 template< typename X, typename U1,\ |...| typename U\ *n* > struct h\ *k*
131 : apply_wrap\ *n*\ <X,U1,\ |...|\ U\ *n*>
135 if ``f`` or ``a``\ *k* is a |bind expression| or a |placeholder|, and
139 template< typename X, typename U1,\ |...| typename U\ *n* > struct h\ *k*
144 otherwise. |Note:| Every ``n``\th appearance of the `unnamed placeholder`__
145 in the ``bind<f,a1,...an>`` specialization is replaced with the corresponding
146 numbered placeholder ``_``\ *n* |-- end note|
158 template< typename T1 > struct apply
166 template< typename T1, typename T2, typename T3, typename T4, typename T5 >
173 typedef apply_wrap\ ``1``\<
178 typedef apply_wrap\ ``5``\<
180 , void,void,void,void,int
183 BOOST_MPL_ASSERT(( is_same<r11,int> ));
184 BOOST_MPL_ASSERT(( is_same<r12,int> ));
186 typedef apply_wrap\ ``5``\<
187 bind\ ``5``\<f5,_1,_2,_3,_4,_5>
188 , void,void,void,void,int
191 typedef apply_wrap\ ``5``\<
192 bind\ ``5``\<f5,_5,_4,_3,_2,_1>
193 , int,void,void,void,void
196 BOOST_MPL_ASSERT(( is_same<r51,int> ));
197 BOOST_MPL_ASSERT(( is_same<r52,int> ));
203 |Composition and Argument Binding|, |Invocation|, |Placeholders|, |lambda|, |quote|,
204 |protect|, |apply|, |apply_wrap|
207 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
208 Distributed under the Boost Software License, Version 1.0. (See accompanying
209 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)