From 8931c494e9c103d89929322ce63f21d55cc64fc4 Mon Sep 17 00:00:00 2001 From: Jeffery Hsu Date: Mon, 13 Nov 2023 15:18:15 -0600 Subject: [PATCH] Expand RingBufferImplementation beyond shared_ptr and unique_ptr Signed-off-by: Jeffery Hsu --- .../buffers/ring_buffer_implementation.hpp | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp b/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp index 3036a5eeb4..e22397f30c 100644 --- a/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp +++ b/rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp @@ -244,7 +244,11 @@ class RingBufferImplementation : public BufferImplementationBase * * \return a vector containing all the elements from the ring buffer */ - template::value, void> * = nullptr> + template::value && + std::is_copy_constructible< + typename is_std_unique_ptr::Ptr_type + >::value, + void> * = nullptr> std::vector get_all_data_impl() { std::lock_guard lock(mutex_); @@ -258,7 +262,8 @@ class RingBufferImplementation : public BufferImplementationBase return result_vtr; } - template::value, void> * = nullptr> + template::value, void> * = nullptr> std::vector get_all_data_impl() { std::lock_guard lock(mutex_); @@ -270,6 +275,23 @@ class RingBufferImplementation : public BufferImplementationBase return result_vtr; } + template::value && + !std::is_copy_constructible::value, void> * = nullptr> + std::vector get_all_data_impl() + { + throw std::logic_error("Underlined type results in invalid get_all_data_impl()"); + return {}; + } + + template::value && + !std::is_copy_constructible::Ptr_type>::value, + void> * = nullptr> + std::vector get_all_data_impl() + { + throw std::logic_error("Underlined type in unique_ptr results in invalid get_all_data_impl()"); + return {}; + } + size_t capacity_; std::vector ring_buffer_;