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:
parent
bc3f2c9daf
commit
dbe030ba21
@ -58,7 +58,7 @@ void randombytes_buf(std::span<char > 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<hashsize> in;
|
||||
in << first;
|
||||
if constexpr (sizeof...(args) > 0) {
|
||||
|
@ -118,7 +118,8 @@
|
||||
inline auto serialize(const decltype(std::declval<wxString>().ToUTF8()) sz){
|
||||
return serialize(static_cast<const char*>(sz));
|
||||
}
|
||||
/*
|
||||
/* Don't do this. Disaster ensues,
|
||||
|
||||
inline auto serialize(const wxString& wxstr) {
|
||||
return serialize(static_cast<const char*>(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<typename T> concept has_machine_independent_representation = requires (T a) {
|
||||
serialize(a);
|
||||
};
|
||||
|
||||
template <typename T, typename... Args> static constexpr bool is_serializable() {
|
||||
if constexpr (!has_machine_independent_representation<T>) return false;
|
||||
else if constexpr (sizeof...(Args) > 0) return is_serializable<Args...>();
|
||||
else return true;
|
||||
template <typename T, typename... Args> static constexpr bool serializable() {
|
||||
if constexpr (requires(T a) {
|
||||
serialize(a);
|
||||
}) {
|
||||
if constexpr (sizeof...(Args) > 0) return serializable<Args...>();
|
||||
else return true;
|
||||
}
|
||||
else return false;
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
concept allserializable = is_serializable<Args...>();
|
||||
concept has_machine_independent_representation = serializable<Args...>();
|
||||
|
||||
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");
|
||||
|
||||
template<class T> ro::CompileSizedString< (2 * sizeof(T))>bin2hex(const T& pt) {
|
||||
|
@ -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<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();
|
||||
if (str_b != "7cTScjKyUtmbvc28BV3ok51szgrQmaBa2YE5HPBcukC9e"
|
||||
) {
|
||||
|
Loading…
Reference in New Issue
Block a user