Variadic模板扣除在variadic模板模板中 [英] Variadic template deduction in variadic template template

查看:169
本文介绍了Variadic模板扣除在variadic模板模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  // A转换器struct具有通用构造函数。 
template< template< typename ...>类TT>
struct converter
{
template< typename ... Args>
converter(const TT< Args ...>&);
};

//几个类模板。
template< typename T>
struct foo {};

template< typename T,typename U>
struct foo2 {};

template< typename ... Args>
struct foo_variadic {};

模板< typename Arg0,typename ... Args>
struct foo_variadic2 {};

int main()
{
//所有这些编译。
converter< foo>(foo< int> {});
converter< foo2>(foo2< int,double> {});
converter< foo_variadic>(foo_variadic<> {});
converter< foo_variadic>(foo_variadic< int> {});
converter< foo_variadic>(foo_variadic< int,double> {});
//这将无法编译。
// converter< foo_variadic2>(foo_variadic2< int> {});
}

我试过使用GCC 4.8.1和clang 3.3,错误消息不同有点,但他们都指向一些问题推断 Args 在第5行(并随后排除转换器构造函数从候选列表)。



如何 foo_variadic2 相对于其他 foo s?



(对于记录,我试图实现 is_instance_of trait以检测模板类的实例)



UPDATE



.3和4.9.1在我的设置接受这个。 clang 3.4.2还在吠叫。

解决方案

这不是解决方案,但可能会帮助你或其他人找出问题是。以下编译:

 模板< template< typename ...>类TT> 
struct converter2
{
template< typename Arg0,typename ... Args>
converter2(const TT };

// ...

converter2< foo_variadic2>(foo_variadic2< int> {});

我不得不承认我不明白为什么这是必要的,为什么你的代码不工作。


I am not sure if the title makes much sense, but the example is actually quite staightforward:

// A converter struct with a generic constructor.
template <template <typename ...> class TT>
struct converter
{
        template <typename ... Args>    
        converter(const TT<Args ...> &);
};

// A few class templates.
template <typename T>
struct foo {};

template <typename T, typename U>
struct foo2 {};

template <typename ... Args>
struct foo_variadic {};

template <typename Arg0, typename ... Args>
struct foo_variadic2 {};

int main()
{
        // All these compile.
        converter<foo>(foo<int>{});
        converter<foo2>(foo2<int,double>{});
        converter<foo_variadic>(foo_variadic<>{});   
        converter<foo_variadic>(foo_variadic<int>{});
        converter<foo_variadic>(foo_variadic<int,double>{});
        // This will not compile.
        // converter<foo_variadic2>(foo_variadic2<int>{});                     
}

I have tried with GCC 4.8.1 and clang 3.3, the error messages vary a bit but they all point to some problem deducing Args around line 5 (and subsequent exclusion of the converter constructor from the candidate list).

How is foo_variadic2 special or different with respect to the other foos?

(For the record, I am trying to implement an is_instance_of type trait to detect instances of template classes)

UPDATE

Now both GCC 4.8.3 and 4.9.1 on my setup accept this. clang 3.4.2 still barking.

解决方案

This is not the solution, but might help you or others to figure out what the problem is. The following compiles:

template <template <typename ...> class TT>
struct converter2
{
    template <typename Arg0, typename ... Args>    
    converter2(const TT<Arg0, Args ...> &);
};

// ...

converter2<foo_variadic2>(foo_variadic2<int>{});

I have to admit I don't understand why this is necessary and why your code doesn't work.

这篇关于Variadic模板扣除在variadic模板模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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