Why Are Callbacks of the HttpRequestHandler Classes Declared as Rvalue References?

chiefsucker • 5 months ago

Basically what the title says, I wonder what the reason is behind the callbacks being declared as rvalue references?

antao2002 • 5 months ago

When a user has to capture the callback for an asynchronous interface, it can be 'moved' (not copied). for example:

auto callbackPtr=std::make_shared<.....>(std::move(callback));  
dbclient<<"select ...."
               >>[callbackPtr](result ...)
                {//create response....
                >>[callbackPtr](....)//exception callback, some error occurs.

Moving is always cheaper than copying, so I pass the callback as a r-reference.

Log in to comment