I have this code:
#include <iostream>
using namespace std;
int print(int i)
{
cout << endl << i;
}
template<typename ...Args>
inline void pass(Args&&...args)
{
}
template<typename ...args>
inline void expand(args&&... a)
{
print(a) ...; //this doesn't expand
//pass( print(a)... ); this works
}
int main() {
expand(1,2,3,4);
return 0;
}
It throws an error:
In function 'void expand(args&& ...)':
error: expected ';' before '...' token
print(a) ...;
^
parameter packs not expanded with '...':
print(a) ...;
^
Why is the use of the pass()
function necessary?