Skip to content

Commit

Permalink
Add serializer for container of non-trivial types
Browse files Browse the repository at this point in the history
Contains notes about future changes to `enable_if` guards, explaining
where this is going.
  • Loading branch information
DanRStevens committed Jan 29, 2021
1 parent 98d806b commit cd9645c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Stream/Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ namespace OP2Utility::Stream
WriteImplementation(container.data(), container.size() * sizeof(typename T::value_type));
}

// Arbitrary container of writeable data types
// For use when the container is non-contiguous, or the element type is not trivially copyable
template<typename T>
inline
std::enable_if_t<
// The enable_if check needs to change to something like:
// is_iterable<T> && is_writeable<typename T::value_type>
// For now, we leave the old check to avoid ambiguity
!std::is_trivially_copyable<typename T::value_type>::value
>
Write(const T& container) {
// Loop over all elements and call custom serializer for type
for (const auto& element : container) {
Write(element); // Call custom serializer
}
}

// Size prefixed container data types
// Ex: Write<uint32_t>(vector); // Write 32-bit vector size followed by vector data
template<typename SizeType, typename T>
Expand Down

0 comments on commit cd9645c

Please sign in to comment.