Allow constructing Buffers from std::vector

This commit is contained in:
Matias Fontanini
2017-06-04 08:31:57 -07:00
parent c58a4792d3
commit 895a983d17
2 changed files with 23 additions and 1 deletions

View File

@@ -77,6 +77,21 @@ public:
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
}
/**
* Constructs a buffer from a vector
*
* \param data The vector to be used as input
*/
template <typename T>
Buffer(const std::vector<T>& data)
: data_(data.data()), size_(data.size()) {
static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)");
}
// Don't allow construction from temporary vectors
template <typename T>
Buffer(std::vector<T>&& data) = delete;
/**
* \brief Construct a buffer from a const string ref
*
@@ -85,7 +100,7 @@ public:
*/
Buffer(const std::string& data);
// Don't allow construction from temporaries
// Don't allow construction from temporary strings
Buffer(std::string&&) = delete;
Buffer(const Buffer&) = delete;