- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否可以通过以下方式专门化模板:
template<typename... Ts>
class Typelist { };
template<template<typename> typename... TTs>
class Typelist<TTs<typename>> { }; //I don't know if that is the right syntax, at least the compiler doesn't complain
我希望它作为模板类型列表和非模板类型列表工作:
template<typename T>
class AT {};
template<typename T>
class BT {};
template<typename T>
class CT {};
int main() {
using tl1 = Typelist<int, float, double>; //works fine
using tl2 = Typelist<AT, BT, CT>; //gives an error
}
如果我将第二个 Typelist
声明为一个单独的类型,它就可以工作...
template<template<typename> typename... TTs>
class Typelist2 { };
//...
using tl2 = Typelist2<AT, BT, CT>; //compiler doesn't complain and it works fine
我想知道是否有可能在这两种情况下都只使用 Typelist
,这样 Typelist2
就不必是一个单独的类型。
谁能帮帮我?
最佳答案
I was wondering though if it was possible to use only Typelist for both cases so that Typelist2 doesn't have to be a seperate type.
我不这么认为。
因为 TypeList
定义为 template<typename... Ts>
或 template<template<typename> typename... TTs>
;这两个定义不能一起工作。
我能想到的最好的帮助你的是定义一个 TypeList
简单类型的基础版本
template <typename ... Ts>
struct TypeList
{
// here you can use Ts...
};
和如下所示的容器特化(其中只有一个类型)
template <template <typename> class ... Tts, typename ... Ts>
struct TypeList<Tts<Ts>...>
{
// here you can use Ts... and Tts...
};
在哪里可以使用 Ts
和 Tts
.
但这不是一个很好的解决方案,因为您无法定义容器 TypeList
就像
TypeList<AT, BT, CT> tcl;
但您必须按如下方式添加包含的虚拟 (?) 类型
TypeList<AT<int>, BT<float>, CT<double>> tl2;
另一个问题是你不能混合它们,所以
TypeList<AT<int>, BT<float>, double> tl;
调用 TypeList
的基础版本(无容器) .
关于c++ - 模板模板可变参数特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44003571/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!