...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Front Page / Metafunctions / Composition and Argument Binding / bind |
template< typename F > struct bind0 { // unspecified // ... }; template< typename F, typename A1 > struct bind1 { // unspecified // ... }; ... template< typename F, typename A1,... typename An > struct bindn { // unspecified // ... }; template< typename F , typename A1 = unspecified ... , typename An = unspecified > struct bind { // unspecified // ... };
bind is a higher-order primitive for Metafunction Class composition and argument binding. In essence, it's a compile-time counterpart of the similar run-time functionality provided by Boost.Bind and Boost.Lambda libraries.
#include <boost/mpl/bind.hpp>
Parameter | Requirement | Description |
---|---|---|
F | Metafunction Class | An metafunction class to perform binding on. |
A1,... An | Any type | Arguments to bind. |
For any Metafunction Class f and arbitrary types a1,... an:
typedef bindn> g; typedef bindn n> g;
Return type: | Metafunction Class |
---|
Semantics: | Equivalent to struct g { template< typename U1 = unspecified ... , typename Un = unspecified > struct apply : apply_wrapn< typename h0 where hk is equivalent to template< typename X, typename U1,... typename Un > struct hk : apply_wrapn if f or ak is a bind expression or a placeholder, and template< typename X, typename U1,... typename Un > struct hk { typedef X type; }; otherwise. [Note: Every nth appearance of the unnamed placeholder
in the bind |
---|
struct f1 { template< typename T1 > struct apply { typedef T1 type; }; }; struct f5 { template< typename T1, typename T2, typename T3, typename T4, typename T5 > struct apply { typedef T5 type; }; }; typedef apply_wrap1< bind1_1> , int >::type r11; typedef apply_wrap5< bind1 _5> , void,void,void,void,int >::type r12; BOOST_MPL_ASSERT(( is_same )); BOOST_MPL_ASSERT(( is_same )); typedef apply_wrap5< bind5 _1,_2,_3,_4,_5> , void,void,void,void,int >::type r51; typedef apply_wrap5< bind5 _5,_4,_3,_2,_1> , int,void,void,void,void >::type r52; BOOST_MPL_ASSERT(( is_same )); BOOST_MPL_ASSERT(( is_same ));