Created
April 24, 2014 04:55
-
-
Save xlc/11242000 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 <iostream> | |
#include <typeinfo> | |
#include <type_traits> | |
#include <functional> | |
#include <tuple> | |
using namespace std; | |
int TestCount = 0; | |
struct Test | |
{ | |
int t; | |
Test() { t = ++TestCount; cout << t << "Test()" << endl; } | |
~Test() { cout << "~Test()" << endl; } | |
Test(const Test &) { t = ++TestCount; cout << t << "Test(const Test &)" << endl; } | |
Test(Test &&) { cout << t << "Test(Test &&)" << endl; } | |
Test & operator=(const Test &) { cout << t << "operator=(const Test &)" << endl; } | |
Test & operator=(Test &&) { cout << t << "operator=(Test &&)" << endl; } | |
}; | |
template <typename T> | |
struct callable_type : callable_type<decltype(&T::operator())> | |
{}; | |
template <typename ClassType, typename ReturnType, typename... Args> | |
struct callable_type<ReturnType(ClassType::*)(Args...) const> | |
{ | |
using return_type = ReturnType; | |
using argument_type = std::tuple<Args...>; | |
template<std::size_t I> | |
using arguments = std::tuple_element<I, argument_type>; | |
}; | |
template <class T> | |
void test(T t) | |
{ | |
t(); | |
} | |
int main() | |
{ | |
auto f = [](int i, float, bool){ return (double)i; }; | |
cout << boolalpha | |
<< is_same<callable_type<decltype(f)>::arguments<0>::type, int>::value << endl | |
<< is_same<callable_type<decltype(f)>::arguments<1>::type, float>::value << endl | |
<< is_same<callable_type<decltype(f)>::arguments<2>::type, bool>::value << endl | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment