still playing around with the mysterious, complicated, and unpredictable effects of std::enable_if_t
This commit is contained in:
parent
b5bc0d40a9
commit
b26721213d
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user