很简单,但也许不可能:给定一些T<some_type>,有没有办法得到T?这里有一个更好的代码示例:
template<class T>
struct parametrized_class{
};
template<class T>
using make_floaty = T<float>; // this doesn't compile since T is not the "base" type
int main() {
using int_class = parametrized_class<int>;
using float_class = make_floaty<int_class>;
}
Run Code Online (Sandbox Code Playgroud)
我不认为是这样,但我想确定一下。
你绝对可以,尽管模板不是一等公民让它有点棘手:
template <class T>
struct make_floaty;
template <template <class> class Template, class T>
struct make_floaty<Template<T>> {
using type = Template<float>;
};
template <class T>
using make_floaty_t = typename make_floaty<T>::type;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |