From 08fc42002cd97d3e2ec2d445f89e07401743a7e0 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 10 Dec 2022 19:33:37 +0330 Subject: [PATCH] AK: Format the contents of NNRP if T is formattable --- AK/Format.h | 3 +++ AK/NonnullRefPtr.h | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/AK/Format.h b/AK/Format.h index 48682c2dbe..c52932e974 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -39,6 +39,9 @@ inline constexpr bool HasFormatter = true; template inline constexpr bool HasFormatter::__no_formatter_defined> = false; +template +concept Formattable = HasFormatter; + constexpr size_t max_format_arguments = 256; struct TypeErasedParameter { diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 069ac05c85..a862878867 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -228,7 +228,16 @@ inline NonnullRefPtr adopt_ref(T& object) return NonnullRefPtr(NonnullRefPtr::Adopt, object); } +template +struct Formatter> : Formatter { + ErrorOr format(FormatBuilder& builder, NonnullRefPtr const& value) + { + return Formatter::format(builder, *value); + } +}; + template +requires(!HasFormatter) struct Formatter> : Formatter { ErrorOr format(FormatBuilder& builder, NonnullRefPtr const& value) {