Skip to content

Struct gl::io::range_formatter

template <std::ranges::range R>

ClassList > io > range_formatter

A customizable stream proxy for formatting and printing C++ ranges. More...

  • #include <gl/io/ranges.hpp>

Public Attributes

Type Name
R range
The underlying range view being formatted.
std::string_view sep = ", "
The string separating each element.
std::string_view open = "["
The opening string/bracket.
std::string_view close = "]"
The closing string/bracket.

Detailed Description

This struct acts as a wrapper around any std::ranges::range, allowing it to be piped into a standard output stream with configurable separators and bounding characters.

Example Usage

std::vector<int> vec = {1, 2, 3};
std::cout << gl::io::range_formatter{vec} << '\n';
std::cout << gl::io::range_formatter{vec, " | ", "<", ">"} << '\n';

Output:

[1, 2, 3]
<1 | 2 | 3>

See Also

Template parameters:

  • R The specific type of the range being formatted.

Public Attributes Documentation

variable range

The underlying range view being formatted.

R gl::io::range_formatter< R >::range;


variable sep

The string separating each element.

std::string_view gl::io::range_formatter< R >::sep = ", ";


variable open

The opening string/bracket.

std::string_view gl::io::range_formatter< R >::open = "[";


variable close

The closing string/bracket.

std::string_view gl::io::range_formatter< R >::close = "]";


Friends Documentation

friend operator<<

Serializes the formatted range to an output stream.

inline std::ostream & io::range_formatter::operator<< (
    std::ostream & os,
    range_formatter formatter
) 

Parameters:

  • os The target output stream.
  • formatter The configured formatter instance.

Returns:

The stream reference for chaining.



The documentation for this class was generated from the following file include/gl/io/ranges.hpp