]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/signals2/example/extended_slot.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / signals2 / example / extended_slot.cpp
1 // Example program for connecting an extended slot,
2 // using a signal's connect_extended and extended_slot_type.
3 //
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 <boost/signals2/signal.hpp>
13 #include <iostream>
14 #include <string>
15
16 namespace bs2 = boost::signals2;
17
18 void single_shot_slot(const bs2::connection &conn, const std::string &message)
19 {
20 conn.disconnect();
21 std::cout << message;
22 }
23
24 int main()
25 {
26 typedef bs2::signal<void (void)> sig_type;
27 sig_type sig;
28 {
29 sig_type::extended_slot_type hello(&single_shot_slot, _1, "Hello");
30 sig.connect_extended(hello);
31 }
32 sig(); // prints "Hello"
33 {
34 sig_type::extended_slot_type world(&single_shot_slot, _1, ", World!\n");
35 sig.connect_extended(world);
36 }
37 sig(); // only prints ", World!\n" since hello slot has disconnected itself
38 sig(); // prints nothing, world slot has disconnected itself
39
40 return 0;
41 }
42