1 // Example program for returning a value from slots to signal invocation.
2 //
3 // Copyright Douglas Gregor 2001-2004.
4 // Copyright Frank Mori Hess 2009.
5 //
6 // Use, modification and
7 // distribution is subject to the Boost Software License, Version
8 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 // For more information, see http://www.boost.org
11
12 #include <iostream>
13 #include <boost/signals2/signal.hpp>
14
15 //[ signal_return_value_slot_defs_code_snippet
product(float x,float y)16 float product(float x, float y) { return x * y; }
quotient(float x,float y)17 float quotient(float x, float y) { return x / y; }
sum(float x,float y)18 float sum(float x, float y) { return x + y; }
difference(float x,float y)19 float difference(float x, float y) { return x - y; }
20 //]
21
main()22 int main()
23 {
24 boost::signals2::signal<float (float x, float y)> sig;
25
26 //[ signal_return_value_main_code_snippet
27 sig.connect(&product);
28 sig.connect("ient);
29 sig.connect(&sum);
30 sig.connect(&difference);
31
32 // The default combiner returns a boost::optional containing the return
33 // value of the last slot in the slot list, in this case the
34 // difference function.
35 std::cout << *sig(5, 3) << std::endl;
36 //]
37 }
38
39