Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ argument pack recursion with two arguments

I have a template class that uses two types:

template<typename T1,typename T2> class Foo { ... };

I need to write a function that takes any number of Foo variables:

template <typename T1, typename T2, typename... Others> size_t getSize(Foo<T1,T2> *f, Foo<Others>*... o) { ... };

If I implement the class Foo with only one template parameter, it works well. But with two (or more) parameters, the compiler complains that Foo<Others> requires two args.

Is is possible to achieve argument pack forwarding when the class Foo has multiple template parameters ?

like image 396
dexter Avatar asked Dec 31 '22 22:12

dexter


1 Answers

What about

template <typename ... Ts1, typename ... Ts2>
std::size_t get_size (Foo<Ts1, Ts2> * ... fs)
 { /* ... */ }

?

Or, maybe,

template <typename T1, typename T2, typename ... Us1, typename ... Us2>
std::size_t get_size (Foo<T1, T2> * f, Foo<Us1, Us2> * ... fs)
 { /* ... */ }

if you want a first Foo managed differently.

like image 129
max66 Avatar answered Jan 13 '23 20:01

max66