pre::type_traits::function_traits< F, typename > Struct Template Reference

Provides access to lambda and functions arity, return type, arguments type and access as std::function type: More...

Detailed Description

template<typename F, typename = void>
struct pre::type_traits::function_traits< F, typename >

Provides access to lambda and functions arity, return type, arguments type and access as std::function type:

Parameters
FThe function, function pointer or lambda type to introspect, pass it as decltype(your_lambda).
#include <iostream>
#include <typeinfo>
#include <pre/traits/function_traits.hpp>
#include <pre/functional/to_std_function.hpp>
int main() {
auto my_lambda = [](bool arg_0, int arg_1, double arg_2, std::string arg_3) {
return int{0} ;
};
std::cout << "my_lambda number of arguments " << my_lambda_types::arity << std::endl;
std::cout << "my_lambda return type is " << typeid(my_lambda_types::result_type).name() << std::endl;
std::cout << "my_lambda argument 0 type is " << typeid(my_lambda_types::arg<0>).name() << std::endl;
std::cout << "my_lambda argument 1 type is " << typeid(my_lambda_types::arg<1>).name() << std::endl;
std::cout << "my_lambda argument 2 type is " << typeid(my_lambda_types::arg<2>).name() << std::endl;
std::cout << "my_lambda argument 3 type is " << typeid(my_lambda_types::arg<3>).name() << std::endl;
std::cout << "my_lambda function type is " << typeid(my_lambda_types::function_type).name() << std::endl;
auto std_function = pre::functional::to_std_function(my_lambda);
std::cout << "my_lambda called as std::function " << std_function(true, int{42}, double{3.14}, std::string{"Hello World"}) << std::endl;
return 0;
}

The documentation for this struct was generated from the following file: