From ae2abcebbbabf7ca8b806b5555c11cd0b216dbdb Mon Sep 17 00:00:00 2001 From: Moustafa Raafat Date: Mon, 14 Nov 2022 18:20:59 +0000 Subject: [PATCH] Everywhere: Use C++ concepts instead of requires clauses --- AK/DeprecatedString.h | 3 +-- AK/Statistics.h | 6 +++--- AK/Stream.h | 20 ++++++++----------- AK/String.h | 4 ++-- AK/Traits.h | 8 ++++---- .../Piano/ProcessorParameterWidget/Dropdown.h | 5 +++-- Userland/Libraries/LibCore/ArgsParser.cpp | 13 ++++++------ Userland/Libraries/LibCore/ArgsParser.h | 6 +++--- .../LibCrypto/BigInt/SignedBigInteger.h | 5 +++-- .../LibCrypto/BigInt/UnsignedBigInteger.h | 5 +++-- .../Libraries/LibDSP/ProcessorParameter.h | 5 +++-- Userland/Libraries/LibEDID/EDID.cpp | 9 +++++---- Userland/Libraries/LibEDID/EDID.h | 9 +++++---- Userland/Libraries/LibGfx/PNGWriter.cpp | 8 ++++---- Userland/Libraries/LibJS/Print.cpp | 4 ++-- .../LibJS/Runtime/AbstractOperations.h | 4 ++-- Userland/Libraries/LibRegex/RegexByteCode.h | 7 +++---- 17 files changed, 60 insertions(+), 61 deletions(-) diff --git a/AK/DeprecatedString.h b/AK/DeprecatedString.h index 280eda6d7c7..0b84762e5eb 100644 --- a/AK/DeprecatedString.h +++ b/AK/DeprecatedString.h @@ -282,9 +282,8 @@ public: return vformatted(fmtstr.view(), variadic_format_parameters); } - template + template [[nodiscard]] static DeprecatedString number(T value) - requires IsArithmetic { return formatted("{}", value); } diff --git a/AK/Statistics.h b/AK/Statistics.h index a74400fb05e..bd42f9514a5 100644 --- a/AK/Statistics.h +++ b/AK/Statistics.h @@ -6,15 +6,15 @@ #pragma once +#include #include #include -#include #include namespace AK { -template -requires(IsArithmetic) class Statistics { +template +class Statistics { public: Statistics() = default; ~Statistics() = default; diff --git a/AK/Stream.h b/AK/Stream.h index 552466657dd..45e62577032 100644 --- a/AK/Stream.h +++ b/AK/Stream.h @@ -134,16 +134,14 @@ InputStream& operator>>(InputStream& stream, Optional& value) return stream; } -template -InputStream& operator>>(InputStream& stream, Integral& value) -requires IsIntegral +template +InputStream& operator>>(InputStream& stream, I& value) { stream.read_or_error({ &value, sizeof(value) }); return stream; } -template -OutputStream& operator<<(OutputStream& stream, Integral value) -requires IsIntegral +template +OutputStream& operator<<(OutputStream& stream, I value) { stream.write_or_error({ &value, sizeof(value) }); return stream; @@ -151,16 +149,14 @@ requires IsIntegral #ifndef KERNEL -template -InputStream& operator>>(InputStream& stream, FloatingPoint& value) -requires IsFloatingPoint +template +InputStream& operator>>(InputStream& stream, F& value) { stream.read_or_error({ &value, sizeof(value) }); return stream; } -template -OutputStream& operator<<(OutputStream& stream, FloatingPoint value) -requires IsFloatingPoint +template +OutputStream& operator<<(OutputStream& stream, F value) { stream.write_or_error({ &value, sizeof(value) }); return stream; diff --git a/AK/String.h b/AK/String.h index 3ce07bdb895..1df4edac923 100644 --- a/AK/String.h +++ b/AK/String.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -74,9 +75,8 @@ public: [[nodiscard]] u32 hash() const; - template + template static ErrorOr number(T value) - requires IsArithmetic { return formatted("{}", value); } diff --git a/AK/Traits.h b/AK/Traits.h index aa49b3795d4..27efd35446a 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -29,8 +29,8 @@ template struct Traits : public GenericTraits { }; -template -requires(IsIntegral) struct Traits : public GenericTraits { +template +struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static constexpr unsigned hash(T value) { @@ -42,8 +42,8 @@ requires(IsIntegral) struct Traits : public GenericTraits { }; #ifndef KERNEL -template -requires(IsFloatingPoint) struct Traits : public GenericTraits { +template +struct Traits : public GenericTraits { static constexpr bool is_trivial() { return true; } static constexpr unsigned hash(T value) { diff --git a/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h b/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h index c29044adf6f..0e4c25f6755 100644 --- a/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h +++ b/Userland/Applications/Piano/ProcessorParameterWidget/Dropdown.h @@ -7,6 +7,7 @@ #pragma once #include "WidgetWithLabel.h" +#include #include #include #include @@ -14,8 +15,8 @@ #include #include -template -requires(IsEnum) class ProcessorParameterDropdown : public GUI::ComboBox { +template +class ProcessorParameterDropdown : public GUI::ComboBox { C_OBJECT(ProcessorParameterDropdown); public: diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index 72d226c579e..2d145b365c8 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -460,9 +460,8 @@ void ArgsParser::add_option(StringView& value, char const* help_string, char con add_option(move(option)); } -template -void ArgsParser::add_option(Integral& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode) -requires(IsIntegral) +template +void ArgsParser::add_option(I& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode) { Option option { OptionArgumentMode::Required, @@ -472,11 +471,11 @@ requires(IsIntegral) value_name, [&value](char const* s) { auto view = StringView { s, strlen(s) }; - Optional opt; - if constexpr (IsSigned) - opt = view.to_int(); + Optional opt; + if constexpr (IsSigned) + opt = view.to_int(); else - opt = view.to_uint(); + opt = view.to_uint(); value = opt.value_or(0); return opt.has_value(); }, diff --git a/Userland/Libraries/LibCore/ArgsParser.h b/Userland/Libraries/LibCore/ArgsParser.h index 420f52213bb..66331760de8 100644 --- a/Userland/Libraries/LibCore/ArgsParser.h +++ b/Userland/Libraries/LibCore/ArgsParser.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -89,9 +90,8 @@ public: void add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(DeprecatedString& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); - template - void add_option(Integral& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None) - requires(IsIntegral); + template + void add_option(I& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); void add_option(Optional& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None); diff --git a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h index 4a6667ebcb7..92b8833891e 100644 --- a/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h +++ b/Userland/Libraries/LibCrypto/BigInt/SignedBigInteger.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -16,8 +17,8 @@ struct SignedDivisionResult; class SignedBigInteger { public: - template - requires(IsSigned && sizeof(T) <= sizeof(i32)) + template + requires(sizeof(T) <= sizeof(i32)) SignedBigInteger(T value) : m_sign(value < 0) , m_unsigned_data(abs(static_cast(value))) diff --git a/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h b/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h index 8fee84b9bf8..c9a4c38021a 100644 --- a/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h +++ b/Userland/Libraries/LibCrypto/BigInt/UnsignedBigInteger.h @@ -9,6 +9,7 @@ #pragma once #include +#include #include #include #include @@ -25,8 +26,8 @@ public: static constexpr size_t BITS_IN_WORD = 32; // This constructor accepts any unsigned with size up to Word. - template - requires(IsIntegral && sizeof(T) <= sizeof(Word)) + template + requires(sizeof(T) <= sizeof(Word)) UnsignedBigInteger(T value) { m_words.append(static_cast(value)); diff --git a/Userland/Libraries/LibDSP/ProcessorParameter.h b/Userland/Libraries/LibDSP/ProcessorParameter.h index becec4b6787..5f9096149c5 100644 --- a/Userland/Libraries/LibDSP/ProcessorParameter.h +++ b/Userland/Libraries/LibDSP/ProcessorParameter.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -146,8 +147,8 @@ private: Logarithmic const m_logarithmic; }; -template -requires(IsEnum) class ProcessorEnumParameter final : public Detail::ProcessorParameterSingleValue { +template +class ProcessorEnumParameter final : public Detail::ProcessorParameterSingleValue { public: ProcessorEnumParameter(DeprecatedString name, EnumT initial_value) : Detail::ProcessorParameterSingleValue(move(name), ParameterType::Enum, initial_value) diff --git a/Userland/Libraries/LibEDID/EDID.cpp b/Userland/Libraries/LibEDID/EDID.cpp index 6038e60d0eb..820e5bd768e 100644 --- a/Userland/Libraries/LibEDID/EDID.cpp +++ b/Userland/Libraries/LibEDID/EDID.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -165,16 +166,16 @@ T Parser::read_host(T const* field) const return value; } -template -requires(IsIntegral && sizeof(T) > 1) +template +requires(sizeof(T) > 1) T Parser::read_le(T const* field) const { static_assert(sizeof(T) > 1); return AK::convert_between_host_and_little_endian(read_host(field)); } -template -requires(IsIntegral && sizeof(T) > 1) +template +requires(sizeof(T) > 1) T Parser::read_be(T const* field) const { static_assert(sizeof(T) > 1); diff --git a/Userland/Libraries/LibEDID/EDID.h b/Userland/Libraries/LibEDID/EDID.h index eff8f26be0f..e09802eaf46 100644 --- a/Userland/Libraries/LibEDID/EDID.h +++ b/Userland/Libraries/LibEDID/EDID.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -437,12 +438,12 @@ private: template T read_host(T const*) const; - template - requires(IsIntegral && sizeof(T) > 1) + template + requires(sizeof(T) > 1) T read_le(T const*) const; - template - requires(IsIntegral && sizeof(T) > 1) + template + requires(sizeof(T) > 1) T read_be(T const*) const; Definitions::EDID const& raw_edid() const; diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index 1821809afeb..c28d857646d 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -44,8 +44,8 @@ public: u32 crc(); private: - template - requires(IsUnsigned) ErrorOr add(T); + template + ErrorOr add(T); ByteBuffer m_data; DeprecatedString m_type; @@ -77,8 +77,8 @@ u32 PNGChunk::crc() return crc; } -template -requires(IsUnsigned) ErrorOr PNGChunk::add(T data) +template +ErrorOr PNGChunk::add(T data) { TRY(m_data.try_append(&data, sizeof(T))); return {}; diff --git a/Userland/Libraries/LibJS/Print.cpp b/Userland/Libraries/LibJS/Print.cpp index 027e695130d..6524ff9b98b 100644 --- a/Userland/Libraries/LibJS/Print.cpp +++ b/Userland/Libraries/LibJS/Print.cpp @@ -6,6 +6,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -362,9 +363,8 @@ ErrorOr print_async_generator(JS::PrintContext& print_context, JS::AsyncGe return {}; } -template +template ErrorOr print_number(JS::PrintContext& print_context, T number) -requires IsArithmetic { TRY(js_out(print_context, "\033[35;1m")); TRY(js_out(print_context, "{}", number)); diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h index b9be4c4bdb7..896484d5f85 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.h +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -167,9 +168,8 @@ Vector merge_lists(Vector const& a, Vector const& b) } // x modulo y, https://tc39.es/ecma262/#eqn-modulo -template +template auto modulo(T x, U y) -requires(IsArithmetic, IsArithmetic) { // The notation “x modulo y” (y must be finite and non-zero) computes a value k of the same sign as y (or zero) such that abs(k) < abs(y) and x - k = q × y for some integer q. VERIFY(y != 0); diff --git a/Userland/Libraries/LibRegex/RegexByteCode.h b/Userland/Libraries/LibRegex/RegexByteCode.h index 8473dec4680..70a18bd8e6e 100644 --- a/Userland/Libraries/LibRegex/RegexByteCode.h +++ b/Userland/Libraries/LibRegex/RegexByteCode.h @@ -10,6 +10,7 @@ #include "RegexMatch.h" #include "RegexOptions.h" +#include #include #include #include @@ -339,9 +340,8 @@ public: Optimizer::append_alternation(*this, move(left), move(right)); } - template + template static void transform_bytecode_repetition_min_max(ByteCode& bytecode_to_repeat, T minimum, Optional maximum, size_t min_repetition_mark_id, size_t max_repetition_mark_id, bool greedy = true) - requires(IsIntegral) { if (!maximum.has_value()) { if (minimum == 0) @@ -410,9 +410,8 @@ public: bytecode_to_repeat = move(new_bytecode); } - template + template void insert_bytecode_repetition_n(ByteCode& bytecode_to_repeat, T n, size_t repetition_mark_id) - requires(IsIntegral) { // LABEL _LOOP // REGEXP