#include <type_traits>
#include <iostream>
int foo( int a, int b)
{
return 1 ;
}
//int foo(int a, int b, bool c)
//{
// return 0;
//}
template < typename R, typename ... Types >
constexpr size_t getArgumentCount( R( * ) ( Types ...) )
{
return sizeof ...( Types) ;
}
template < int N>
static int setupTempl( int a, int b, typename std:: enable_if < N == 3 , void > :: type * = nullptr)
{
return foo( a, b, true ) ;
}
template < int N>
static int setupTempl( int a, int b, typename std:: enable_if < N == 2 , void > :: type * = nullptr)
{
return foo( a, b) ;
}
int main( )
{
setupTempl< getArgumentCount( foo) > ( 1 , 2 ) ;
return 0 ;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgojaW5jbHVkZSA8aW9zdHJlYW0+CgppbnQgZm9vKGludCBhLCBpbnQgYikKewogICAgIHJldHVybiAxOwp9CgovL2ludCBmb28oaW50IGEsIGludCBiLCBib29sIGMpCi8vewovLyAgICByZXR1cm4gMDsKLy99Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgUiwgdHlwZW5hbWUgLi4uIFR5cGVzPgpjb25zdGV4cHIgc2l6ZV90IGdldEFyZ3VtZW50Q291bnQoUigqKShUeXBlcyAuLi4pKQp7CiAgICByZXR1cm4gc2l6ZW9mLi4uKFR5cGVzKTsKfQoKdGVtcGxhdGU8aW50IE4+CnN0YXRpYyBpbnQgc2V0dXBUZW1wbChpbnQgYSwgaW50IGIsIHR5cGVuYW1lIHN0ZDo6ZW5hYmxlX2lmPE4gPT0gMywgdm9pZD46OnR5cGUqID0gbnVsbHB0cikKewogICAgIHJldHVybiBmb28oYSwgYiwgdHJ1ZSk7Cn0KCnRlbXBsYXRlPGludCBOPgpzdGF0aWMgaW50IHNldHVwVGVtcGwoaW50IGEsIGludCBiLCB0eXBlbmFtZSBzdGQ6OmVuYWJsZV9pZjxOID09IDIsIHZvaWQ+Ojp0eXBlKiA9IG51bGxwdHIpCnsKICAgICByZXR1cm4gZm9vKGEsIGIpOwp9CgppbnQgbWFpbigpCnsKICAgICBzZXR1cFRlbXBsPGdldEFyZ3VtZW50Q291bnQoZm9vKT4oMSwgMik7CiAgICAgCiAgICAgcmV0dXJuIDA7Cn0K
compilation info
prog.cpp: In function ‘int setupTempl(int, int, typename std::enable_if<(N == 3), void>::type*)’:
prog.cpp:23:27: error: too many arguments to function ‘int foo(int, int)’
return foo(a, b, true);
^
prog.cpp:4:5: note: declared here
int foo(int a, int b)
^~~
stdout