@@ -39,61 +39,54 @@ void * retyped_allocate(size_t size, void * untyped_allocator)
39
39
return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
40
40
}
41
41
42
- template <typename T, typename Alloc>
42
+ template <typename Alloc>
43
43
void retyped_deallocate (void * untyped_pointer, void * untyped_allocator)
44
44
{
45
45
auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
46
46
if (!typed_allocator) {
47
47
throw std::runtime_error (" Received incorrect allocator type" );
48
48
}
49
- auto typed_ptr = static_cast <T *>(untyped_pointer);
49
+ auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
50
50
std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
51
51
}
52
52
53
- template <typename T, typename Alloc>
53
+ template <typename Alloc>
54
54
void * retyped_reallocate (void * untyped_pointer, size_t size, void * untyped_allocator)
55
55
{
56
56
auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
57
57
if (!typed_allocator) {
58
58
throw std::runtime_error (" Received incorrect allocator type" );
59
59
}
60
- auto typed_ptr = static_cast <T *>(untyped_pointer);
60
+ auto typed_ptr = static_cast <typename Alloc::value_type *>(untyped_pointer);
61
61
std::allocator_traits<Alloc>::deallocate (*typed_allocator, typed_ptr, 1 );
62
62
return std::allocator_traits<Alloc>::allocate (*typed_allocator, size);
63
63
}
64
64
65
+ } // namespace allocator
65
66
66
67
// 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>
71
69
rcl_allocator_t get_rcl_allocator (Alloc & allocator)
72
70
{
73
71
rcl_allocator_t rcl_allocator = rcl_get_default_allocator ();
74
72
#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>;
78
76
rcl_allocator.state = &allocator;
79
77
#else
80
78
(void )allocator; // Remove warning
81
79
#endif
82
80
return rcl_allocator;
83
81
}
84
82
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)
91
85
{
92
- (void )allocator;
86
+ (void )allocator; // Remove warning
93
87
return rcl_get_default_allocator ();
94
88
}
95
89
96
- } // namespace allocator
97
90
} // namespace rclcpp
98
91
99
92
#endif // RCLCPP__ALLOCATOR__ALLOCATOR_COMMON_HPP_
0 commit comments