libsigc++: libsigc++ Reference Manual

libsigc++ 2.12.2

libsigc++ Reference Manual

# Description

libsigc++ provides a typesafe (at compile time) callback system for standard C++. It allows you to define signals and to connect those signals to any callback function, either a global or a member function, regardless of whether it is static or virtual. It also contains adaptor classes for connection of dissimilar callbacks.

For instance, see the Signals, Functors, Slots and Adaptors.

See also the libsigc++ tutorial, the libsigc++ website, and the Signals appendix of the Programming with gtkmm book. Note that the online documentation describes sigc++3.

# Features

- Compile-time typesafe callbacks (also faster than run time checks)
- Type-safety violations report the line number correctly with template names (no tracing template failures into headers)
- No compiler extensions or meta compilers required
- Proper handling of dynamic objects and signals (deleted objects will not cause crashes)
- Extendable API at any level: signal, slot, connection and trackable
- Extensions do not require alteration of basic components
- User-definable accumulators
- A variety of adaptors to change the callback signature: bind, hide, retype, and compose

# Basic Usage

Include the libsigc++ header:

#include <sigc++/sigc++.h>

(You may include individual headers, such as `sigc++/bind`.h instead.)

If your source file is `program.cc`, you can compile it with:

g++ program.cc -o program `pkg-config --cflags --libs sigc++-2.0`
sigc
The libsigc++ namespace.
Definition limit_reference.h:12

If your version of g++ is not C++11-compliant by default, add the `-std=c++11` option.

## Using Meson

If using Meson, include the following in `meson.build:`

sigc_dep = dependency('sigc++-2.0')
program_name = 'program'
cpp_sources = [ 'program.cc' ]
executable(program_name,
cpp_sources,
dependencies: sigc_dep
)

Your `dependencies:` keyword argument should also mention any other libraries that you need to use.

## Using Autotools

Alternatively, if using autoconf, use the following in `configure.ac:`

PKG_CHECK_MODULES([DEPS], [sigc++-2.0])

Then use the generated `DEPS_CFLAGS` and `DEPS_LIBS` variables in the project `Makefile.am` files. For example:

yourprogram_CPPFLAGS = $(DEPS_CFLAGS)
yourprogram_LDADD = $(DEPS_LIBS)

Your `PKG_CHECK_MODULES()` call should also mention any other libraries that you need to use via pkg-config.

## Using CMake

If using CMake, use the following in `CMakeList.txt:`

include(FindPkgConfig)
pkg_check_modules(DEPS REQUIRED sigc++-2.0)
include_directories(${DEPS_INCLUDE_DIRS})
target_link_libraries(yourprogram ${DEPS_LIBRARIES})

Your `pkg_check_modules()` call should also mention any other libraries that you need to use via pkg-config.

# Scope of Documentation

libsigc++ contains many template functions and template classes/structs, some with many specializations. This reference manual does not show all specializations of those templates that hardly any user will use directly.