Skip to content

Commit

Permalink
AK: Explicitly require Checked types to be Integral
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IdanHo authored and linusg committed Jul 4, 2021
1 parent 301c1a3 commit 9321d9d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions AK/Checked.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#pragma once

#include <AK/Assertions.h>
#include <AK/Concepts.h>
#include <AK/NumericLimits.h>
#include <AK/StdLibExtras.h>

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9321d9d

Please sign in to comment.