Went all in on concepts because of nicer error messages

But did not apply the concept to the parameter pack,
event though I applied no end of cleverness to generate
a variant concept, because
visual studio gives meaningless error messages when applying
a variant concept to a parameter pack.

This will probably improve in later or different compilers,
but right now, this feature does not work
This commit is contained in:
Cheng 2023-09-30 20:11:14 +00:00
parent bc3f2c9daf
commit dbe030ba21
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
3 changed files with 14 additions and 14 deletions

View File

@ -58,7 +58,7 @@ void randombytes_buf(std::span<char > in);
namespace ristretto255 { namespace ristretto255 {
using using
ro::to_base64_string, ro::is_serializable, ro::to_base64_string,
ro::serialize, ro::bin2hex, ro::hex2bin, ro::serialize, ro::bin2hex, ro::hex2bin,
ro::bin2hex, ro::CompileSizedString, ro::bin2hex, ro::CompileSizedString,
ro::has_machine_independent_representation; ro::has_machine_independent_representation;
@ -195,7 +195,6 @@ namespace ristretto255 {
if (i) throw HashReuseException(); if (i) throw HashReuseException();
} }
template< has_machine_independent_representation T, typename... Args>explicit hash(const T& first, Args... args) { template< has_machine_independent_representation T, typename... Args>explicit hash(const T& first, Args... args) {
hsh<hashsize> in; hsh<hashsize> in;
in << first; in << first;
if constexpr (sizeof...(args) > 0) { if constexpr (sizeof...(args) > 0) {

View File

@ -118,7 +118,8 @@
inline auto serialize(const decltype(std::declval<wxString>().ToUTF8()) sz){ inline auto serialize(const decltype(std::declval<wxString>().ToUTF8()) sz){
return serialize(static_cast<const char*>(sz)); return serialize(static_cast<const char*>(sz));
} }
/* /* Don't do this. Disaster ensues,
inline auto serialize(const wxString& wxstr) { inline auto serialize(const wxString& wxstr) {
return serialize(static_cast<const char*>(wxstr.ToUTF8())); return serialize(static_cast<const char*>(wxstr.ToUTF8()));
} }
@ -303,21 +304,21 @@
format being 44 digits in a base 58 representation.*/ format being 44 digits in a base 58 representation.*/
// a compile time test to check if an object class has a machine independent representation // a compile time test to check if an object class has a machine independent representation
template<typename T> concept has_machine_independent_representation = requires (T a) { template <typename T, typename... Args> static constexpr bool serializable() {
serialize(a); if constexpr (requires(T a) {
}; serialize(a);
}) {
template <typename T, typename... Args> static constexpr bool is_serializable() { if constexpr (sizeof...(Args) > 0) return serializable<Args...>();
if constexpr (!has_machine_independent_representation<T>) return false; else return true;
else if constexpr (sizeof...(Args) > 0) return is_serializable<Args...>(); }
else return true; else return false;
}; };
template<typename... Args> template<typename... Args>
concept allserializable = is_serializable<Args...>(); concept has_machine_independent_representation = serializable<Args...>();
static_assert( !has_machine_independent_representation<double> static_assert( !has_machine_independent_representation<double>
&& allserializable<std::span<const byte>, char*, std::span<const char>>, && has_machine_independent_representation<std::span<const byte>, char*, std::span<const char>>,
"concepts needed"); "concepts needed");
template<class T> ro::CompileSizedString< (2 * sizeof(T))>bin2hex(const T& pt) { template<class T> ro::CompileSizedString< (2 * sizeof(T))>bin2hex(const T& pt) {

View File

@ -238,7 +238,7 @@ static bool checkDataConversionsProduceExpected(void){
point pt_a{ scl_a.timesBase() }; point pt_a{ scl_a.timesBase() };
std::string str_pt_a = &(base58(pt_a))[0]; std::string str_pt_a = &(base58(pt_a))[0];
assert(base58<point>::bin(str_pt_a.c_str()) == pt_a); assert(base58<point>::bin(str_pt_a.c_str()) == pt_a);
hash<256> hash_b{ hash_a, str_hash_a, scl_a, str_sclr_a, pt_a, str_pt_a, 33, 66ull }; hash<256> hash_b( hash_a, str_hash_a, scl_a, str_sclr_a, pt_a, wxString(str_pt_a).ToUTF8(), 33, 66ull);
auto str_b = base58(hash_b).operator std::string(); auto str_b = base58(hash_b).operator std::string();
if (str_b != "7cTScjKyUtmbvc28BV3ok51szgrQmaBa2YE5HPBcukC9e" if (str_b != "7cTScjKyUtmbvc28BV3ok51szgrQmaBa2YE5HPBcukC9e"
) { ) {