How does compiler deduce return type from this lambda expression?

websocket::stream_base::decorator is a template function with one template type parameter.

template<class Decorator>
decorator( Decorator&& f );

In this call

ws_.set_option(websocket::stream_base::decorator(
        [](websocket::response_type& res)
        {
            res.set(http::field::server,
                std::string(BOOST_BEAST_VERSION_STRING) +
                    " websocket-server-async");
        }));

the function is called accepting the lambda expression

[](websocket::response_type& res)
        {
            res.set(http::field::server,
                std::string(BOOST_BEAST_VERSION_STRING) +
                    " websocket-server-async");
        }

as its template argument. The lambda expression has by default the return type void because there is no return statement in the lambda expression.

How does the lambda expression know, it should return a Decorator&&

It is the lambda expression itself is used as an argument for the declared function template parameter Decorator&&.