@@ -27,10 +27,39 @@ namespace rclcpp
2727namespace allocator
2828{
2929
30+ template <typename T>
31+ using clean_t = std::remove_cv_t <std::remove_reference_t <T>>;
32+
33+ // Primary template: false
34+ template <typename , typename = std::void_t <>>
35+ struct has_get_rcl_allocator : std::false_type {};
36+
37+ // Specialization: true if expression is valid
38+ template <typename T>
39+ struct has_get_rcl_allocator <T,
40+ std::void_t <
41+ decltype (std::declval<clean_t <T> &>().get_rcl_allocator())
42+ >
43+ >
44+ : std::bool_constant<
45+ std::is_same_v<
46+ decltype(std::declval<clean_t <T> &>().get_rcl_allocator()),
47+ rcl_allocator_t
48+ >
49+ >
50+ {};
51+
52+ // Helper variable template
53+ template <typename T>
54+ inline constexpr bool has_get_rcl_allocator_v =
55+ has_get_rcl_allocator<T>::value;
56+
3057template <typename T, typename Alloc>
3158using AllocRebind = typename std::allocator_traits<Alloc>::template rebind_traits<T>;
3259
3360template <typename Alloc>
61+ [[deprecated(" Conversion of C++ allocators to C style is not valid, as the size on deallocate"
62+ " can not be determined. This will be remove in future versions of ros." )]]
3463void * retyped_allocate (size_t size, void * untyped_allocator)
3564{
3665 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
@@ -41,6 +70,8 @@ void * retyped_allocate(size_t size, void * untyped_allocator)
4170}
4271
4372template <typename Alloc>
73+ [[deprecated(" Conversion of C++ allocators to C style is not valid, as the size on deallocate"
74+ " can not be determined. This will be remove in future versions of ros." )]]
4475void * retyped_zero_allocate (size_t number_of_elem, size_t size_of_elem, void * untyped_allocator)
4576{
4677 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
@@ -57,6 +88,8 @@ void * retyped_zero_allocate(size_t number_of_elem, size_t size_of_elem, void *
5788}
5889
5990template <typename T, typename Alloc>
91+ [[deprecated(" Conversion of C++ allocators to C style is not valid, as the size on deallocate"
92+ " can not be determined. This will be remove in future versions of ros." )]]
6093void retyped_deallocate (void * untyped_pointer, void * untyped_allocator)
6194{
6295 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
@@ -68,6 +101,8 @@ void retyped_deallocate(void * untyped_pointer, void * untyped_allocator)
68101}
69102
70103template <typename T, typename Alloc>
104+ [[deprecated(" Conversion of C++ allocators to C style is not valid, as the size on deallocate"
105+ " can not be determined. This will be remove in future versions of ros." )]]
71106void * retyped_reallocate (void * untyped_pointer, size_t size, void * untyped_allocator)
72107{
73108 auto typed_allocator = static_cast <Alloc *>(untyped_allocator);
@@ -86,7 +121,8 @@ template<
86121 typename Alloc,
87122 typename std::enable_if<!std::is_same<Alloc, std::allocator<void >>::value>::type * = nullptr >
88123[[deprecated(" Conversion of C++ allocators to C style is not valid, as the size on deallocate"
89- " can not be determined. This will be remove in future versions of ros." )]]
124+ " can not be determined. This will be remove in future versions of ros. To suppress this warning"
125+ " define the method 'rcl_allocator_t get_rcl_allocator()' on your allocator" )]]
90126rcl_allocator_t get_rcl_allocator (Alloc & allocator)
91127{
92128 rcl_allocator_t rcl_allocator = rcl_get_default_allocator ();
0 commit comments