假如还觉得不够的话,能够参考variadic-templates的主页,上面的variadic templates proposal中带了三个tr1实现,分别是tuple,bind,function,当然,variadic-templates的好处远远不但仅止于这三个实现,从本质上他提供了一种真正直接的表达意图的工具,完全避开了像下面这种horrible的workaround:
| template<class T1> cons(T1& t1, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&, const null_type&) : head (t1) {} |
tuple的C 98实现,代码近千行。利用variadic-templates实现,代码仅百行。
和这种更horrible的workaround:
| template<class R, class F, class A1, class A2, class A3, class A4, class A5, class A6> _bi::bind_t<R, F, typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type> BOOST_BIND(boost::type<R>, F f, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { typedef typename _bi::list_av_6<A1, A2, A3, A4, A5, A6>::type list_type; return _bi::bind_t<R, F, list_type>(f, list_type(a1, a2, a3, a4, a5, a6)); } |
小小的boost.bind,实现代码逾两千行,其间重复代码无数。用了variadic-templates,实现但是百行。
BTW. variadic templates在C 大会上一次性几乎全数投票通过。lambda能不能进标准则要看几个提案者的工作。现在还没有wording出来。但是只要出了wording想必也会像variadic templates那样压倒性通过的。
[1] [2] [3] [4] [5]




