MCPcopy Create free account
hub / github.com/fmtlib/fmt / write_padded

Function write_padded

include/fmt/format.h:1711–1728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1709template <typename Char, align default_align = align::left, typename OutputIt,
1710 typename F>
1711FMT_CONSTEXPR auto write_padded(OutputIt out, const format_specs& specs,
1712 size_t size, size_t width, F&& f) -> OutputIt {
1713 static_assert(default_align == align::left || default_align == align::right,
1714 "");
1715 unsigned spec_width = to_unsigned(specs.width);
1716 size_t padding = spec_width > width ? spec_width - width : 0;
1717 // Shifts are encoded as string literals because static constexpr is not
1718 // supported in constexpr functions.
1719 auto* shifts =
1720 default_align == align::left ? "\x1f\x1f\x00\x01" : "\x00\x1f\x00\x01";
1721 size_t left_padding = padding >> shifts[static_cast<int>(specs.align())];
1722 size_t right_padding = padding - left_padding;
1723 auto it = reserve(out, size + padding * specs.fill_size());
1724 if (left_padding != 0) it = fill<Char>(it, left_padding, specs);
1725 it = f(it);
1726 if (right_padding != 0) it = fill<Char>(it, right_padding, specs);
1727 return base_iterator(out, it);
1728}
1729
1730template <typename Char, align default_align = align::left, typename OutputIt,
1731 typename F>

Callers 1

formatMethod · 0.85

Calls 5

to_unsignedFunction · 0.85
base_iteratorFunction · 0.85
fill_sizeMethod · 0.80
reserveFunction · 0.70
alignMethod · 0.45

Tested by 1

formatMethod · 0.68