Move to common namespace

This commit is contained in:
David Marcec
2020-08-03 19:30:39 +10:00
parent 4f4cbde9e5
commit f7df03e328
2 changed files with 8 additions and 4 deletions

View File

@@ -4,6 +4,8 @@
#pragma once #pragma once
namespace Common {
// Check if type is like an STL container // Check if type is like an STL container
template <typename T> template <typename T>
concept IsSTLContainer = requires(T t) { concept IsSTLContainer = requires(T t) {
@@ -18,3 +20,5 @@ concept IsSTLContainer = requires(T t) {
t.data(); t.data();
t.size(); t.size();
}; };
} // namespace Common

View File

@@ -194,15 +194,15 @@ public:
/* Helper function to write a buffer using the appropriate buffer descriptor /* Helper function to write a buffer using the appropriate buffer descriptor
* *
* @tparam ContiguousContainer an arbitrary container that satisfies the * @tparam T an arbitrary container that satisfies the
* ContiguousContainer concept in the C++ standard library. * ContiguousContainer concept in the C++ standard library or a trivially copyable type.
* *
* @param container The container to write the data of into a buffer. * @param data The container/data to write into a buffer.
* @param buffer_index The buffer in particular to write to. * @param buffer_index The buffer in particular to write to.
*/ */
template <typename T, typename = std::enable_if_t<!std::is_pointer_v<T>>> template <typename T, typename = std::enable_if_t<!std::is_pointer_v<T>>>
std::size_t WriteBuffer(const T& data, std::size_t buffer_index = 0) const { std::size_t WriteBuffer(const T& data, std::size_t buffer_index = 0) const {
if constexpr (IsSTLContainer<T>) { if constexpr (Common::IsSTLContainer<T>) {
using ContiguousType = typename T::value_type; using ContiguousType = typename T::value_type;
static_assert(std::is_trivially_copyable_v<ContiguousType>, static_assert(std::is_trivially_copyable_v<ContiguousType>,
"Container to WriteBuffer must contain trivially copyable objects"); "Container to WriteBuffer must contain trivially copyable objects");