#include <iostream>
template <typename T0, typename T1>
struct Clazz {
void doSomething(const std::shared_ptr<T0>& p0,
const std::shared_ptr<T1>& p1) {}
T0 t0;
T1 t1;
};
template <typename T0, typename T1, typename T2>
struct Clazz3 {
void doSomething(const std::shared_ptr<T0>& p0,
const std::shared_ptr<T1>& p1,
const std::shared_ptr<T1>& p2) {}
T0 t0;
T1 t1;
T2 t1;
};
template <typename... Ts>
struct ClazzN {
// Q1: one part: define types in doSomething
// Q2: two part: define data members
// using param_type = typename (std::shared_ptr<Ts>, ...) // fold expression? can it works on type part, or only value?
// Ts... ts; // ??? pack it by tuple ???
};
int main() {
Clazz<int, double> c2;
Clazz3<int, double, char> c3;
return 0;
}
I have a class ClazN
, and I:
- want a variadic template form, instead of limiting the class template type size.
- want define different data members as the template type correspodingly.
- the
T1
,T2
...Tn
have no relationship.
How to write ClazzN
? It's too stupid to write a lot repeated codes.
How could I do this? Need your help, thanks a lot!!!