Skip to content

Instantly share code, notes, and snippets.

@2bbb
Created September 28, 2017 08:22
Show Gist options
  • Save 2bbb/2249b29451f8683e27b38fdf01188968 to your computer and use it in GitHub Desktop.
Save 2bbb/2249b29451f8683e27b38fdf01188968 to your computer and use it in GitHub Desktop.
check function exist
#include <iostream>
int f(int x) {
std::cout << "true f" << std::endl;
return 0;
}
namespace bbb {
struct function_is_not_exist {};
function_is_not_exist f(...) { return {}; };
using check_f = std::is_same<decltype(f(0)), function_is_not_exist>;
}
template <typename type, typename = std::enable_if<std::is_same<type, int>::value>>
auto f(type x) -> typename std::enable_if<bbb::check_f::value, int>::type {
std::cout << "dummy f" << std::endl;
return 0;
}
int main(int argc, char *argv[]) {
f(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment