I was looking at answers of how to call a function only if it exists and found some code on this questiuon Is it possible to write a template to check for a function's existence?. I'm trying to use std::is_member_function_pointer as the discriminator to call specialised templated code. But I'm seeing true twice in the output, when I expect to see false and then true. Any suggestions on why this might be? The code can also be seen at https://ideone.com/HZ17Wf
#include <iostream>
#include <utility>
#include <type_traits>
namespace Ckb
{
struct Version
{
enum { Major = 1, Minor = 0, Release = 0 };
void CheckDependencies()
{
std::cout << "Ckb Check" << std::endl;
}
};
} // namespace Ckb
namespace Cg
{
struct Version { enum { Major = 1, Minor = 8, Release = 1 }; };
} // namespace Cg
template <typename T, bool> struct RunCheck
{ void operator()() {std::cout << "false" << std::endl;} };
template <typename T> struct RunCheck<T, true>
{ void operator()() { std::cout << "true" << std::endl; } };
template <typename T> void Do()
{
RunCheck<T, std::is_member_function_pointer<void(T::*)()>::value>()();
}
int main()
{
Do<Cg::Version>();
Do<Ckb::Version>();
return 0;
}