使用运算符>>折叠表达式[重复]

问题描述 投票:0回答:1

考虑以下代码片段:

#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);
}

writeall
中,我使用折叠表达式将其输入到
std :: cout
参数包中。一切都很完美,我将
1234
打印到屏幕上。

readall
中,我做了完全相同的事情,期望从
std :: cin
读取参数包。不过,我明白了

error: expected ')'
(std :: cin >> ... >> items);

我做错了什么?人们会期望事情的工作方式完全相同,我只是将运算符

<<
替换为运算符
>>

c++ clang variadic-templates compiler-bug fold-expression
1个回答
1
投票

如@T.C.回答说,这是 clang 中的一个错误。它已修复。似乎存在拼写错误,导致

>
>>
在折叠表达式中无法正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.