1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

AK: Explicitly require Checked types to be Integral

These were already implicitly required to be integral via the usage of
the is_within_range templated function, but making them explicit should
produce nicer error messages when building, and make the IDE highlight
the incorrect usage.
This commit is contained in:
Idan Horowitz 2021-07-04 20:03:09 +03:00 committed by Linus Groh
parent 301c1a3a58
commit 9321d9d83d

View file

@ -28,6 +28,7 @@
#pragma once #pragma once
#include <AK/Assertions.h> #include <AK/Assertions.h>
#include <AK/Concepts.h>
#include <AK/NumericLimits.h> #include <AK/NumericLimits.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
@ -109,17 +110,17 @@ template<typename Destination, typename Source>
return TypeBoundsChecker<Destination, Source>::is_within_range(value); return TypeBoundsChecker<Destination, Source>::is_within_range(value);
} }
template<typename T> template<Integral T>
class Checked { class Checked {
public: public:
constexpr Checked() = default; constexpr Checked() = default;
constexpr Checked(T value) explicit constexpr Checked(T value)
: m_value(value) : m_value(value)
{ {
} }
template<typename U> template<Integral U>
constexpr Checked(U value) constexpr Checked(U value)
{ {
m_overflow = !is_within_range<T>(value); m_overflow = !is_within_range<T>(value);