Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C3520 parameter pack must be expanded – incorrect behaviour for 'variadic using'

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading