relopnice.blogg.se

Boost signal
Boost signal








An object of type boost::optional is returned, which when de-referenced returns the number 2. Please note that s() does not directly return the result of the last function called. By default, only the last return value of all associated functions is returned. Both return values were correctly accepted by s, but all except the last one were ignored. The first lambda function returns 1, the second returns 2.Įxample 67.7 writes 2 to standard output.

boost signal

In Example 67.7 two lambda functions are associated with the signal s. Calling s results in a trigger that, in turn, executes the lambda function that was previously associated with connect().Įxample 67.1 can also be implemented with std::function, as shown in Example 67.2. The brackets are empty because void() does not expect any parameters. The signature of this function matches the one passed as the template parameter. The signal is triggered by calling s like a regular function.

boost signal

The lambda function is called whenever the signal s is triggered. Because the lambda function conforms to the required signature, void(), the association is successfully established. In Example 67.1, only functions with a signature of void() can be associated with the signal s.Ī lambda function is associated with the signal s through connect(). S.connect() īoost::signals2::signal is a class template that expects as a template parameter the signature of the function that will be used as an event handler.










Boost signal