Lets say that I have a function that accepts only a type template parameter, I canβt change its definition / implementation.
template < typename T > void do_it();
Now I have a typelist, which is defined in the usual way, also cannot change it:
template< typename ...Ts > struct typelist;
I want to implement a function that takes a list of types and runs do_it () for each type:
template< typename List > void do_them();
The only solution I have found so far:
template< typename T > void do_them_impl() { do_it<T>(); } template< typename T, typename Ts...> void do_them_impl() { do_it<T>(); do_them_impl<Ts...>(); } template< template < typename...> class List, typename ...Ts > void do_them_extract( List<Ts...>&& ) { do_them_impl< Ts >(); } template< typename List > void do_them() { do_them_impl( List{} ); }
But for each case, 4 (!) Functions are required. I want to create one do_them
function. I will need a lot of these, and I do not want to write four functions for each. Did I miss something?
C ++ 14 is welcome, also C ++ 17 solutions, but marked as such.
source share