libstdc++-v3/testsuite/std/format/formatter/basic.cc
raw| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | // BasicFormatter requirements do not require a const parameter. |
| 4 | |
| 5 | #include <format> |
| 6 | |
| 7 | struct X { }; |
| 8 | |
| 9 | template<> struct std::formatter<X, char> |
| 10 | { |
| 11 | constexpr auto parse(format_parse_context& ctx) |
| 12 | { return ctx.begin(); } |
| 13 | |
| 14 | // Takes non-const X& |
| 15 | format_context::iterator format(X&, format_context& ctx) const |
| 16 | { |
| 17 | auto out = ctx.out(); |
| 18 | *out++ = 'x'; |
| 19 | return out; |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | X x; |
| 24 | auto s = std::format("{}", x); |