In some code snippet, here on stackoverflow mostly, I often found myself reading code like this:
std::array<std::string_view, 3> appleNames{"Fuji", "Golden", "Gala"};
std::copy (appleNames.begin (), appleNames.end (), std::ostream_iterator<std::string_view> (std::cout, "\n")); // print all the names
It's just me or this is not so glad to see? Isn't this version more understandable at a first sight?
std::array<std::string_view, 3> appleNames{"Fuji", "Golden", "Gala"};
for(const auto& name : appleNames)
std::cout<<name<<"\n"; // print all the names
I know this question wiil be mostly opinion based, but I would like to understand what are the benefits with the first version, readability wise mainly, 'cause I can't really figure it out.