forked from cheng/wallet
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>>
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -654,12 +654,13 @@ 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(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(std::enable_if_t < ro::is_standard_unsigned_integer<T>, T> i) :scalar(uintmax_t(i)) {}
|
||||
template <class T, class U = std::enable_if_t<ro::is_standard_signed_integer<T>, uintmax_t>>
|
||||
explicit constexpr scalar(T i) : scalar(U(ro::iabs<T>(i))) {
|
||||
if constexpr (ro::is_standard_signed_integer<T>) {
|
||||
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(const scalar&) = default; // Copy constructor
|
||||
scalar& operator=(scalar&&) = default; // Move assignment.
|
||||
|
Loading…
Reference in New Issue
Block a user