Signals Library
optional_last_value.hpp
1 #ifndef SIGNALS_OPTIONAL_LAST_VALUE_HPP
2 #define SIGNALS_OPTIONAL_LAST_VALUE_HPP
3 #include <optional>
4 #include <utility>
5 
6 namespace sig {
7 
9 
12 template <typename T>
14  public:
16  using Result_type = std::optional<T>;
17 
18  public:
23  template <typename InputIterator>
24  auto operator()(InputIterator first, InputIterator last) const
25  -> Result_type
26  {
27  if (first == last)
28  return {std::nullopt};
29  auto temp = T();
30  while (first != last) {
31  temp = *first;
32  ++first;
33  }
34  return {std::move(temp)};
35  }
36 };
37 
39 
40 template <>
41 class Optional_last_value<void> {
42  public:
44  using Result_type = void;
45 
46  public:
49  template <typename InputIterator>
50  auto operator()(InputIterator first, InputIterator last) const
51  -> Result_type
52  {
53  while (first != last) {
54  *first;
55  ++first;
56  }
57  }
58 };
59 
60 } // namespace sig
61 #endif // SIGNALS_OPTIONAL_LAST_VALUE_HPP
sig::Optional_last_value< void >::operator()
auto operator()(InputIterator first, InputIterator last) const -> Result_type
Definition: optional_last_value.hpp:50
sig::Optional_last_value::operator()
auto operator()(InputIterator first, InputIterator last) const -> Result_type
Definition: optional_last_value.hpp:24
sig
Definition: connection.hpp:8
sig::Optional_last_value< void >::Result_type
void Result_type
Type of object the iterator range points to.
Definition: optional_last_value.hpp:44
sig::Optional_last_value
A functor class that returns the last value in an iterator range.
Definition: optional_last_value.hpp:13
sig::Optional_last_value::Result_type
std::optional< T > Result_type
Type of object the iterator range points to.
Definition: optional_last_value.hpp:16