From e00f519cddc6b63ee96f67b855a65f8ffc92001d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Feb 2021 12:31:09 +0100 Subject: [PATCH] AK: Add formatter for DistinctNumeric --- AK/DistinctNumeric.h | 10 ++++++++++ AK/Tests/TestDistinctNumeric.cpp | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/AK/DistinctNumeric.h b/AK/DistinctNumeric.h index 59c6ad2739a..ae0c43f320e 100644 --- a/AK/DistinctNumeric.h +++ b/AK/DistinctNumeric.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Ben Wiederhake + * Copyright (c) 2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,6 +27,7 @@ #pragma once +#include #include #include @@ -299,6 +301,14 @@ private: T m_value {}; }; +template +struct Formatter> : Formatter { + void format(FormatBuilder& builder, DistinctNumeric value) + { + return Formatter::format(builder, "{}", value.value()); + } +}; + // TODO: When 'consteval' sufficiently-well supported by host compilers, try to // provide a more usable interface like this one: // https://gist.github.com/alimpfard/a3b750e8c3a2f44fb3a2d32038968ddf diff --git a/AK/Tests/TestDistinctNumeric.cpp b/AK/Tests/TestDistinctNumeric.cpp index 9e2b77f8876..0381bb55aad 100644 --- a/AK/Tests/TestDistinctNumeric.cpp +++ b/AK/Tests/TestDistinctNumeric.cpp @@ -24,9 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include + template class ForType { public: