still playing around with the mysterious, complicated, and unpredictable effects of std::enable_if_t

This commit is contained in:
Cheng 2022-04-02 13:38:06 +11:00
parent b5bc0d40a9
commit b26721213d
No known key found for this signature in database
GPG Key ID: D51301E176B31828
2 changed files with 12 additions and 6 deletions

View File

@ -25,7 +25,12 @@ namespace ro {
template <class T, class U = std::enable_if_t<is_standard_integer<T>,std::make_unsigned<std::remove_cvref_t<T>>::type>> template <class T, class U = std::enable_if_t<is_standard_integer<T>,std::make_unsigned<std::remove_cvref_t<T>>::type>>
constexpr U iabs(T i) { constexpr U iabs(T i) {
if constexpr (is_standard_signed_integer<T>)return U(abs(i)); if constexpr (is_standard_signed_integer<T>) {
U j;
if (i < 0)j = -i;
else j = i;
return j;
}
else return i; else return i;
} }

View File

@ -654,11 +654,12 @@ namespace ristretto255 {
explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>&& in) : blob{ in } {}; explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>&& in) : blob{ in } {};
explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>* in) :blob(*in) {}; explicit constexpr scalar(std::array<uint8_t, crypto_core_ristretto255_BYTES>* in) :blob(*in) {};
explicit constexpr scalar(uintmax_t k){ for (auto& j : blob) { j = k; k = k >> 8; } } explicit constexpr scalar(uintmax_t k){ for (auto& j : blob) { j = k; k = k >> 8; } }
template <class T, class U = std::enable_if_t<ro::is_standard_integer<T>, uintmax_t>> template <class T>
explicit constexpr scalar(T i) :scalar(U(ro::iabs<T>(i))) { explicit constexpr scalar(std::enable_if_t < ro::is_standard_unsigned_integer<T>, T> i) :scalar(uintmax_t(i)) {}
if constexpr (ro::is_standard_signed_integer<T>) { template <class T, class U = std::enable_if_t<ro::is_standard_signed_integer<T>, uintmax_t>>
if (i < 0) crypto_core_ristretto255_scalar_negate(&blob[0], &blob[0]); explicit constexpr scalar(T i) : scalar(U(ro::iabs<T>(i))) {
} static_assert (ro::is_standard_signed_integer<T>);
if (i < 0) crypto_core_ristretto255_scalar_negate(&blob[0], &blob[0]);
} }
scalar(scalar&&) = default; // Move constructor scalar(scalar&&) = default; // Move constructor
scalar(const scalar&) = default; // Copy constructor scalar(const scalar&) = default; // Copy constructor