Signals Library
slot_iterator.hpp
1 #ifndef SIGNALS_DETAIL_SLOT_ITERATOR_HPP
2 #define SIGNALS_DETAIL_SLOT_ITERATOR_HPP
3 #include <iterator>
4 
5 namespace sig {
6 
7 // Slot_iterator points to a functor object, when it is dereferenced you get a
8 // function type object that is callable with no arguments. The iterator is
9 // useful for iterating over a container of functions and calling each function
10 // on a dereference operation. InputIterator is any container iterator that
11 // holds a callable type and can be incremented, dereferenced and copied.
12 template <typename InputIterator>
14  public:
15  using Iter_value_t =
16  typename std::iterator_traits<InputIterator>::value_type;
17  using Result_t = typename Iter_value_t::result_type;
18 
19  public:
20  Slot_iterator() = default;
21 
22  explicit Slot_iterator(InputIterator iter) : iter_{iter} {}
23 
24  public:
25  auto operator*() -> Result_t
26  {
27  auto slot = *iter_;
28  return slot();
29  }
30 
31  auto operator++() -> Slot_iterator&
32  {
33  ++iter_;
34  return *this;
35  }
36 
37  auto operator==(Slot_iterator const& x) -> bool { return iter_ == x.iter_; }
38 
39  auto operator!=(Slot_iterator const& x) -> bool { return !operator==(x); }
40 
41  private:
42  InputIterator iter_;
43 };
44 
45 } // namespace sig
46 
47 #endif // SIGNALS_DETAIL_SLOT_ITERATOR_HPP
sig
Definition: connection.hpp:8
sig::Slot_iterator
Definition: slot_iterator.hpp:13