c++11模拟boost元占位符(四)

2015-01-27 14:02:54 · 作者: · 浏览: 58
, P##2, P##1, P##4) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##3, P##2, P##4, P##1) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##3, P##4, P##1, P##2) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##3, P##4, P##2, P##1) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##1, P##2, P##3) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##1, P##3, P##2) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##2, P##1, P##3) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##2, P##3, P##1) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##3, P##1, P##2) ? ? ? ? ? ?\
? ? SUPPORT_LAMBDA_4_IMPL(classname, P##4, P##3, P##2, P##1)
?
?
?
?
#endif
复制代码
在每个你希望支持占位符的类定义后边,加上SUPPORT_LAMBDA这句宏,填入参数总数,占位符前缀(可包含命名空间,默认占位符必须以本身数字结束)。如下例子
?
复制代码
? ? template struct push_back;
?
? ? template
? ? struct push_back< typelist, T>?
? ? {
? ? ? ? typedef typelist type;
? ? };
?
? ? template<>
? ? struct push_back< nulllist >
? ? {
? ? ? ? typedef nulllist type;
? ? };
? ??
? ? SUPPORT_LAMBDA(push_back, 2, placeholders::_);?
复制代码
以上这一套实现占位符的办法,比boost的要简洁了很多。当然还缺少匿名占位符这样的手法,这里提供一个简易的思路,望你有所得。