| 1709 | template <typename Char, align default_align = align::left, typename OutputIt, |
| 1710 | typename F> |
| 1711 | FMT_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 | |
| 1730 | template <typename Char, align default_align = align::left, typename OutputIt, |
| 1731 | typename F> |