Zepha/src/util/FunctionTraits.h

34 lines
1.0 KiB
C++

#pragma once
#include <functional>
/**
* Template struct that takes a function pointer, method pointer, or lambda and
* exposes the corresponding std::function type, arguments types, and return type.
* Adapted from the god over at https://stackoverflow.com/q/21657627 (thank you god)
*/
template <typename T>
struct function_traits : public function_traits<decltype(&T::operator())> {};
template <typename C, typename R, typename... Args>
struct function_traits<R(C::*)(Args...) const> {
typedef std::function<R(Args...)> function_type;
typedef std::tuple<Args...> args_type;
typedef R return_type;
};
template <typename C, typename R, typename... Args>
struct function_traits<R(C::*)(Args...)> {
typedef std::function<R(Args...)> function_type;
typedef std::tuple<Args...> args_type;
typedef R return_type;
};
template <typename R, typename... Args>
struct function_traits<R(*)(Args...)> {
typedef std::function<R(Args...)> function_type;
typedef std::tuple<Args...> args_type;
typedef R return_type;
};