开发者

Composing meta-functions

开发者 https://www.devze.com 2023-02-15 06:43 出处:网络
Is there an established idiom for composing (\"chaining\") meta-functions? This is my current solution:

Is there an established idiom for composing ("chaining") meta-functions? This is my current solution:

template
<
    template <typename> class First,
    temp开发者_JAVA百科late <typename> class Then,
    typename T
>
struct compose : Then<typename First<T>::type> {};

And here is an example usage:

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

Is there a better way to do it?


You might check out the boost::mpl library:

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

I'm not claiming that mpl is better than what you have. Just that it looks like similar territory and it might interest you.

0

精彩评论

暂无评论...
验证码 换一张
取 消