diff --git a/db_accessors.h b/db_accessors.h index 166b3db..393d695 100644 --- a/db_accessors.h +++ b/db_accessors.h @@ -53,10 +53,10 @@ namespace ro { return retval; } } - else if constexpr (std::is_same< T, std::span>::value) { + else if constexpr (std::is_same_v, std::span>) { return (*this)->Isqlite3_column_blob(i); } - else if constexpr (std::is_same< T, const char*>::value) { + else if constexpr (std::is_same_v, const char*>) { auto sz{ (*this)->Isqlite3_column_text(i) }; // if (!IsValidUtf8String(sz)) throw NonUtf8DataInDatabase(); return sz; @@ -83,10 +83,10 @@ namespace ro { j = (*this)->Isqlite3_column_int(i); } } - else if constexpr (std::is_same< T, std::span>::value) { + else if constexpr (std::is_same_v, std::span>) { j = (*this)->Isqlite3_column_blob(i); } - else if constexpr (std::is_same< T, const char*>::value) { + else if constexpr (std::is_same_v, const char*>) { j = (*this)->Isqlite3_column_text(i); } else { diff --git a/introspection_of_standard_C_types.h b/introspection_of_standard_C_types.h index 75f6bcf..47d9ba7 100644 --- a/introspection_of_standard_C_types.h +++ b/introspection_of_standard_C_types.h @@ -14,27 +14,30 @@ namespace ro { template constexpr bool is_standard_unsigned_integer = - _Is_any_of_v::type, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long>; + _Is_any_of_v, unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long>; template constexpr bool is_standard_signed_integer = - _Is_any_of_v::type, signed char, signed short, signed int, signed long, signed long long>; + _Is_any_of_v, signed char, signed short, signed int, signed long, signed long long>; // A compile time test to see if desired casts work, and make sure that // undesired casts do not work - template struct has_constructor { + template struct is_constructible_from { template static constexpr decltype(T(std::declval()), bool()) test() { return true; } template static constexpr bool test(int = 0) { return false; } - static constexpr bool value = has_constructor::template test(); + static constexpr bool value = is_constructible_from::template test(); }; + template + inline constexpr bool is_constructible_from_v = is_constructible_from::value; + template inline constexpr bool is_constructible_from_any_of = //true if T is constructible from any of the listed types - std::disjunction...>::value; + std::disjunction...>::value; template struct _Junction { // handle false trait or last trait @@ -56,7 +59,11 @@ namespace ro { template inline constexpr bool is_constructible_from_all_of = //true if T is constructible from any of the listed types - junction...>::value; + junction...>::value; + + template + inline constexpr bool is_same = std::is_same_v, std::remove_cvref_t>; + } /*spaceship operator for any pair of types that take an index @@ -88,7 +95,7 @@ decltype(std::declval()[0] <=> std::declval()[0]) operator <=> ( if (std::is_eq(retval)) { if (slh.size() > srh.size()) { assert(prh == srh.end() && plh < slh.end()); - if constexpr (std::is_arithmetic()[0])>::type>::value) { + if constexpr (std::is_arithmetic()[0])> >::value) { while ( plh < slh.end() && std::is_eq(retval = plh[0] <=> 0) @@ -102,7 +109,7 @@ decltype(std::declval()[0] <=> std::declval()[0]) operator <=> ( } if (slh.size() < srh.size()) { assert(plh == slh.end() && prh < srh.end()); - if constexpr (std::is_arithmetic()[0])>::type>::value) { + if constexpr (std::is_arithmetic()[0])> >::value) { while ( prh < srh.end() && std::is_eq(retval = prh[0] <=> 0) diff --git a/libsodium b/libsodium index d30251f..32cba2b 160000 --- a/libsodium +++ b/libsodium @@ -1 +1 @@ -Subproject commit d30251f03e646abd07b5399654f1f5dcea9a6b38 +Subproject commit 32cba2b5e90c2b98b61e8cc4c8105c0a27725fb0 diff --git a/mpir_and_base58.h b/mpir_and_base58.h index f902693..a996f68 100644 --- a/mpir_and_base58.h +++ b/mpir_and_base58.h @@ -74,7 +74,7 @@ namespace ro { void map_base_to_mpir58(const char*, char*, size_t); template class base58 : public CompileSizedString< - ((sizeof(T) * 8 + 4) * 4943ui64 + 28955ui64) / 28956ui64 - (std::is_same_v ? 1 : 0)> { + ((sizeof(T) * 8 + 4) * 4943ui64 + 28955ui64) / 28956ui64 - (std::is_same_v, scalar> ? 1 : 0)> { public: // The rational number 4943 / 28956 is minisculy larger than log(2)/log(58) // hence rounding up the nearest integer guarantees it will always be big enough. @@ -108,7 +108,7 @@ namespace ro { if (thl == nullptr)thl = new thread_local__(); mpz_ui_pow_ui(thl->n, 58, base58::length); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v, scalar>) { mpz_fdiv_q(thl->q, thl->n, mpir::ristretto25519_curve_order); } else { @@ -130,7 +130,7 @@ namespace ro { map_base_to_mpir58(p, ps, strsc.length); if (p[base58::length] > ' ')throw OversizeBase58String(); if (mpz_set_str(thl->n, ps, 58))throw BadStringRepresentationOfCryptoIdException(); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v, scalar>) { mpz_fdiv_qr(thl->q, thl->r, thl->n, mpir::ristretto25519_curve_order); } else { @@ -153,7 +153,7 @@ namespace ro { ) { mpir_ui ck{ (static_cast(fasthash(sc)) * static_cast(check_range_m)) >> 32 }; mpz_import(thl->n, sizeof(sc.blob), -1, 1, -1, 0, &sc.blob[0]); - if constexpr (std::is_same_v) { + if constexpr (std::is_same_v, scalar>) { mpz_addmul_ui(thl->n, mpir::ristretto25519_curve_order, ck); } else { diff --git a/ristretto255.h b/ristretto255.h index 85f856a..e9cb218 100644 --- a/ristretto255.h +++ b/ristretto255.h @@ -750,14 +750,14 @@ namespace ristretto255 { static_assert(ro::is_serializable::value); static_assert(ro::is_serializable::value); static_assert(ro::is_serializable::value == false); //false because uint8_t * has no inband terminator - static_assert(false == ro::is_serializable::value && !ro::has_constructor, wxString>::value, "wxStrings are apt to convert anything to anything, with surprising and unexpected results"); + static_assert(false == ro::is_serializable::value && !ro::is_constructible_from_v, wxString>, "wxStrings are apt to convert anything to anything, with surprising and unexpected results"); static_assert(ro::is_serializable().ToUTF8())>::value == true); static_assert(ro::is_constructible_from_all_of, std::array>); static_assert(ro::is_constructible_from_all_of, char*, short, unsigned short, hash<512>, point, scalar>, "want to be able to hash anything serializable"); static_assert(false == ro::is_constructible_from_any_of, hash<256>>); static_assert(false == ro::is_constructible_from_any_of , byte*>, "do not want indiscriminate casts"); static_assert(false == ro::is_constructible_from_any_of , byte*>, "do not want indiscriminate casts "); - static_assert(false == ro::has_constructor, float>::value); + static_assert(false == ro::is_constructible_from_v, float>); static_assert(ro::is_serializable::value == false);//Need to convert floats to // their machine independent representation, possibly through idexp, frexp // and DBL_MANT_DIG diff --git a/slash6.cpp b/slash6.cpp index 41f5e5a..86702d4 100644 --- a/slash6.cpp +++ b/slash6.cpp @@ -5,7 +5,7 @@ #include //#include // for initializer_list //#include -#include // for shared_ptr, unique_ptr +//#include // for shared_ptr, unique_ptr #include #include "ILog.h" #include "localization.h" diff --git a/slash6.h b/slash6.h index e543879..f9ea648 100644 --- a/slash6.h +++ b/slash6.h @@ -1,5 +1,4 @@ #pragma once - // Converts a bit buffer, arbitrarily positioned with respect to byte boundaries, into a base sixty four numeral. // In release mode, returns without doing anything if the output string buffer is too small. // In debug mode, halts execution with an assert. Should throw, need to put in and unit test. @@ -25,7 +24,7 @@ uint8_t base64_to_bytes(uint8_t* byteBuffer, uint_fast32_t byteCount, const char Returns a uint8_t containing the excess bits of the last numeral in its low order part.*/ template < typename T> std::enable_if_t< - sizeof(std::size(std::declval())) >= sizeof(int) && + !std::is_pointer::value && sizeof(std::declval()[0]) == 1, uint8_t >base64_to_bytes( T& byteRange, const char* base64Numerals) {