@@ -273,8 +273,8 @@ template<typename Stream> inline void Serialize(Stream& s, int64_t a ) { ser_wri
273
273
template <typename Stream> inline void Serialize (Stream& s, uint64_t a) { ser_writedata64 (s, a); }
274
274
template <typename Stream, int N> inline void Serialize (Stream& s, const char (&a)[N]) { s.write (MakeByteSpan (a)); }
275
275
template <typename Stream, int N> inline void Serialize (Stream& s, const unsigned char (&a)[N]) { s.write (MakeByteSpan (a)); }
276
- template <typename Stream, typename B, std::size_t N> void Serialize (Stream& s, const std::array<B, N>& a) { ( void ) /* force byte-type */ UCharCast (a. data ()); s.write (MakeByteSpan (a)); }
277
- template <typename Stream, typename B> void Serialize (Stream& s, Span<B> span) { ( void ) /* force byte-type */ UCharCast (span. data ()); s.write (AsBytes (span)); }
276
+ template <typename Stream, BasicByte B, std::size_t N> void Serialize (Stream& s, const std::array<B, N>& a) { s.write (MakeByteSpan (a)); }
277
+ template <typename Stream, BasicByte B> void Serialize (Stream& s, Span<B> span) { s.write (AsBytes (span)); }
278
278
279
279
#ifndef CHAR_EQUALS_INT8
280
280
template <typename Stream> void Unserialize (Stream&, char ) = delete; // char serialization forbidden. Use uint8_t or int8_t
@@ -290,8 +290,8 @@ template<typename Stream> inline void Unserialize(Stream& s, int64_t& a ) { a =
290
290
template <typename Stream> inline void Unserialize (Stream& s, uint64_t & a) { a = ser_readdata64 (s); }
291
291
template <typename Stream, int N> inline void Unserialize (Stream& s, char (&a)[N]) { s.read (MakeWritableByteSpan (a)); }
292
292
template <typename Stream, int N> inline void Unserialize (Stream& s, unsigned char (&a)[N]) { s.read (MakeWritableByteSpan (a)); }
293
- template <typename Stream, typename B, std::size_t N> void Unserialize (Stream& s, std::array<B, N>& a) { ( void ) /* force byte-type */ UCharCast (a. data ()); s.read (MakeWritableByteSpan (a)); }
294
- template <typename Stream, typename B> void Unserialize (Stream& s, Span<B> span) { ( void ) /* force byte-type */ UCharCast (span. data ()); s.read (AsWritableBytes (span)); }
293
+ template <typename Stream, BasicByte B, std::size_t N> void Unserialize (Stream& s, std::array<B, N>& a) { s.read (MakeWritableByteSpan (a)); }
294
+ template <typename Stream, BasicByte B> void Unserialize (Stream& s, Span<B> span) { s.read (AsWritableBytes (span)); }
295
295
296
296
template <typename Stream> inline void Serialize (Stream& s, bool a) { uint8_t f = a; ser_writedata8 (s, f); }
297
297
template <typename Stream> inline void Unserialize (Stream& s, bool & a) { uint8_t f = ser_readdata8 (s); a = f; }
@@ -755,18 +755,23 @@ template<typename Stream, typename T> void Serialize(Stream& os, const std::uniq
755
755
template <typename Stream, typename T> void Unserialize (Stream& os, std::unique_ptr<const T>& p);
756
756
757
757
758
-
759
758
/* *
760
759
* If none of the specialized versions above matched, default to calling member function.
761
760
*/
762
- template <typename Stream, typename T>
763
- inline void Serialize (Stream& os, const T& a)
761
+ template <class T , class Stream >
762
+ concept Serializable = requires(T a, Stream s) { a.Serialize (s); };
763
+ template <typename Stream, typename T>
764
+ requires Serializable<T, Stream>
765
+ void Serialize (Stream& os, const T& a)
764
766
{
765
767
a.Serialize (os);
766
768
}
767
769
768
- template <typename Stream, typename T>
769
- inline void Unserialize (Stream& is, T&& a)
770
+ template <class T , class Stream >
771
+ concept Unserializable = requires(T a, Stream s) { a.Unserialize (s); };
772
+ template <typename Stream, typename T>
773
+ requires Unserializable<T, Stream>
774
+ void Unserialize (Stream& is, T&& a)
770
775
{
771
776
a.Unserialize (is);
772
777
}
0 commit comments