Created
February 9, 2013 11:15
-
-
Save Amanieu/4744908 to your computer and use it in GitHub Desktop.
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 <functional> | |
#include <iostream> | |
// Detect whether the function takes an int argument or zero arguments | |
template<typename T, typename = decltype(std::declval<T>()(0))> std::true_type detect_type(const T&); | |
template<typename T, typename = decltype(std::declval<T>()())> std::false_type detect_type(const T&); | |
int main() | |
{ | |
auto a = std::bind([](int){}, std::placeholders::_1); // Prints 1 | |
//auto a = std::bind([](){}, std::placeholders::_1); // Prints 0 | |
std::cout << decltype(detect_type(a))::value << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment