I have a class Base
and MyFunc
templates with parameter packs.
I have a class Derived
, which specifies a const T&
type in the parameter pack.
template <typename... T>
class Base {};
template <typename... T>
void MyFunc(Base<T...>, T... t) {}
class Derived : public Base<const int&> {};
void Test() { MyFunc(Derived(), 1); }
This yields the error:
no matching function for call to 'MyFunc'
deduced conflicting types for parameter 'T' (<const int &> vs. <int>)
How can I make this work so that I can use const T&
in the parameter pack?
Make one type non deducible
template <typename... Ts>
void MyFunc(Base<Ts...>, std::type_identity_t<Ts>... ts) {}
or, possibly, if appropriate, make 2 parameter packs:
template <typename... Ts, typename... Us>
void MyFunc(Base<Ts...>, Us&&... us) {}