#include <iostream>
#include <string>
using namespace std;
class function_set {
public:
static void override() { cout << "1" << endl; }
static void override( const char* ) { cout << "2" << endl; }
static void override( string ) { cout << "2" << endl; }
};
#define probe1( funct, ... ) funct( __VA_ARGS__ )
template < class f, class ... ax > auto probe2( f && funct, ax ... args ) -> decltype( funct( args ... ) ) {
return funct( args ... );
}
int main() {
probe1( function_set::override, "abc" );
probe2( function_set::override, "abc" );
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgZnVuY3Rpb25fc2V0IHsKcHVibGljOgoJc3RhdGljIHZvaWQgb3ZlcnJpZGUoKSB7IGNvdXQgPDwgIjEiIDw8IGVuZGw7IH0KCXN0YXRpYyB2b2lkIG92ZXJyaWRlKCBjb25zdCBjaGFyKiApIHsgY291dCA8PCAiMiIgPDwgZW5kbDsgfQoJc3RhdGljIHZvaWQgb3ZlcnJpZGUoIHN0cmluZyApIHsgY291dCA8PCAiMiIgPDwgZW5kbDsgfQp9OwoKI2RlZmluZSBwcm9iZTEoIGZ1bmN0LCAuLi4gKSBmdW5jdCggX19WQV9BUkdTX18gKQoKdGVtcGxhdGUgPCBjbGFzcyBmLCBjbGFzcyAuLi4gYXggPiBhdXRvIHByb2JlMiggZiAmJiBmdW5jdCwgYXggLi4uIGFyZ3MgKSAtPiBkZWNsdHlwZSggZnVuY3QoIGFyZ3MgLi4uICkgKSB7CglyZXR1cm4gZnVuY3QoIGFyZ3MgLi4uICk7Cn0KCmludCBtYWluKCkgewoJcHJvYmUxKCBmdW5jdGlvbl9zZXQ6Om92ZXJyaWRlLCAiYWJjIiApOwoJcHJvYmUyKCBmdW5jdGlvbl9zZXQ6Om92ZXJyaWRlLCAiYWJjIiApOwp9
prog.cpp: In function ‘int main()’:
prog.cpp:20:40: error: no matching function for call to ‘probe2(<unresolved overloaded function type>, const char [4])’
probe2( function_set::override, "abc" );
^
prog.cpp:20:40: note: candidate is:
prog.cpp:14:41: note: template<class f, class ... ax> decltype (funct(probe2::args ...)) probe2(f&&, ax ...)
template < class f, class ... ax > auto probe2( f && funct, ax ... args ) -> decltype( funct( args ... ) ) {
^
prog.cpp:14:41: note: template argument deduction/substitution failed:
prog.cpp:20:40: note: couldn't deduce template parameter ‘f’
probe2( function_set::override, "abc" );
^