Skip to content

Commit 481b71b

Browse files
jmachowinskiJanosch MachowinskiJEnoch
authored
fix: Compile fix for MSVC 2022 in C++20 mode (#778)
Signed-off-by: Janosch Machowinski <J.Machowinski@cellumation.com> Co-authored-by: Janosch Machowinski <J.Machowinski@cellumation.com> Co-authored-by: Julien Enoch <julien.e@zettascale.tech>
1 parent 1d10c36 commit 481b71b

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

include/zenoh/api/bytes.hxx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ class Bytes : public Owned<::z_owned_bytes_t> {
6464
template <class Allocator>
6565
Bytes(std::vector<uint8_t, Allocator>&& v) : Bytes() {
6666
std::vector<uint8_t, Allocator>* ptr = new std::vector<uint8_t, Allocator>(std::move(v));
67-
auto d = [p = ptr]() mutable { delete p; };
68-
using D = decltype(d);
69-
using Dval = std::remove_reference_t<D>;
70-
using DroppableType = typename detail::closures::Droppable<Dval>;
71-
auto drop = DroppableType::into_context(std::move(d));
67+
struct VectorDeleter {
68+
std::vector<uint8_t, Allocator>* ptr;
69+
void operator()() { delete ptr; };
70+
};
71+
using DroppableType = typename detail::closures::Droppable<VectorDeleter>;
72+
auto drop = DroppableType::into_context(VectorDeleter{ptr});
7273
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), ptr->data(), ptr->size(),
7374
detail::closures::_zenoh_drop_with_context, drop);
7475
}
@@ -81,19 +82,20 @@ class Bytes : public Owned<::z_owned_bytes_t> {
8182
}
8283

8384
/// @brief Construct by copying sequence of charactes.
84-
Bytes(const char* v) : Bytes(std::string_view(v)){};
85+
Bytes(const char* v) : Bytes(std::string_view(v)) {}
8586

8687
/// @brief Construct by copying sequence of charactes.
87-
Bytes(const std::string& v) : Bytes(std::string_view(v)){};
88+
Bytes(const std::string& v) : Bytes(std::string_view(v)) {}
8889

8990
/// @brief Construct by moving a string.
9091
Bytes(std::string&& v) : Bytes() {
9192
std::string* ptr = new std::string(std::move(v));
92-
auto d = [p = ptr]() mutable { delete p; };
93-
using D = decltype(d);
94-
using Dval = std::remove_reference_t<D>;
95-
using DroppableType = typename detail::closures::Droppable<Dval>;
96-
auto drop = DroppableType::into_context(std::move(d));
93+
struct StringDeleter {
94+
std::string* ptr;
95+
void operator()() { delete ptr; }
96+
};
97+
using DroppableType = typename detail::closures::Droppable<StringDeleter>;
98+
auto drop = DroppableType::into_context(StringDeleter{ptr});
9799
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), reinterpret_cast<uint8_t*>(ptr->data()), ptr->size(),
98100
detail::closures::_zenoh_drop_with_context, drop);
99101
}
@@ -108,11 +110,13 @@ class Bytes : public Owned<::z_owned_bytes_t> {
108110
Bytes(uint8_t* ptr, size_t len, Deleter deleter) : Bytes() {
109111
static_assert(std::is_invocable_r<void, Deleter, uint8_t*>::value,
110112
"deleter should be callable with the following signature: void deleter(uint8_t* data)");
111-
auto d = [p = ptr, del = std::move(deleter)]() mutable { del(p); };
112-
using D = decltype(d);
113-
using Dval = std::remove_reference_t<D>;
114-
using DroppableType = typename detail::closures::Droppable<Dval>;
115-
auto drop = DroppableType::into_context(std::move(d));
113+
struct CustomDeleter {
114+
uint8_t* ptr;
115+
Deleter deleter;
116+
void operator()() { deleter(ptr); }
117+
};
118+
using DroppableType = typename detail::closures::Droppable<CustomDeleter>;
119+
auto drop = DroppableType::into_context(CustomDeleter{ptr, std::move(deleter)});
116120
::z_bytes_from_buf(interop::as_owned_c_ptr(*this), ptr, len, detail::closures::_zenoh_drop_with_context, drop);
117121
}
118122

0 commit comments

Comments
 (0)