删除嵌套类型中的所有包装器类型 [英] Delete all wrapper types in a nested type

查看:63
本文介绍了删除嵌套类型中的所有包装器类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能编写一个元函数,给定一个类型,该类型具有多次出现的某些特定类型template<class> class Decor,并且返回该类型而没有出现类Decorator.

Is it possible to write a metafunction that, given a type with several occurrences of certain type template<class> class Decor, returns the type without the appearances of the class Decorator.

一个例子是转换以下类型 A<Decor<T<B<A<Decor<C>>>>>> 进入 A<T<B<A<C>>>>

An example would be to convert following type A<Decor<T<B<A<Decor<C>>>>>> into A<T<B<A<C>>>>

我们假定最终类型的结构确实是正确的类型,但是我们不对输入类型的结构做任何假设.某些情况下,用于构造输入类型的某些类型可能是template<class...> class或任何其他类型类的形式.

We assume that the structure of the final type is indeed a correct type, but we do not assume anything on the structure of the input type. It could be the case that some types used to construct the input type were of the form template<class...> class or any other type class.

推荐答案

 template <class T>
 struct RemDec
 { using type = T; };
 template <class T>
 struct RemDec<Decor<T>>
 { using type = T; };
 template <class T>
 struct RemDec<T&>
 { using type = typename RemDec<T>::type&; };
 template <class T>
 struct RemDec<T&&>
 { using type = typename RemDec<T>::type&&; };
 template <class T>
 struct RemDec<const T>
 { using type = typename RemDec<T>::type const; };
 template <class T>
 struct RemDec<volatile T>
 { using type = typename RemDec<T>::type volatile; };
 template <template <typename...> class TT, class... Ts>
 struct RemDec<TT<Ts...>>
 { using type = TT<typename RemDec<Ts>::type...>; }

如果您的模板可能包含value-或template-template-arguments,那么您将需要更多的专业化知识.

You will need even more specializations if your templates might have value- or template-template-arguments.

这篇关于删除嵌套类型中的所有包装器类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆