簡體   English   中英

組合元函數

[英]Composing meta-functions

是否有用於組合(“鏈接”)元功能的既定習語? 這是我目前的解決方案:

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> {};

有沒有更好的方法來做到這一點?

您可以查看 boost::mpl 庫:

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

我並不是說 mpl 比你擁有的更好。 只是它看起來像類似的領域,它可能會讓你感興趣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM