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

1 Relevant Page: Controller-httpsimplecontroller
chiefsucker 11 months ago

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

antao2002 11 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