Home > other >  C3520 parameter pack must be expanded - incorrect behaviour for 'variadic using'
C3520 parameter pack must be expanded - incorrect behaviour for 'variadic using'

Time:04-05

While compiling the code below with Qt 5.12 using Microsoft Visual C Compiler 15.9.28307.1300 (amd64) and c 17 standard I get the following error:

error C3520: 'Args': parameter pack must be expanded in this context note: see reference to class template instantiation 'Helper<Args...>' being compiled

template<typename T> 
struct Base { 
    void operator()(const T& arg){} 
}; 

template <typename... Args>
class Helper : Base<Args>... {
public:
    using Base<Args>::operator()...;
};

Is this a bug with msvc? Is there any known workaround? The same code compiles on macOS using clang.

CodePudding user response:

As workaround to variadic using (C 17), you might use the recursive way:

template <typename... Args>
class Helper;

template <>
class Helper<>
{
};

template <typename T>
class Helper<T> : Base<T>
{
public:
    using Base<T>::operator();
};

template <typename T, typename... Ts>
class Helper<T, Ts...> : Base<T>, Helper<Ts...>
{
public:
    using Base<T>::operator();
    using Helper<Ts...>::operator();
};

Demo

  • Related