From 04a92482bf7a3374fcd0451de15add2acba8dea0 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Fri, 1 Feb 2019 02:02:22 +0000 Subject: [PATCH] ChunkFile: treat vectors/strings as sized arrays --- Source/Core/Common/ChunkFile.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index bb2764ce54..b4383d2570 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -116,7 +116,7 @@ public: template void Do(std::vector& x) { - DoContainer(x); + DoContiguousContainer(x); } template @@ -134,7 +134,7 @@ public: template void Do(std::basic_string& x) { - DoContainer(x); + DoContiguousContainer(x); } template @@ -147,16 +147,22 @@ public: template void DoArray(std::array& x) { - DoArray(x.data(), (u32)x.size()); + DoArray(x.data(), static_cast(x.size())); } - template + template , int> = 0> void DoArray(T* x, u32 count) { - static_assert(IsTriviallyCopyable, "Only sane for trivially copyable types"); DoVoid(x, count * sizeof(T)); } + template , int> = 0> + void DoArray(T* x, u32 count) + { + for (u32 i = 0; i < count; ++i) + Do(x[i]); + } + template void DoArray(T (&arr)[N]) { @@ -249,6 +255,16 @@ public: } private: + template + void DoContiguousContainer(T& container) + { + u32 size = static_cast(container.size()); + Do(size); + container.resize(size); + + DoArray(&container[0], size); + } + template void DoContainer(T& x) {