C++ continues to refine its range library, offering developers more efficient and expressive ways to manipulate collections. In this post, we'll dive into three powerful range adaptors—
concat_view
, join_view
, and join_with_view
—exploring their differences, use cases, and practical examples.
How to Join or Concat Ranges, C++26
by Bartlomiej Filipek
From the article:
Modern C++ continuously improves its range library to provide more expressive, flexible, and efficient ways to manipulate collections. Traditionally, achieving tasks like concatenation and flattening required manual loops, copying, or custom algorithms. With C++’s range adaptors, we now have an elegant and efficient way to process collections lazily without unnecessary allocations.
In this post, we will explore three powerful range adaptors introduced in different C++ standards:
std::ranges::concat_view
(C++26)std::ranges::join_view
(C++20)std::ranges::join_with_view
(C++23)Let’s break down their differences, use cases, and examples.
std::ranges::concat_view
(C++26)The
concat_view
allows you to concatenate multiple independent ranges into a single sequence. Unlikejoin_view
, it does not require a range of ranges—it simply merges the given ranges sequentially while preserving their structure.In short:
- Takes multiple independent ranges as arguments.
- Supports random access if all underlying ranges support it.
- Allows modification if underlying ranges are writable.
- Lazy evaluation: No additional memory allocations.
Add a Comment
Comments are closed.