Skip to content
Permalink
Browse files

Merge pull request #7767 from Tilka/chunkfile

ChunkFile: treat vectors/strings as sized arrays
  • Loading branch information...
Tilka committed Feb 2, 2019
2 parents 363ce67 + 04a9248 commit 0115906e41c457ad5cffe3bb2766b7124ee31fde
Showing with 21 additions and 5 deletions.
  1. +21 −5 Source/Core/Common/ChunkFile.h
@@ -116,7 +116,7 @@ class PointerWrap
template <typename T>
void Do(std::vector<T>& x)
{
DoContainer(x);
DoContiguousContainer(x);
}

template <typename T>
@@ -134,7 +134,7 @@ class PointerWrap
template <typename T>
void Do(std::basic_string<T>& x)
{
DoContainer(x);
DoContiguousContainer(x);
}

template <typename T, typename U>
@@ -147,16 +147,22 @@ class PointerWrap
template <typename T, std::size_t N>
void DoArray(std::array<T, N>& x)
{
DoArray(x.data(), (u32)x.size());
DoArray(x.data(), static_cast<u32>(x.size()));
}

template <typename T>
template <typename T, typename std::enable_if_t<IsTriviallyCopyable<T>, int> = 0>
void DoArray(T* x, u32 count)
{
static_assert(IsTriviallyCopyable<T>, "Only sane for trivially copyable types");
DoVoid(x, count * sizeof(T));
}

template <typename T, typename std::enable_if_t<!IsTriviallyCopyable<T>, int> = 0>
void DoArray(T* x, u32 count)
{
for (u32 i = 0; i < count; ++i)
Do(x[i]);
}

template <typename T, std::size_t N>
void DoArray(T (&arr)[N])
{
@@ -249,6 +255,16 @@ class PointerWrap
}

private:
template <typename T>
void DoContiguousContainer(T& container)
{
u32 size = static_cast<u32>(container.size());
Do(size);
container.resize(size);

DoArray(&container[0], size);
}

template <typename T>
void DoContainer(T& x)
{

0 comments on commit 0115906

Please sign in to comment.
You can’t perform that action at this time.