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
Notes: sideshowbarker 2024-07-18 10:27:36 +09:00

View file

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