专业化和模板模板参数 [英] Specialization and template template parameters

查看:144
本文介绍了专业化和模板模板参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下:

 模板< template< typename,typename>类C,类T,类A> 
class TTCTest
{
public:
TTCTest(C C< ; T,A> _采集;
};

我想确保模板只在T和A类是特定类型(分别为路径和分配器)。



例如:

 。 .. 
list< path,allocator< path> > list1;
list< int,allocator< int> > list2;

TTCTest< list> testvar(list1); // ...应该工作
TTCTest< list> testvar(list2); // ... should not work
...

解决方案



<您可以使用部分专门化,在那里您无法为非特殊情况提供实施。

例如:

  template< template< typename,typename>类C,类T,类A> 
class TTCTest;

template< template< typename,typename>类C>
class TTCTest< C,path,allocator< path> >
{
// ...
};


I've the following:

template <template <typename, typename> class C, class T, class A >
class TTCTest
{
public:
        TTCTest(C<T, A> parameter) { /* ... some stuff... */ }
        C<T, A> _collection;
};

I want to ensure that the template is only instantiated where the T and A classes are of a specific type (path and allocator respectively).

For example:

...
list<path, allocator<path> > list1;
list<int, allocator<int> > list2;

TTCTest<list> testvar(list1); // ...should work
TTCTest<list> testvar(list2); // ...should not work
...

Is this possible and what is the syntax?

Regards, Col

解决方案

You can do that with partial specialisation, where you fail to provide an implementation for the non-specialised case.
For example:

template <template <typename, typename> class C, class T, class A >
class TTCTest;

template <template <typename, typename> class C>
class TTCTest<C, path, allocator<path> >
{
  // ...
};

这篇关于专业化和模板模板参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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