From dbe030ba211486b3c144bdb12fe57e10377e5d0b Mon Sep 17 00:00:00 2001 From: Cheng Date: Sat, 30 Sep 2023 20:11:14 +0000 Subject: [PATCH] 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 --- src/ristretto255.h | 3 +-- src/serialization.h | 23 ++++++++++++----------- src/unit_test.cpp | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ristretto255.h b/src/ristretto255.h index 7faf593..91b0e30 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -58,7 +58,7 @@ void randombytes_buf(std::span in); namespace ristretto255 { using - ro::to_base64_string, ro::is_serializable, + ro::to_base64_string, ro::serialize, ro::bin2hex, ro::hex2bin, ro::bin2hex, ro::CompileSizedString, ro::has_machine_independent_representation; @@ -195,7 +195,6 @@ namespace ristretto255 { if (i) throw HashReuseException(); } template< has_machine_independent_representation T, typename... Args>explicit hash(const T& first, Args... args) { - hsh in; in << first; if constexpr (sizeof...(args) > 0) { diff --git a/src/serialization.h b/src/serialization.h index 0fcae03..7c4c997 100644 --- a/src/serialization.h +++ b/src/serialization.h @@ -118,7 +118,8 @@ inline auto serialize(const decltype(std::declval().ToUTF8()) sz){ return serialize(static_cast(sz)); } - /* + /* Don't do this. Disaster ensues, + inline auto serialize(const wxString& wxstr) { return serialize(static_cast(wxstr.ToUTF8())); } @@ -303,21 +304,21 @@ format being 44 digits in a base 58 representation.*/ // a compile time test to check if an object class has a machine independent representation - template concept has_machine_independent_representation = requires (T a) { - serialize(a); - }; - - template static constexpr bool is_serializable() { - if constexpr (!has_machine_independent_representation) return false; - else if constexpr (sizeof...(Args) > 0) return is_serializable(); - else return true; + template static constexpr bool serializable() { + if constexpr (requires(T a) { + serialize(a); + }) { + if constexpr (sizeof...(Args) > 0) return serializable(); + else return true; + } + else return false; }; template - concept allserializable = is_serializable(); + concept has_machine_independent_representation = serializable(); static_assert( !has_machine_independent_representation - && allserializable, char*, std::span>, + && has_machine_independent_representation, char*, std::span>, "concepts needed"); template ro::CompileSizedString< (2 * sizeof(T))>bin2hex(const T& pt) { diff --git a/src/unit_test.cpp b/src/unit_test.cpp index 62ea8f5..85750b2 100644 --- a/src/unit_test.cpp +++ b/src/unit_test.cpp @@ -238,7 +238,7 @@ static bool checkDataConversionsProduceExpected(void){ point pt_a{ scl_a.timesBase() }; std::string str_pt_a = &(base58(pt_a))[0]; assert(base58::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(); if (str_b != "7cTScjKyUtmbvc28BV3ok51szgrQmaBa2YE5HPBcukC9e" ) {