Created
September 28, 2017 08:22
-
-
Save 2bbb/2249b29451f8683e27b38fdf01188968 to your computer and use it in GitHub Desktop.
check function exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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