Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
danakj committed Aug 14, 2023
1 parent 0e8e611 commit 2b9b786
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 287 deletions.
238 changes: 188 additions & 50 deletions sus/num/__private/signed_integer_methods.inc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ sus_pure constexpr inline _self operator~() const& noexcept {
/// excluded as they require an explicit conversion to a `@doc.self`.
///
/// #[doc.overloads=signedint.+]
[[nodiscard]] sus_pure friend constexpr inline _self operator+(
[[nodiscard]] sus_pure_const friend constexpr inline _self operator+(
_self l, _self r) noexcept {
const auto out =
__private::add_with_overflow(l.primitive_value, r.primitive_value);
Expand All @@ -534,13 +534,29 @@ sus_pure constexpr inline _self operator~() const& noexcept {
return out.value;
}
/// #[doc.overloads=signedint.+]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator+(_self l,
U r) noexcept {
return l + _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator+(
_self l, U r) noexcept {
return l + _self(r);
}
/// #[doc.overloads=signedint.+]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator+(
U l, _self r) noexcept {
return _self(l) + r;
}
/// #[doc.overloads=signedint.+]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator+(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.+]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator+(U l, _self r) noexcept = delete;
/// sus::num::Sub<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
Expand All @@ -557,13 +573,29 @@ template <class U>
return out.value;
}
/// #[doc.overloads=signedint.-]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator-(_self l,
U r) noexcept {
return l - _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator-(
_self l, U r) noexcept {
return l - _self(r);
}
/// #[doc.overloads=signedint.-]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator-(
U l, _self r) noexcept {
return _self(l) - r;
}
/// #[doc.overloads=signedint.-]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator-(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.-]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator-(U l, _self r) noexcept = delete;
/// sus::num::Mul<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
Expand All @@ -580,13 +612,29 @@ template <class U>
return out.value;
}
/// #[doc.overloads=signedint.*]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator*(_self l,
U r) noexcept {
return l * _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator*(
_self l, U r) noexcept {
return l * _self(r);
}
/// #[doc.overloads=signedint.*]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator*(
U l, _self r) noexcept {
return _self(l) * r;
}
/// #[doc.overloads=signedint.*]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator*(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.*]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator*(U l, _self r) noexcept = delete;
/// sus::num::Div<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
Expand All @@ -603,14 +651,30 @@ template <class U>
return static_cast<_primitive>(l.primitive_value / r.primitive_value);
}
/// #[doc.overloads=signedint./]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator/(_self l,
U r) noexcept {
return l / _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator/(
_self l, U r) noexcept {
return l / _self(r);
}
/// #[doc.overloads=signedint./]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator/(
U l, _self r) noexcept {
return _self(l) / r;
}
/// sus::num::Rem<T> trait for signed integers.
/// #[doc.overloads=signedint./]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator/(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint./]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator/(U l, _self r) noexcept =
delete; /// sus::num::Rem<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
/// that convert to `@doc.self`, as well as enums. However enum class is
Expand All @@ -626,13 +690,29 @@ template <class U>
return static_cast<_primitive>(l.primitive_value % r.primitive_value);
}
/// #[doc.overloads=signedint.%]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator%(_self l,
U r) noexcept {
return l % _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator%(
_self l, U r) noexcept {
return l % _self(r);
}
/// #[doc.overloads=signedint.%]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator%(
U l, _self r) noexcept {
return _self(l) % r;
}
/// #[doc.overloads=signedint.%]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator%(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.%]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator%(U l, _self r) noexcept = delete;

/// sus::num::BitAnd<T> trait for signed integers.
///
Expand All @@ -646,13 +726,29 @@ template <class U>
return static_cast<_primitive>(l.primitive_value & r.primitive_value);
}
/// #[doc.overloads=signedint.&]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator&(_self l,
U r) noexcept {
return l & _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator&(
_self l, U r) noexcept {
return l & _self(r);
}
/// #[doc.overloads=signedint.&]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator&(
U l, _self r) noexcept {
return _self(l) & r;
}
/// #[doc.overloads=signedint.&]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator&(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.&]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator&(U l, _self r) noexcept = delete;
/// sus::num::BitOr<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
Expand All @@ -665,13 +761,29 @@ template <class U>
return static_cast<_primitive>(l.primitive_value | r.primitive_value);
}
/// #[doc.overloads=signedint.|]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator|(_self l,
U r) noexcept {
return l | _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator|(
_self l, U r) noexcept {
return l | _self(r);
}
/// #[doc.overloads=signedint.|]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator|(
U l, _self r) noexcept {
return _self(l) | r;
}
/// #[doc.overloads=signedint.|]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator|(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.|]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator|(U l, _self r) noexcept = delete;
/// sus::num::BitXor<T> trait for signed integers.
///
/// This operation supports working with primitive signed or unsigned integers
Expand All @@ -684,13 +796,29 @@ template <class U>
return static_cast<_primitive>(l.primitive_value ^ r.primitive_value);
}
/// #[doc.overloads=signedint.^]
template <class U>
requires(::sus::construct::From<_self, U> && //
(PrimitiveInteger<U> || PrimitiveEnum<U>))
[[nodiscard]] sus_pure friend constexpr inline _self operator^(_self l,
U r) noexcept {
return l ^ _self::from(r);
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator^(
_self l, U r) noexcept {
return l ^ _self(r);
}
/// #[doc.overloads=signedint.^]
template <std::convertible_to<_self> U>
requires(PrimitiveInteger<U> || PrimitiveEnum<U>)
[[nodiscard]] sus_pure_const friend constexpr inline _self operator^(
U l, _self r) noexcept {
return _self(l) ^ r;
}
/// #[doc.overloads=signedint.^]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator^(_self l, U r) noexcept = delete;
/// #[doc.overloads=signedint.^]
template <class U>
requires((PrimitiveInteger<U> || PrimitiveEnum<U>) &&
!std::convertible_to<U, _self>)
friend constexpr inline _self operator^(U l, _self r) noexcept = delete;
/// sus::num::Shl<T> trait for signed integers.
///
/// This operation supports shifting with primitive signed or unsigned integers
Expand All @@ -708,6 +836,11 @@ template <class U>
::sus::check(!out.overflow);
return out.value;
}
/// #[doc.overloads=signedint.<<]
template <class U>
requires(!std::convertible_to<U, u32>)
[[nodiscard]] sus_pure friend constexpr inline _self operator<<(
_self l, U r) noexcept = delete;
/// sus::num::Shr<T> trait for signed integers.
///
/// #[doc.overloads=signedint.>>]
Expand All @@ -719,6 +852,11 @@ template <class U>
::sus::check(!out.overflow);
return out.value;
}
/// #[doc.overloads=signedint.>>]
template <class U>
requires(!std::convertible_to<U, u32>)
[[nodiscard]] sus_pure friend constexpr inline _self operator>>(
_self l, U r) noexcept = delete;

/// sus::num::AddAssign<@doc.self> trait.
constexpr inline void operator+=(_self r) & noexcept {
Expand Down
Loading

0 comments on commit 2b9b786

Please sign in to comment.