Skip to content

Commit 42b56d7

Browse files
committed
Avoid some explicit template parameters
1 parent 3eb2da7 commit 42b56d7

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

common/altypes.hpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -619,43 +619,43 @@ DECL_BINARY(^)
619619
* operand type doesn't influence the return type, as this is only modifying
620620
* the left-side operand value (e.g. 1_u8 << 1_u32 == 2_u8).
621621
*/
622-
template<al::strong_number T, al::strong_number U> [[nodiscard]] force_inline
623-
constexpr auto operator>>(T const &lhs, U const &rhs) noexcept -> T
622+
template<al::strong_number T> [[nodiscard]] force_inline constexpr
623+
auto operator>>(T const &lhs, al::strong_number auto const &rhs) noexcept -> T
624624
{ return T{static_cast<typename T::value_t>(lhs.c_val >> rhs.c_val)}; }
625625

626-
template<al::strong_number T, al::strong_number U> [[nodiscard]] force_inline
627-
constexpr auto operator<<(T const &lhs, U const &rhs) noexcept -> T
626+
template<al::strong_number T> [[nodiscard]] force_inline constexpr
627+
auto operator<<(T const &lhs, al::strong_number auto const &rhs) noexcept -> T
628628
{ return T{static_cast<typename T::value_t>(lhs.c_val << rhs.c_val)}; }
629629

630630
/* Binary ops >> and << between a strong number type and weak integer.
631631
* Unlike the other operations, these don't require the weak integer to be
632632
* constant because the result type is always the same as the left-side
633633
* operand.
634634
*/
635-
template<al::strong_number T, std::integral U> [[nodiscard]] force_inline
636-
constexpr auto operator>>(T const &lhs, U const &rhs) noexcept -> T
635+
template<al::strong_number T> [[nodiscard]] force_inline constexpr
636+
auto operator>>(T const &lhs, std::integral auto const &rhs) noexcept -> T
637637
{ return T{static_cast<typename T::value_t>(lhs.c_val >> rhs)}; }
638638

639-
template<al::strong_number T, std::integral U> [[nodiscard]] force_inline
640-
constexpr auto operator<<(T const &lhs, U const &rhs) noexcept -> T
639+
template<al::strong_number T> [[nodiscard]] force_inline constexpr
640+
auto operator<<(T const &lhs, std::integral auto const &rhs) noexcept -> T
641641
{ return T{static_cast<typename T::value_t>(lhs.c_val << rhs)}; }
642642

643643
/* Increment/decrement a strong unsigned integral using its signed difference
644644
* type.
645645
*/
646-
template<al::strong_unsigned_integral T, std::same_as<typename T::difference_type> U> [[nodiscard]]
647-
force_inline constexpr
648-
auto operator+(T const &lhs, U const &rhs) noexcept -> T
646+
template<al::strong_unsigned_integral T> [[nodiscard]] force_inline constexpr
647+
auto operator+(T const &lhs, std::same_as<typename T::difference_type> auto const &rhs) noexcept
648+
-> T
649649
{ return T{static_cast<typename T::value_t>(lhs.c_val + static_cast<typename T::value_t>(rhs))}; }
650650

651-
template<al::strong_unsigned_integral T, std::same_as<typename T::difference_type> U> [[nodiscard]]
652-
force_inline constexpr
653-
auto operator+(U const &lhs, T const &rhs) noexcept -> T
651+
template<al::strong_unsigned_integral T> [[nodiscard]] force_inline constexpr
652+
auto operator+(std::same_as<typename T::difference_type> auto const &lhs, T const &rhs) noexcept
653+
-> T
654654
{ return T{static_cast<typename T::value_t>(static_cast<typename T::value_t>(lhs) + rhs.c_val)}; }
655655

656-
template<al::strong_unsigned_integral T, std::same_as<typename T::difference_type> U> [[nodiscard]]
657-
force_inline constexpr
658-
auto operator-(T const &lhs, U const &rhs) noexcept -> T
656+
template<al::strong_unsigned_integral T> [[nodiscard]] force_inline constexpr
657+
auto operator-(T const &lhs, std::same_as<typename T::difference_type> auto const &rhs) noexcept
658+
-> T
659659
{ return T{static_cast<typename T::value_t>(lhs.c_val - static_cast<typename T::value_t>(rhs))}; }
660660

661661
/* Our binary assignment ops only promote the rhs value to the lhs type when
@@ -694,24 +694,27 @@ DECL_BINASSIGN(^=)
694694
* operand must fit an uint8 type.
695695
*/
696696
#define DECL_BINASSIGN(op) \
697-
template<al::strong_number T, al::strong_number U> force_inline constexpr \
698-
auto operator op(T &lhs LIFETIMEBOUND, U const &rhs) noexcept -> T& \
697+
template<al::strong_number T> force_inline constexpr \
698+
auto operator op(T &lhs LIFETIMEBOUND, \
699+
al::strong_number auto const &rhs) noexcept -> T& \
699700
{ lhs.c_val op rhs.c_val; return lhs; } \
700701
template<al::strong_number T> force_inline constexpr \
701-
auto operator op(T &lhs LIFETIMEBOUND, al::ConstantNum<std::uint8_t> const &rhs) \
702-
noexcept -> T& \
702+
auto operator op(T &lhs LIFETIMEBOUND, \
703+
al::ConstantNum<std::uint8_t> const &rhs) noexcept -> T& \
703704
{ lhs.c_val op static_cast<typename T::value_t>(rhs.c_val); return lhs; }
704705
DECL_BINASSIGN(>>=)
705706
DECL_BINASSIGN(<<=)
706707
#undef DECL_BINASSIGN
707708

708709
/* Offset a strong unsigned integral using its signed difference type. */
709-
template<al::strong_unsigned_integral T, std::same_as<typename T::difference_type> U> force_inline
710-
constexpr auto operator+=(T &lhs LIFETIMEBOUND, U const &rhs) noexcept -> T&
710+
template<al::strong_unsigned_integral T> force_inline constexpr
711+
auto operator+=(T &lhs LIFETIMEBOUND, std::same_as<typename T::difference_type> auto const &rhs)
712+
noexcept -> T&
711713
{ lhs.c_val += static_cast<typename T::value_t>(rhs); return lhs; }
712714

713-
template<al::strong_unsigned_integral T, std::same_as<typename T::difference_type> U> force_inline
714-
constexpr auto operator-=(T &lhs LIFETIMEBOUND, U const &rhs) noexcept -> T&
715+
template<al::strong_unsigned_integral T> force_inline constexpr
716+
auto operator-=(T &lhs LIFETIMEBOUND, std::same_as<typename T::difference_type> auto const &rhs)
717+
noexcept -> T&
715718
{ lhs.c_val -= static_cast<typename T::value_t>(rhs); return lhs; }
716719

717720

0 commit comments

Comments
 (0)