diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 0d86df83..bddd2533 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -94,6 +94,17 @@ namespace ngcore template constexpr bool is_archivable = detail::is_Archivable_struct::value; + + template + constexpr size_t TotSize () + { + if constexpr (sizeof...(Trest) == 0) + return sizeof(T); + else + return sizeof(T) + TotSize (); + } + + // Base Archive class class NGCORE_API Archive { @@ -308,22 +319,25 @@ namespace ngcore val.DoArchive(*this); return *this; } + + + // pack elements to binary template Archive & DoPacked (Types & ... args) { if (true) // (isbinary) { + constexpr size_t totsize = TotSize(); // (args...); + std::byte mem[totsize]; if (is_output) { - std::byte mem[TotSize(args...)]; CopyToBin (&mem[0], args...); - Do(&mem[0], sizeof(mem)); + Do(&mem[0], totsize); } else { - std::byte mem[TotSize(args...)]; - Do(&mem[0], sizeof(mem)); + Do(&mem[0], totsize); CopyFromBin (&mem[0], args...); } } @@ -332,13 +346,6 @@ namespace ngcore return *this; } - template - static constexpr size_t TotSize (T & first, Trest & ...rest) - { - return sizeof(first) + TotSize(rest...); - } - static constexpr size_t TotSize () { return 0; } - template constexpr void CopyToBin (std::byte * ptr, T & first, Trest & ...rest) const