I have a class like this:
template <typename T>
struct operation {
typedef T result_type;
typedef ::std::shared_ptr<operation<T> > ptr_t;
};
I have a functor that will match this type ::std::function:
::std::function<int(double, ::std::string)>
I want to create a functor that has a signature something like this:
operation<int>::ptr_t a_func(operation<double>::ptr_t, operation< ::std::string>::ptr_t);
I want to do this in an automatic way to create a similar functor for any type ::std::function.
Finally, I would like to put this wrinkle. It:
::std::function<int(operation<double>::ptr_t, ::std::string)>
should result in the following:
operation<int>::ptr_t a_func(operation<double>::ptr_t, operation< ::std::string>::ptr_t);
Because if the functor already accepts operation<T>::ptr_t, which means that he understands what he is and wants to deal with their asynchronous nature.
How should I do it? I have a naive and partially working attempt:
template <typename argtype>
struct transform_type {
typedef typename operation<argtype>::ptr_t type;
};
template <typename ResultType, typename... ArgTypes>
::std::function<typename transform_type<ResultType>::type(typename transform_type<ArgTypes...>::type)>
make_function(::std::function<ResultType(ArgTypes...)>)
{
return nullptr;
}
It does not detect arguments that already have a type std::shared_ptr<operation<T> >. And this transform_type specialization will not compile:
template <typename argtype>
struct transform_type<typename operation<argtype>::ptr_t>
{
typedef typename stub_op<argtype>::ptr_t type;
};