c++boost.gif (8819 bytes)HomeLibrariesPeopleFAQMore

Boost.Signals

Douglas Gregor

Permission to copy, use, sell and distribute this software is granted provided this copyright notice appears in all copies. Permission to modify the code and to distribute modified code is granted provided this copyright notice appears in all copies, and a notice that the code was modified is included with the copyright notice.

This software is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.

Table of Contents

Introduction
Tutorial
How to Read this Tutorial
Compatibility Note
Hello, World! (Beginner)
Calling multiple slots
Connecting multiple slots (Beginner)
Ordering slot call groups (Intermediate)
Passing values to and from slots
Slot Arguments (Beginner)
Signal Return Values (Advanced)
Connection Management
Disconnecting Slots (Beginner)
Scoped connections (Intermediate)
Automatic connection management (Intermediate)
When can disconnections occur? (Intermediate)
Passing slots (Intermediate)
Reference
Header <boost/signal.hpp>
Header <boost/signals/slot.hpp>
Header <boost/signals/trackable.hpp>
Header <boost/signals/connection.hpp>
Header <boost/visit_each.hpp>
Header <boost/last_value.hpp>
Frequently Asked Questions
Design Overview
Type Erasure
connection class
Slot Call Iterator
visit_each function template
Design Rationale
Choice of Slot Definitions
User-level Connection Management
Combiner Interface
Connection Interfaces: += operator
trackable rationale
trackable copying behavior
Why derivation from trackable?
Comparison with other Signal/Slot implementations
libsigc++
.NET delegates
Testsuite
Acceptance tests

Introduction

The Boost.Signals library is an implementation of a managed signals and slots system. Signals represent callbacks with multiple targets, and are also called publishers or events in similar systems. Signals are connected to some set of slots, which are callback receivers (also called event targets or subscribers), which are called when the signal is "emitted."

Signals and slots are managed, in that signals and slots (or, more properly, objects that occur as part of the slots) track all connections and are capable of automatically disconnecting signal/slot connections when either is destroyed. This enables the user to make signal/slot connections without expending a great effort to manage the lifetimes of those connections with regard to the lifetimes of all objects involved.

When signals are connected to multiple slots, there is a question regarding the relationship between the return values of the slots and the return value of the signals. Boost.Signals allows the user to specify the manner in which multiple return values are combined.