//******************************************************** // The following code example is taken from the book // C++23 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd23.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include #include #include // new view type for all elements: template struct SepNewlineView : std::ranges::view_interface> { private: InnerRgT innerRange; public: template SepNewlineView(RgT&& rg) : innerRange(std::forward(rg)) { } auto begin() { return innerRange.begin(); } auto end() { return innerRange.end(); } }; // deduction guide to deal with lvalues and rvalues: template SepNewlineView(RgT&& rg) -> SepNewlineView>; // add special formatter for this view: template struct std::formatter> : std::range_formatter> { constexpr formatter() { this->set_brackets("[", "]"); this->set_separator("\n "); } }; // make the view usable in a pipe: struct SepNewlineFO : std::ranges::range_adaptor_closure { template constexpr auto operator()(RgT&& rg) const { return SepNewlineView(std::forward(rg)); } };