【发布时间】:2016-06-19 05:17:47
【问题描述】:
让我们将看起来像T<Us...> 的类型称为更高种类的类型。对于某个高级类型SomeType(假设它是std::vector<int>),我想使用类型特征从中提取T 部分(std::vector)。我可以这样做:
template<typename>
struct HKT;
template<template <typename...> class T, typename... Us>
struct HKT<T<Us...>> {
template<typename... Vs>
using type = T<Vs...>;
};
所以现在我可以使用HKT<SomeType>::type<Foo> 来定义std::vector<Foo>。
但我试图摆脱::type 部分,就像typename std::enable_if<T>::type 可以缩写为std::enable_if_t<T>。不过不确定是否可能,因为在我的情况下,HKT_t<SomeType>(假设它存在)将是别名模板而不是类型。用法类似于HKT_t<SomeType><Foo>...我猜这确实是一个“别名模板模板”。
我想这样做的原因是将它用作模板模板参数的参数。例如,
template<template <typename...> class T>
void foo() {...}
foo<HKT_t<std::vector<int>>>();
这可能吗?
【问题讨论】:
-
很遗憾
X<Y>不能指定模板,所以HKT_t<std::vector<int>>不能是std::vector的别名。