@@ -39,61 +39,54 @@ void * retyped_allocate(size_t size, void * untyped_allocator)
3939 return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
4040}
4141
42- template <typename T, typename Alloc>
42+ template <typename Alloc>
4343void retyped_deallocate (void * untyped_pointer, void * untyped_allocator)
4444{
4545 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
4646 if (!typed_allocator) {
4747 throw std::runtime_error (" Received incorrect allocator type" );
4848 }
49- auto typed_ptr = static_cast <T *>(untyped_pointer);
49+ auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
5050 std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
5151}
5252
53- template <typename T, typename Alloc>
53+ template <typename Alloc>
5454void * retyped_reallocate (void * untyped_pointer, size_t size, void * untyped_allocator)
5555{
5656 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
5757 if (!typed_allocator) {
5858 throw std::runtime_error (" Received incorrect allocator type" );
5959 }
60- auto typed_ptr = static_cast <T *>(untyped_pointer);
60+ auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
6161 std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
6262 return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
6363}
6464
65+ } // namespace allocator
6566
6667// Convert a std::allocator_traits-formatted Allocator into an rcl allocator
67- template <
68- typename T,
69- typename Alloc,
70- typename std::enable_if<!std::is_same<Alloc, std::allocator<void >>::value>::type * = nullptr >
68+ template <typename Alloc>
7169rcl_allocator_t get_rcl_allocator (Alloc & allocator)
7270{
7371 rcl_allocator_t rcl_allocator = rcl_get_default_allocator ();
7472#ifndef _WIN32
75- rcl_allocator.allocate = &retyped_allocate<Alloc>;
76- rcl_allocator.deallocate = &retyped_deallocate<T, Alloc>;
77- rcl_allocator.reallocate = &retyped_reallocate<T, Alloc>;
73+ rcl_allocator.allocate = &allocator:: retyped_allocate<Alloc>;
74+ rcl_allocator.deallocate = &allocator:: retyped_deallocate<Alloc>;
75+ rcl_allocator.reallocate = &allocator:: retyped_reallocate<Alloc>;
7876 rcl_allocator.state = &allocator;
7977#else
8078 (void )allocator; // Remove warning
8179#endif
8280 return rcl_allocator;
8381}
8482
85- // TODO(jacquelinekay) Workaround for an incomplete implementation of std::allocator<void>
86- template <
87- typename T,
88- typename Alloc,
89- typename std::enable_if<std::is_same<Alloc, std::allocator<void >>::value>::type * = nullptr >
90- rcl_allocator_t get_rcl_allocator (Alloc & allocator)
83+ template <typename T>
84+ rcl_allocator_t get_rcl_allocator (std::allocator<T>& allocator)
9185{
92- (void )allocator;
86+ (void )allocator; // Remove warning
9387 return rcl_get_default_allocator ();
9488}
9589
96- } // namespace allocator
9790} // namespace rclcpp
9891
9992#endif // RCLCPP__ALLOCATOR__ALLOCATOR_COMMON_HPP_
0 commit comments