From 883bd8ebe8a0e6660a65985074040b1e96052a3e Mon Sep 17 00:00:00 2001 From: Cheng Date: Sun, 24 Sep 2023 20:04:19 +1000 Subject: [PATCH] std::format seems like a great idea. Used it in one place. Better than printf derived functionality. But they never bothered to think through supporting user types, and that is a complete mess that is grossly inconsistent or simply not working from one compiler to the next. --- src/ILog.cpp | 5 ++--- src/db_accessors.h | 2 +- src/mpir_and_base58.h | 3 ++- src/ristretto255.h | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ILog.cpp b/src/ILog.cpp index f02728e..6ef3132 100644 --- a/src/ILog.cpp +++ b/src/ILog.cpp @@ -46,7 +46,6 @@ MyException::MyException(const char* sz, int i, const char* func__, const char* // usage // throw MyException("Expected wallet file not found", __LINE__, __func__, __FILE__); err_number(i) { - char buff[20]; - snprintf(buff, 20, "%d", i); - err = std::string(sz) + "\nline " + buff + ", function " + func__ + ", file " + FILE__; + err = std::format(R"|({} +line {}, function {}, file {})|", sz, i, func__, FILE__); } diff --git a/src/db_accessors.h b/src/db_accessors.h index 531176e..500c86f 100644 --- a/src/db_accessors.h +++ b/src/db_accessors.h @@ -36,7 +36,7 @@ namespace ro { sql(std::unique_ptr&& p) :std::unique_ptr(p.release()) { } ~sql() = default; template auto column(int i) const { - if constexpr (ro::is_blob_field_type::value) { + if constexpr (ro::blob_type) { auto st = (*this)->Isqlite3_column_blob(i); if (st.size_bytes() != sizeof(T)) throw BadDataException(); static_assert (std::is_standard_layout(), "not standard layout"); diff --git a/src/mpir_and_base58.h b/src/mpir_and_base58.h index f18a230..13f2389 100644 --- a/src/mpir_and_base58.h +++ b/src/mpir_and_base58.h @@ -57,7 +57,7 @@ namespace ro { bool is_alphanumeric_fixed_length(unsigned int, const char*); template typename std::enable_if< - ro::is_blob_field_type::value, + ro::blob_type, decltype(T::type_indentifier, uint32_t()) >::type fasthash(const T& p_blob) { static_assert(sizeof(T) % 8 == 0, "fasthash assumes a multiple of 8 bytes"); @@ -181,3 +181,4 @@ namespace ro { this->operator char* [this->length] = '\0'; } } + diff --git a/src/ristretto255.h b/src/ristretto255.h index 883902b..a868115 100644 --- a/src/ristretto255.h +++ b/src/ristretto255.h @@ -138,17 +138,16 @@ namespace ro { static constexpr bool value = is_blob_field_type::template test(); }; + template concept blob_type = ro::is_blob_field_type::value; + + // At present our serial classes consist of std::span and custom classes that publicly inherit from std::span // To handle compound objects, add custom classes inheriting from std::span[n] // template class that generates a std::span of bytes over the blob // field of any object containing a blob record, which is normally sufficient // for a machine independent representation of that object - template - std::enable_if_t< - is_blob_field_type::value, - std::span - > serialize(const T& pt) { + template std::span serialize(const T& pt) { return serialize(pt.blob); } @@ -567,7 +566,7 @@ namespace ristretto255 { { // We will be reading points from the database, as blobs, // reading them from the network as blobs, - // and reading them from human entered text as base52 encoded blobs. + // and reading them from human entered text as base58 encoded blobs. // Therefore, invalid point initialization data is all too possible. public: static constexpr unsigned int type_indentifier = 1; @@ -770,6 +769,7 @@ namespace ristretto255 { } }; + static_assert(ro::blob_type && !ro::blob_type); static_assert(ro::is_blob_field_type::value); static_assert(ro::is_blob_field_type::value); static_assert(ro::is_blob_field_type::value);