I can take several ints from a vector putting them to standard output with an iterator:
std::vector<int> v{0,1,2,3,4,5};
std::copy_n(v.begin(),
3,
std::ostream_iterator<int>(std::cout, ":"));
I can use the new C++20 ranges to take several ints from a vector putting them to standard output with | operator in a for loop, one value at a time using <<.
for(int n : std::views::all(v)
| std::views::take(3))
{
std::cout << n << '/';
}
How can I put the results of std::views::all(v) | std::views::take(3) to standard output w/o explicitly looping through values?
Something like:
std::views::all(v)
| std::views::take(4)
| std::ostream_iterator<int>(std::cout, " ");
or
std::cout << (std::views::all(v)
| std::views::take(4));