From e9dda2a5f831bfadab8f08e17c30609fa3247e7d Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 8 Nov 2023 21:12:54 +0100 Subject: [PATCH] AK: Provide a default set of Traits for `const` types --- AK/Endian.h | 10 -------- AK/Traits.h | 5 ++++ Userland/Libraries/LibGfx/Font/BitmapFont.cpp | 4 +--- .../LibGfx/Font/OpenType/DataTypes.h | 8 +++---- .../Libraries/LibGfx/Font/OpenType/Tables.h | 24 +++++++++---------- 5 files changed, 22 insertions(+), 29 deletions(-) diff --git a/AK/Endian.h b/AK/Endian.h index 936304818f5..2b028cff724 100644 --- a/AK/Endian.h +++ b/AK/Endian.h @@ -125,21 +125,11 @@ struct Traits> : public DefaultTraits> { static constexpr bool is_trivially_serializable() { return Traits::is_trivially_serializable(); } }; -template -struct Traits const> : public DefaultTraits const> { - static constexpr bool is_trivially_serializable() { return Traits::is_trivially_serializable(); } -}; - template struct Traits> : public DefaultTraits> { static constexpr bool is_trivially_serializable() { return Traits::is_trivially_serializable(); } }; -template -struct Traits const> : public DefaultTraits const> { - static constexpr bool is_trivially_serializable() { return Traits::is_trivially_serializable(); } -}; - constexpr u16 bitswap(u16 v) { v = ((v >> 1) & 0x5555) | ((v & 0x5555) << 1); // even & odd bits diff --git a/AK/Traits.h b/AK/Traits.h index 229c2d63ad7..b6f35573820 100644 --- a/AK/Traits.h +++ b/AK/Traits.h @@ -30,6 +30,11 @@ template struct Traits : public DefaultTraits { }; +template +struct Traits : public Traits { + using PeekType = typename Traits::ConstPeekType; +}; + template struct Traits : public DefaultTraits { static constexpr bool is_trivial() { return true; } diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index a12e423e33f..5251e459f2c 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -43,10 +43,8 @@ static constexpr size_t s_max_range_mask_size = s_max_glyph_count / (256 * 8); } -// FIXME: We define the traits for the const FontFileHeader, because that's the one we use, and defining -// Traits doesn't apply to Traits. Once that's fixed, remove the const here. template<> -class AK::Traits : public DefaultTraits { +class AK::Traits : public DefaultTraits { public: static constexpr bool is_trivially_serializable() { return true; } }; diff --git a/Userland/Libraries/LibGfx/Font/OpenType/DataTypes.h b/Userland/Libraries/LibGfx/Font/OpenType/DataTypes.h index db3fe2e64b9..f8803434d6a 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/DataTypes.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/DataTypes.h @@ -55,19 +55,19 @@ static_assert(AssertSize()); namespace AK { template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; } diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h index 93fc02742f0..988203f537b 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h @@ -48,13 +48,13 @@ static_assert(AssertSize()); } template<> -class AK::Traits : public DefaultTraits { +class AK::Traits : public DefaultTraits { public: static constexpr bool is_trivially_serializable() { return true; } }; template<> -class AK::Traits : public DefaultTraits { +class AK::Traits : public DefaultTraits { public: static constexpr bool is_trivially_serializable() { return true; } }; @@ -788,47 +788,47 @@ private: namespace AK { template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; template<> -struct Traits : public DefaultTraits { +struct Traits : public DefaultTraits { static constexpr bool is_trivially_serializable() { return true; } }; }