o? Pay attention to the following co...">

Why does g ++ claim that there is some appropriate function to call cbegin (o) "for some valarray <double> o?

Pay attention to the following code:

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

g ++ - 5 says

There is no corresponding function to call cbegin(custom_t&)

If I use std::begin(o)and std::end(o)instead, everything will work. Is this a compiler error? The code is compiled using Visual Studio 2015.

+4
source share
2 answers

This is a libstdc ++ error, I just created https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67374

+3
source

No

std::cbegin.

Using

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

which feels a lot more object oriented.

-3
source

All Articles