Ed Tanous | 95c6307 | 2024-03-26 13:19:52 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <boost/system/error_code.hpp> |
| 4 | #include <boost/url/grammar.hpp> |
| 5 | #include <boost/url/url_view_base.hpp> |
| 6 | |
| 7 | #include <format> |
| 8 | |
| 9 | // NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp) |
| 10 | template <std::derived_from<boost::system::error_code> ErrorCodeType> |
| 11 | struct std::formatter<ErrorCodeType> |
| 12 | { |
| 13 | constexpr auto parse(std::format_parse_context& ctx) |
| 14 | { |
| 15 | return ctx.begin(); |
| 16 | } |
| 17 | |
| 18 | auto format(const ErrorCodeType& ec, auto& ctx) const |
| 19 | { |
| 20 | return std::format_to(ctx.out(), "{}", ec.what()); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | template <std::derived_from<boost::urls::grammar::string_view_base> StringView> |
| 25 | struct std::formatter<StringView> |
| 26 | { |
| 27 | constexpr auto parse(std::format_parse_context& ctx) |
| 28 | { |
| 29 | return ctx.begin(); |
| 30 | } |
| 31 | auto format(const StringView& msg, auto& ctx) const |
| 32 | { |
| 33 | return std::format_to(ctx.out(), "{}", |
| 34 | std::string_view(msg.data(), msg.size())); |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | template <std::derived_from<boost::urls::url_view_base> UrlBase> |
| 39 | struct std::formatter<UrlBase> |
| 40 | { |
| 41 | constexpr auto parse(std::format_parse_context& ctx) |
| 42 | { |
| 43 | return ctx.begin(); |
| 44 | } |
| 45 | auto format(const UrlBase& msg, auto& ctx) const |
| 46 | { |
| 47 | return std::format_to(ctx.out(), "{}", std::string_view(msg.buffer())); |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | template <std::derived_from<boost::core::string_view> StringView> |
| 52 | struct std::formatter<StringView> |
| 53 | { |
| 54 | constexpr auto parse(std::format_parse_context& ctx) |
| 55 | { |
| 56 | return ctx.begin(); |
| 57 | } |
| 58 | auto format(const StringView& msg, auto& ctx) const |
| 59 | { |
| 60 | return std::format_to(ctx.out(), "{}", std::string_view(msg)); |
| 61 | } |
| 62 | }; |
| 63 | // NOLINTEND(readability-convert-member-functions-to-static, cert-dcl58-cpp) |