Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/signals/example/difference_connection.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.2 KB
Line 
1// Boost.Signals library
2
3// Copyright Douglas Gregor 2001-2003. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org
9
10#include <iostream>
11#include <boost/signals/signal2.hpp>
12#include <cassert>
13
14struct print_sum {
15  void operator()(int x, int y) const { std::cout << x+y << std::endl; }
16};
17
18struct print_product {
19  void operator()(int x, int y) const { std::cout << x*y << std::endl; }
20};
21
22struct print_difference {
23  void operator()(int x, int y) const { std::cout << x-y << std::endl; }
24};
25
26int main()
27{
28  boost::signal2<void, int, int> sig;
29
30  sig.connect(print_sum());
31  sig.connect(print_product());
32
33  sig(3, 5);
34
35  boost::signals::connection print_diff_con = sig.connect(print_difference());
36
37  // sig is still connected to print_diff_con
38  assert(print_diff_con.connected());
39
40  sig(5, 3); // prints 8, 15, and 2
41
42  print_diff_con.disconnect(); // disconnect the print_difference slot
43
44  sig(5, 3); // now prints 8 and 15, but not the difference
45
46  assert(!print_diff_con.connected()); // not connected any more
47  return 0;
48}
Note: See TracBrowser for help on using the repository browser.