Skip to content

Instantly share code, notes, and snippets.

@PovelikinRostislav
Created August 13, 2018 13:10
Show Gist options
  • Save PovelikinRostislav/5a52786438b9b3271d751f88b98c60d1 to your computer and use it in GitHub Desktop.
Save PovelikinRostislav/5a52786438b9b3271d751f88b98c60d1 to your computer and use it in GitHub Desktop.
Find out a type of lambda or functor
#include <tuple>
template<typename Functor> struct functor_arg : functor_arg<decltype(&Functor::operator())> {};
template<typename Functor, typename ReturnType, typename... ArgTypes> struct functor_arg<ReturnType (Functor::*)(ArgTypes...) const> {
template<std::size_t N> using arg_t = std::tuple_element_t<N, std::tuple<ArgTypes...>>;
};
int main() {
auto func = [](int) {};
typename functor_arg<decltype(func)>::arg_t<0> arg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment