File size: 1,271 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Simple Examples

>If you are not familar with Boost.Signals2, please read [Boost.Signals2: Connections](https://theboostcpplibraries.com/boost.signals2-connections)

## Example with signal<> and connection

```cpp

// Creates signal and connects 1 slot, calls 2 times, disconnects, calls again.

// Outputs:

//  13

//  17

#include "libfastsignals/signal.h"



using namespace fastsignals;



int main()

{

    signal<void(int)> valueChanged;

    connection conn;

    conn = valueChanged.connect([](int value) {

        cout << value << endl;

    });

    valueChanged(13);

    valueChanged(17);

    conn.disconnect();

    valueChanged(42);

}

```

## Example with scoped_connection



```cpp

// Creates signal and connects 1 slot, calls 2 times, calls again after scoped_connection destroyed.
//  - note: scoped_connection closes connection in destructor

// Outputs:

//  13

//  17

#include "libfastsignals/signal.h"



using namespace fastsignals;



int main()

{

    signal<void(int)> valueChanged;

    {

        scoped_connection conn;
        conn = valueChanged.connect([](int value) {

            cout << value << endl;

        });

        valueChanged(13);

        valueChanged(17);

    }

    valueChanged(42);

}

```