The following code example is taken from the book
C++23 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2026
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
#include <ranges>
#include <utility>
// new view type to process all elements:
template<std::ranges::range InnerRgT>
struct ProcessView : std::ranges::view_interface<ProcessView<InnerRgT>>
{
private:
InnerRgT innerRange; // view, ref_view to range, or owning view to range
public:
template<std::ranges::range RgT>
ProcessView(RgT&& rg)
: innerRange(std::forward<RgT>(rg)) {
}
auto begin() { return innerRange.begin(); }
auto end() { return innerRange.end(); }
};
// deduction guide to deal with lvalues and rvalues:
template<std::ranges::range RgT>
ProcessView(RgT&& rg) -> ProcessView<std::ranges::views::all_t<RgT>>;