Skip to content

std::formatter<E, CharT>

Part of Formatting.

template <typename E, typename CharT>
struct std::formatter< E, CharT >;

Formatting of tensors and expressions with std::format.

Any element that std::format takes, element by element, with no temporary: a lazy expression is read where it is printed.

The format spec follows the one of a range ([format.range.formatter]), with options of its own where a range has its type:

tensor-format-spec:  fill-and-align? width? options? (':' element-spec)?

The options, in any order, each once:

  • n: no outer brackets, as for a range;
  • l: on one line, as a range of ranges prints: [[0, 2, 4], [1, 3, 5]];
  • ?: a header first: the kind of node, the element type and the shape;
  • a: every element, however many;
  • eN: N elements at each end of every axis longer than 2 N, ... between them;
  • wN: lines of N characters at most, 75 by default as in NumPy; rows wrap past it.

By default the tensor is printed over lines, as NumPy prints an array, its columns aligned to the widest element; past 1000 elements only 3 at each end of every axis are, as in NumPy. The fill, alignment and width apply to the whole text, as for a range.

Template parameters

Name Description
E A tensor expression whose values std::format takes.
CharT The character type of the format string.

Members

parse

constexpr std::basic_format_parse_context<CharT>::iterator parse(std::basic_format_parse_context<CharT> &ctx)

Parses the options of the tensor, then the spec of its elements after :.

format

template <typename Ctx>
Ctx::iterator format(const E &expression, Ctx &ctx) const

Writes the tensor.