Consider the following snippet:
#include <iostream>
template <typename... types> void writeall(const types & ... items)
{
(std :: cout << ... << items);
}
template <typename... types> void readall(types & ... items)
{
(std :: cin >> ... >> items);
}
int main()
{
writeall(1, 2, 3, 4);
std :: cout << std :: endl;
int a, b, c, d;
readall(a, b, c, d);
}
In writeall
, I use fold expressions to feed into std :: cout
a parameter pack. Everything works perfectly, and I get 1234
printed out to screen.
In readall
, I do exactly the same, expecting to read from std :: cin
a parameter pack. However, I get
error: expected ')'
(std :: cin >> ... >> items);
What am I doing wrong? One would expect things to work exactly the same, I just replaced operator <<
with operator >>
.
As @T.C. answered, this is a bug in clang. It has been fixed. There was what appeared to be a typo that made >
and >>
not work right in fold expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With