From 757d2b623fe7808f259fb2e64e541642ca0aadac Mon Sep 17 00:00:00 2001 From: Tyler Galdes Date: Fri, 16 Nov 2018 19:49:52 -0500 Subject: [PATCH 1/3] 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; From b48036fe62e3f6b948407910a6259c1fa36b5246 Mon Sep 17 00:00:00 2001 From: Tyler Galdes Date: Mon, 19 Nov 2018 11:49:17 -0500 Subject: [PATCH 2/3] use std::array functions for pointer and size of data --- include/cppkafka/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cppkafka/buffer.h b/include/cppkafka/buffer.h index c2c8ed7..b4c05cf 100644 --- a/include/cppkafka/buffer.h +++ b/include/cppkafka/buffer.h @@ -99,7 +99,7 @@ public: */ template Buffer(const std::array& data) - : data_(reinterpret_cast(&data[0])), size_(N * sizeof(T)) { + : data_(reinterpret_cast(data.data())), size_(data.size()) { static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)"); } From 248d1b06388fa04a8249f7dcccfb3d665fbfd588 Mon Sep 17 00:00:00 2001 From: Tyler Galdes Date: Mon, 19 Nov 2018 19:48:02 -0500 Subject: [PATCH 3/3] Delete construction of buffer with rvalue arrays --- include/cppkafka/buffer.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/cppkafka/buffer.h b/include/cppkafka/buffer.h index b4c05cf..1c5e7c9 100644 --- a/include/cppkafka/buffer.h +++ b/include/cppkafka/buffer.h @@ -92,6 +92,10 @@ public: static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)"); } + // Don't allow construction from temporary vectors + template + Buffer(std::vector&& data) = delete; + /** * Constructs a buffer from an array * @@ -103,9 +107,9 @@ public: static_assert(sizeof(T) == sizeof(DataType), "sizeof(T) != sizeof(DataType)"); } - // Don't allow construction from temporary vectors - template - Buffer(std::vector&& data) = delete; + // Don't allow construction from temporary arrays + template + Buffer(std::array&& data) = delete; /** * \brief Construct a buffer from a const string ref