1 /* Copyright (c) 2014-2015. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #ifndef SIMGRID_XBT_SIGNAL_HPP
7 #define SIMGRID_XBT_SIGNAL_HPP
15 template<class S> class signal;
17 /** A signal/slot mechanism
19 * S is expected to be the function signature of the signal.
20 * I'm not sure we need a return value (it is currently ignored).
21 * If we don't we might use `signal<P1, P2, ...>` instead.
23 template<class R, class... P>
24 class signal<R(P...)> {
26 typedef std::function<R(P...)> callback_type;
27 std::vector<callback_type> handlers_;
29 template<class U> XBT_ALWAYS_INLINE
32 handlers_.push_back(std::move(slot));
35 R operator()(P... args) const
37 for (auto& handler : handlers_)
40 void disconnect_all_slots()