From 757d2b623fe7808f259fb2e64e541642ca0aadac Mon Sep 17 00:00:00 2001 From: Tyler Galdes Date: Fri, 16 Nov 2018 19:49:52 -0500 Subject: [PATCH] Add support for constructing Buffer from std::array --- include/cppkafka/buffer.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/cppkafka/buffer.h b/include/cppkafka/buffer.h index afa61b5..c2c8ed7 100644 --- a/include/cppkafka/buffer.h +++ b/include/cppkafka/buffer.h @@ -92,6 +92,17 @@ public: static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)"); } + /** + * Constructs a buffer from an array + * + * \param data The the array to be used as input + */ + template + Buffer(const std::array& data) + : data_(reinterpret_cast(&data[0])), size_(N * sizeof(T)) { + static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)"); + } + // Don't allow construction from temporary vectors template Buffer(std::vector&& data) = delete;