用运算符折叠表达式 >>

Mat*_*nti 5 c++ variadic-templates fold-expression

考虑以下片段:

#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);
}
Run Code Online (Sandbox Code Playgroud)

在 中writeall,我使用折叠表达式输入std :: cout参数包。一切正常,我被1234打印到屏幕上。

在 中readall,我做的完全一样,期望从std :: cin参数包中读取。但是,我得到

error: expected ')'
(std :: cin >> ... >> items);
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?人们希望事情完全一样,我只是用 operator 替换<<了 operator >>

Yak*_*ont 1

正如@TC 回答的那样,这是 clang 中的一个错误。它已被修复。似乎有一个拼写错误导致折叠表达式无法正常工作>>>