First off, I apologize if this is a duplicate, I will be happy to take it down but I am not even sure what the issue/diagnosis is here.
Anyway, my code here works with gcc and not clang - why is this the case? I am clearly not able to understand why clang cant compile this.
#include <iostream>
#include <type_traits>
using std::cout;
using std::endl;
template <typename T, typename... Args, typename std::enable_if<!sizeof...(Args)>::type* = nullptr>
void func(int start_size, int idx)
{
cout << start_size << " " << idx << endl;
return;
}
template <typename T, typename... Args, typename std::enable_if<sizeof...(Args)>::type* = nullptr>
void func(int start_size, int idx)
{
if((idx + 1) == int(start_size - int(sizeof...(Args))))
{
cout << start_size << " " << idx << endl;
return;
}
func<Args...>(start_size, idx);
}
template <typename... Args>
void func_wrapper(int idx)
{
func<Args...>(sizeof...(Args),idx);
}
int main()
{
func_wrapper<int,double,char>(1);
}
Error:
prog.cc:37:5: error: no matching function for call to 'func'
func<Args...>(sizeof...(Args),idx);
^~~~~~~~~~~~~
prog.cc:44:5: note: in instantiation of function template specialization 'func_wrapper<int, double, char>' requested here
func_wrapper<int,double,char>(1);
^
prog.cc:16:6: note: candidate template ignored: requirement '!sizeof...(Args)' was not satisfied [with T = int, Args = <double, char>]
void func(int start_size, int idx)
^
prog.cc:23:6: note: candidate template ignored: substitution failure [with T = int, Args = <double, char>]: non-type template argument evaluates to 2, which cannot be narrowed to type 'bool'
void func(int start_size, int idx)
^
1 error generated.
Wandbox: https://wandbox.org/permlink/yqki47uYcwUlE013
Aucun commentaire:
Enregistrer un commentaire