为什么 g++ 声明某些 valarray o 存在"no matching function for call cbegin(o)"<double>?

Why does g++ states, that there is "no matching function for call cbegin(o)" for some valarray<double> o?

本文关键字:cbegin lt gt double call function 声明 g++ valarray 存在 为什么      更新时间:2023-10-16

请考虑以下代码:

using custom_t = std::valarray<unsigned>;
custom_t o;
unsigned acc = std::accumulate(std::cbegin(o), std::cend(o), 0);

g++-5表示

呼叫cbegin(custom_t&)没有匹配函数

如果我使用std::begin(o)std::end(o)代替,一切工作。这是一个编译器错误吗?该代码使用Visual Studio 2015编译。

这是一个libstdc++的bug,我刚刚创建了https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67374

没有

std::cbegin.
使用

unsigned acc = std::accumulate(o.cbegin(), o.cend(), 0);

感觉更面向对象。