I have program that receives callback calls from a library when messages are received. The callbacks' signature is void on_message(const MyLargeObject &my_large_object);
My code for reacting to some of the messages is more complex than what I want to run directly in the callbacks. Because of that, I am launching an asynchronous task (std::async) to do the actual processing.
Currently, the asynchronous tasks' signature is void on_message_async_task(MyLargeObject my_large_object);. My reasoning says that I should pass the argument to the async task as a copy because I see no guarantee that the original object lives until the task is finished. Static code analysis is, however, saying that I should use const reference instead to avoid expensive copying. Is that false positive or am I missing something here?
void on_message(std::unique_ptr<MyLargeObject> my_large_object_in_a_smart_pointer).