我正在使用boost :: mpl对概念样本做一些证明,并且在理解lambda函数如何使用占位符方面遇到一些困难.
我意识到我可以在元函数类中包装元函数,以使更高阶的函数能够访问嵌套的apply函数,并且意识到可以通过使用允许占位符的元函数mpl :: lambda来避免这种努力.@H_404_3@
这怎么实际工作?我的头脑围绕着喇叭和占位符在封面下实际做了很麻烦.@H_404_3@
解决方法
请参阅
Boost.MPL manual:占位符是mpl :: arg< X>形式的元功能类.元功能类是包含应用元功能的类.
template <int N> struct arg; // forward declarations struct void_; template <> struct arg<1> { template < class A1,class A2 = void_,... class Am = void_> struct apply { typedef A1 type; // return the first argument }; }; typedef arg<1> _1
mpl :: lambda的工作是将占位符表达式转换为元函数类.这是通过嵌入像this这样的元功能类完成的:@H_404_3@
template< typename X,typename Tag = unspecified > struct lambda { typedef unspecified type; };
如果x是通用形式X< a1,... an>中的占位符表达式,其中X是类模板,a1,… an是任意类型,嵌入的未指定类型f等价于@H_404_3@
typedef protect< bind< quoten<X>,lambda<a1>::type,... lambda<an>::type > > f;