1 // Example program for returning a value from slots to signal invocation.
3 // Copyright Douglas Gregor 2001-2004.
4 // Copyright Frank Mori Hess 2009.
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
13 #include <boost/signals2/signal.hpp>
15 //[ signal_return_value_slot_defs_code_snippet
16 float product(float x, float y) { return x * y; }
17 float quotient(float x, float y) { return x / y; }
18 float sum(float x, float y) { return x + y; }
19 float difference(float x, float y) { return x - y; }
24 boost::signals2::signal<float (float x, float y)> sig;
26 //[ signal_return_value_main_code_snippet
27 sig.connect(&product);
28 sig.connect("ient);
30 sig.connect(&difference);
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;