Skip to content

Commit

Permalink
added requires constraints to IntegralCast<>
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 4, 2024
1 parent 86c8773 commit 67875ff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/orm/utils/integralcast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Private
!std::same_as<T, bool> && !std::same_as<T, char>;

/*! Get integral type name as a string. */
template<std::integral T>
template<std::integral T> requires (!std::is_reference_v<T>)
constexpr const char *IntegralTypeName() noexcept
{
// Sorted by most used types
Expand Down Expand Up @@ -103,7 +103,7 @@ namespace Private

/*! Format the given integer number (insert group separator before every 3th
number). */
template<IntegralNoBoolChar T>
template<IntegralNoBoolChar T> requires (!std::is_reference_v<T>)
QString formatNumber(const T integer, QChar groupSeparator = Constants::SQUOTE)
{
constexpr static QString::size_type groupWidth = 3;
Expand Down Expand Up @@ -147,6 +147,7 @@ namespace Private

/*! Determine whether the given value is in the T type range (min/max). */
template<IntegralNoBoolChar T, IntegralNoBoolChar V>
requires (!std::is_reference_v<T> && !std::is_reference_v<V>)
bool InRange(const V value) noexcept
{
/* This method must mirror or follow steps in Usual arithmetic conversions -
Expand Down Expand Up @@ -210,6 +211,7 @@ namespace Private

/*! Cast the given integral value to the T type with range checks, throw if failed. */
template<Private::IntegralNoBoolChar T, Private::IntegralNoBoolChar V>
requires (!std::is_reference_v<T> && !std::is_reference_v<V>)
auto IntegralCast(const V value)
{
if (Private::InRange<T>(value))
Expand Down

0 comments on commit 67875ff

Please sign in to comment.