Skip to content

Instantly share code, notes, and snippets.

@Amanieu
Created February 9, 2013 11:15
Show Gist options
  • Save Amanieu/4744908 to your computer and use it in GitHub Desktop.
Save Amanieu/4744908 to your computer and use it in GitHub Desktop.
#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