#include <iostream>
#include <type_traits>
#define declare_member_check(name, ret_type, /*args*/ ...) \
namespace member_check{ \
template <typename T> \
struct has_##name \
{ \
template <typename U> static std::true_type test(decltype(&U::name)); \
template <typename U> static std::false_type test(...); \
static constexpr bool value = std::is_same<decltype(test<T>(nullptr)), std::true_type>::value; \
};\
}\
struct Test {
const std::string &print(const std::string &str, void *pointer, int *second) {
std::cout<<str<<std::endl;
return str;
}
};
struct Test2 {
void show_msg(){}
};
declare_member_check(show_msg, void);
declare_member_check(print, const std::string &, const std::string &, void *, int *);
int main()
{
std::cout << "Check show_msg" << std::endl;
std::cout << "Test: " << (member_check::has_show_msg<Test>::value ? "yes" : "no") <<std::endl;
std::cout << "Test2: " << (member_check::has_show_msg<Test2>::value ? "yes" : "no") <<std::endl;
std::cout << "Check print msg" << std::endl;
std::cout << "Test: " << (member_check::has_print<Test>::value ? "yes" : "no") << std::endl;
std::cout << "Test2: " << (member_check::has_print<Test2>::value ? "yes" : "no") << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CgojZGVmaW5lIGRlY2xhcmVfbWVtYmVyX2NoZWNrKG5hbWUsIHJldF90eXBlLCAvKmFyZ3MqLyAuLi4pIFwKbmFtZXNwYWNlIG1lbWJlcl9jaGVja3sgXAp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4gXApzdHJ1Y3QgaGFzXyMjbmFtZSBcCnsgXAogICAgdGVtcGxhdGUgPHR5cGVuYW1lIFU+IHN0YXRpYyBzdGQ6OnRydWVfdHlwZSB0ZXN0KGRlY2x0eXBlKCZVOjpuYW1lKSk7IFwKICAgIHRlbXBsYXRlIDx0eXBlbmFtZSBVPiBzdGF0aWMgc3RkOjpmYWxzZV90eXBlIHRlc3QoLi4uKTsgXAogICAgc3RhdGljIGNvbnN0ZXhwciBib29sIHZhbHVlID0gc3RkOjppc19zYW1lPGRlY2x0eXBlKHRlc3Q8VD4obnVsbHB0cikpLCBz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