作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有以下内容:
template <template <typename, typename> class C, class T, class A >
class TTCTest
{
public:
TTCTest(C<T, A> parameter) { /* ... some stuff... */ }
C<T, A> _collection;
};
我想确保模板仅在 T 类和 A 类属于特定类型(分别为路径和分配器)的情况下实例化。
例如:
...
list<path, allocator<path> > list1;
list<int, allocator<int> > list2;
TTCTest<list> testvar(list1); // ...should work
TTCTest<list> testvar(list2); // ...should not work
...
这可能吗,语法是什么?
问候,上校
最佳答案
您可以通过部分特化来做到这一点,在这种情况下您无法为非特化案例提供实现。
例如:
template <template <typename, typename> class C, class T, class A >
class TTCTest;
template <template <typename, typename> class C>
class TTCTest<C, path, allocator<path> >
{
// ...
};
关于c++ - 特化和模板模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4647941/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!