2017-03-17 20 views
3

私は、次のクラステンプレートを持っている:部分テンプレート特殊化SFINAE

template<bool head, bool... tail> 
struct var_and { 
    static constexpr bool value = head && var_and<tail...>::value; 
}; 

template<bool b> struct var_and<b> { 
    static constexpr bool value = b; 
}; 

template<typename... Ts> 
struct type_list {}; 

template <typename T, typename Enable = void> 
class foo; 

template <typename... T> 
class foo<type_list<T...>, std::enable_if_t<var_and<std::is_integral_v<T>...>::value>> {}; 

私は専門一致させよう:で

Error C2079 'test' uses undefined class 'ECS::foo<ECS::type_list<int,int,int>,void>' 

:私はエラーを取得する

foo<type_list<int, int, int>> test{}; 

を私はこれらのエラーを得ると同時に:

more than one partial specialization matches the template argument list of class "ECS::foo<ECS::type_list<int, int, int>, void>" 
"ECS::foo<ECS::type_list<T...>, std::enable_if_t<ECS::var_and<std::is_integral_v<T>...>::value, void>>"   
"ECS::foo<ECS::type_list<T...>, std::enable_if_t<ECS::var_and<std::is_integral_v<T>...>::value, void>>" 
... (The exact same error message 6 more times) 

SFINAEを使用して、variadic型パックの型の型特性を具体的に実行するにはどうすればよいですか?

私は何の問題は、単一の型引数のために働くことを得るがありませんでした: http://www.cppsamples.com/common-tasks/class-template-sfinae.html

それがなくても可能であるならば、私は、私は単にstatic_assertを使用することができます知っているが、私は思っていました。次のように

+1

あなたがMSVCを使用しているようで、コンパイラの出力から。このコードはgccとclangで完璧に動作します(http://coliru.stacked-crooked.com/a/36b9eecd91763aafを参照)...だから、msvcバグ?どちらか、それともコンパイルされているすべてのコードを与えていないか:) – Rerito

+0

msvcでコンパイルされたこの正確なコードは、同じエラー(http://rextester.com/NIU85113)を返します。だから私はそれがバグだと仮定していますか? –

+0

実際に、私はリンクがわずかに異なるエラーを表示するようになったことに気付きました。 http://webcompiler.cloudapp.net/で同じコードが実行されても同じエラーが発生し、より新しいコンパイラを使用します。 –

答えて

1

解決策になります:

#include <type_traits> 

template <bool...> 
struct bool_pack { }; 

template <bool... Bs> 
using var_and = std::is_same<bool_pack<true, Bs...>, bool_pack<Bs..., true>>; 

template<typename... Ts> 
struct type_list {}; 

template <typename T, typename Enable = void> 
class foo; 

template <typename... T> 
class foo<type_list<T...>, std::enable_if_t<var_and<std::is_integral<T>::value...>::value>> {}; 

int main() 
{ 
    foo<type_list<int, int, int>> {}; 
} 

[live demo]

+0

私のvar_andをあなたのものに置き換えるのは確かにコンパイルされます。興味深い..これはMSVCの既知の問題ですか? –

+0

わからない... 'std :: is_integral_v 'の使用にも問題があるようでした。私は 'std :: is_integral :: value' –

関連する問題