Cajoled visual studio into issuing intelligent error messages

when an unserializable type is in the parameter pack.
This commit is contained in:
Cheng 2023-10-02 01:49:03 +00:00
parent dbe030ba21
commit 7ba674c29a
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
2 changed files with 6 additions and 1 deletions

View File

@ -195,10 +195,12 @@ 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) {
// not restraining the variant args by concept, because they get caught deeper in,
// and visual studio reporting of variant concept errors sucks.
hsh<hashsize> in; hsh<hashsize> in;
in << first; in << first;
if constexpr (sizeof...(args) > 0) { if constexpr (sizeof...(args) > 0) {
in.hashinto( args...); in.hashinto( ro::trigger_error(args)...);
} }
int i = crypto_generichash_blake2b_final( int i = crypto_generichash_blake2b_final(
&in.st, &in.st,

View File

@ -317,6 +317,9 @@
template<typename... Args> template<typename... Args>
concept has_machine_independent_representation = serializable<Args...>(); concept has_machine_independent_representation = serializable<Args...>();
template<has_machine_independent_representation T>
T trigger_error(T x) { return x; };
static_assert( !has_machine_independent_representation<double> static_assert( !has_machine_independent_representation<double>
&& has_machine_independent_representation<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");