NEURON
signal.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 
5 template <typename... Args>
6 class signal_ {
7  public:
8  using key_type = unsigned;
9 
10  template <typename F>
12  ++counter;
13  functors[counter] = f;
14  return counter;
15  }
16 
17  void disconnect(unsigned i) {
18  auto it = functors.find(i);
19  if (it != functors.end()) {
20  functors.erase(it);
21  }
22  }
23 
24  void send(Args... args) const {
25  for (const auto& [i, f]: functors) {
26  std::invoke(f, args...);
27  }
28  }
29 
30  private:
32  std::unordered_map<key_type, std::function<void(Args...)>> functors;
33 };
key_type counter
Definition: signal.hpp:31
void send(Args... args) const
Definition: signal.hpp:24
void disconnect(unsigned i)
Definition: signal.hpp:17
key_type connect(F f)
Definition: signal.hpp:11
std::unordered_map< key_type, std::function< void(Args...)> > functors
Definition: signal.hpp:32
unsigned key_type
Definition: signal.hpp:8
#define i
Definition: md1redef.h:19