I have the following code snippet where I define a struct quick with a static template using the random method with some specializations:
(I used function_traits from another SO answer. Attached below for reference.)
struct quick { template <typename T> static T random(); template <typename F> static void check(F f) { constexpr auto arity = function_traits<F>::arity;
I would like to get all types of F parameters inside check so that I can generate a tuple with random entries (based on my random methods).
Same:
auto t0 = std::make_tuple(quick::random<AllTypes>()...); //pseudo code auto t = std::make_tuple(quick::random < function_traits<F>::template arg<std::make_index_sequence<arity>>::type... > ()... );
I tried with something like:
template<typename F, typename ...TIdxs> using ArgTypes = typename function_traits<F>::template arg<TIdxs>::type...;
but failed:
main.cpp:80:72: error: expected ';' before '...' token using ArgTypes = typename function_traits<F>::template arg<TIdxs>::type...; ^ main.cpp: In static member function 'static void quick::check(F, D)': main.cpp:98:15: error: 'ArgTypes' does not name a type typedef ArgTypes<F, std::make_index_sequence<arity>> types;
I used the function traits utilities from this SO answer.
template <typename T> struct function_traits : function_traits<decltype(&T::operator())> {};
source share