15 #ifndef RCLCPP__ALLOCATOR__ALLOCATOR_DELETER_HPP_
16 #define RCLCPP__ALLOCATOR__ALLOCATOR_DELETER_HPP_
26 template<
typename Allocator>
30 using AllocRebind =
typename std::allocator_traits<Allocator>::template rebind_alloc<T>;
46 allocator_ = a.get_allocator();
50 void operator()(T * ptr)
52 std::allocator_traits<AllocRebind<T>>::destroy(*allocator_, ptr);
53 std::allocator_traits<AllocRebind<T>>::deallocate(*allocator_, ptr, 1);
57 Allocator * get_allocator()
const
62 void set_allocator(Allocator * alloc)
68 Allocator * allocator_;
71 template<
typename Alloc,
typename T,
typename D>
72 void set_allocator_for_deleter([[maybe_unused]] D * deleter, [[maybe_unused]] Alloc * alloc)
74 throw std::runtime_error(
"Reached unexpected template specialization");
77 template<
typename T,
typename U>
78 void set_allocator_for_deleter(
79 [[maybe_unused]] std::default_delete<T> * deleter,
80 [[maybe_unused]] std::allocator<U> * alloc)
85 template<
typename Alloc,
typename T>
86 void set_allocator_for_deleter(AllocatorDeleter<T> * deleter, Alloc * alloc)
88 if (!deleter || !alloc) {
89 throw std::invalid_argument(
"Argument was NULL to set_allocator_for_deleter");
91 deleter->set_allocator(alloc);
94 template<
typename Alloc,
typename T>
95 using Deleter =
typename std::conditional<
96 std::is_same<typename std::allocator_traits<Alloc>::template rebind_alloc<T>,
97 std::allocator<T>>::value,
98 std::default_delete<T>,
99 AllocatorDeleter<Alloc>
Versions of rosidl_typesupport_cpp::get_message_type_support_handle that handle adapted types.