Replace const std::vector& with boost::span#50
Replace const std::vector& with boost::span#50vsoulgard wants to merge 2 commits intoboostorg:developfrom
const std::vector& with boost::span#50Conversation
|
Hi, thanks for the PR! Issue is that this code would stop working (heap-use-after-free) auto op = c.async_subscribe(
std::vector<subscribe_topic>{{ "test/mqtt-test", { qos_e::exactly_once } }}, subscribe_props {},
asio::deferred
);
/* initiate op later */In the current implementation, the vector is copied only if the initiation is deferred; otherwise it's forwarded by reference ( I think the correct solution is to use boost::span in template <
typename TopicSequence,
typename CompletionToken =
typename asio::default_completion_token<executor_type>::type
>
decltype(auto) async_subscribe(
const TopicSequence& topics,
const subscribe_props& props,
CompletionToken&& token = {}
) {
using Signature = void (
error_code, std::vector<reason_code>, suback_props
);
return asio::async_initiate<CompletionToken, Signature>(
detail::initiate_async_subscribe(_impl), token,
topics, props
);
}Regarding template <
typename CompletionToken =
typename asio::default_completion_token<executor_type>::type
>
decltype(auto) async_subscribe(
std::initializer_list<subscribe_topic> topics,
const subscribe_props& props,
CompletionToken&& token = {}
) {
return async_subscribe(std::vector(topics), props, std::forward<CompletionToken>(token));
} |
|
Thank you for the detailed review and clear guidance! I've comitted new changes. For |
|
Thanks for the update! I'd like to explore a few options for constraining the template before merging. I'll get back to you on this. |
close #49
Allows to accept any contiguous memory (arrays, vectors, or raw buffers) without being tied to a specific storage type.
But
boost::spandoes not construct from initializer_list.