【问题标题】:Composing meta-functions组合元函数
【发布时间】:2011-07-08 18:12:24
【问题描述】:

是否存在组合(“链接”)元函数的既定习惯用法?这是我目前的解决方案:

template
<
    template <typename> class First,
    template <typename> class Then,
    typename T
>
struct compose : Then<typename First<T>::type> {};

这是一个示例用法:

template <typename T>
struct remove_cv : compose<remove_const, remove_volatile, T> {};

有没有更好的方法?

【问题讨论】:

    标签: c++ templates function metaprogramming composition


    【解决方案1】:

    您可以查看 boost::mpl 库:

    http://www.boost.org/doc/libs/1_46_0/libs/mpl/doc/refmanual/composition-and-argument-binding.html

    我并不是说 mpl 比你所拥有的更好。只是它看起来很相似,你可能会感兴趣。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      相关资源
      最近更新 更多