#include <iostream>
template<typename T_function_type>
struct pointer_wrapper {
T_function_type function_pointer;
explicit pointer_wrapper(T_function_type ptr) : function_pointer(ptr) { }
~pointer_wrapper() { }
};
template<typename T_return, typename T_arg1, typename T_arg2>
pointer_wrapper<T_return (*)(T_arg1, T_arg2)> fabricate_some_trait(T_return (*ptr)(T_arg1, T_arg2)) {
return pointer_wrapper<T_return (*)(T_arg1, T_arg2)>(ptr);
}
void hello(std::string const& name, std::string const& surname) {
std::cout << "Hi " << name << " " << surname << "! ";
std::cout << "Was wondering if it\'s possible to modify ";
std::cout << "some_trait template in that way that it\'s ";
std::cout << "capable of deducing function (as well as ";
std::cout << "static and member one) type like the ";
std::cout << "template function fabricate_some_trait is. ";
std::cout << "So I can use these traits in typedef. ";
std::cout << "Will be perfect if no <functional>, ";
std::cout << "Boost.Function nor sigc::signal is going ";
std::cout << "to be used. Hope you can help and sorry ";
std::cout << "in advance about the form of this question, ";
std::cout << "just feeling good today." << std::endl;
std::cout << "Cheers!" << std::endl;
}
int main() {
// need
// some_trait<hello>::function_type hello_pointer = hello;
// hello_pointer("Stackoverflow", "User");
fabricate_some_trait(hello).function_pointer("Stackoverflow", "User");
}
/*
template<typename T_return_type(*)(typename T_arg, typename T_arg2)>
struct some_trait {
typedef T_return (*function_type)(T_arg1, T_arg2);
typedef T_return result_type;
typedef T_arg1 arg1_type;
// (...)
};
*/