RxCpp
The Reactive Extensions for Native (RxCpp) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators in both C and C++.
rx-ignore_elements.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2 
3 #pragma once
4 
16 #if !defined(RXCPP_OPERATORS_RX_IGNORE_ELEMENTS_HPP)
17 #define RXCPP_OPERATORS_RX_IGNORE_ELEMENTS_HPP
18 
19 #include "../rx-includes.hpp"
20 
21 namespace rxcpp {
22 
23 namespace operators {
24 
25 namespace detail {
26 
27 template<class... AN>
28 struct ignore_elements_invalid_arguments {};
29 
30 template<class... AN>
31 struct ignore_elements_invalid : public rxo::operator_base<ignore_elements_invalid_arguments<AN...>> {
32  using type = observable<ignore_elements_invalid_arguments<AN...>, ignore_elements_invalid<AN...>>;
33 };
34 template<class... AN>
35 using ignore_elements_invalid_t = typename ignore_elements_invalid<AN...>::type;
36 
37 template<class T>
38 struct ignore_elements {
39  typedef rxu::decay_t<T> source_value_type;
40 
41  template<class Subscriber>
42  struct ignore_elements_observer
43  {
44  typedef ignore_elements_observer<Subscriber> this_type;
45  typedef source_value_type value_type;
46  typedef rxu::decay_t<Subscriber> dest_type;
47  typedef observer<value_type, this_type> observer_type;
48  dest_type dest;
49 
50  ignore_elements_observer(dest_type d)
51  : dest(d)
52  {
53  }
54 
55  void on_next(source_value_type) const {
56  // no-op; ignore element
57  }
58 
59  void on_error(std::exception_ptr e) const {
60  dest.on_error(e);
61  }
62 
63  void on_completed() const {
64  dest.on_completed();
65  }
66 
67  static subscriber<value_type, observer_type> make(dest_type d) {
68  return make_subscriber<value_type>(d, this_type(d));
69  }
70  };
71 
72  template<class Subscriber>
73  auto operator()(Subscriber dest) const
74  -> decltype(ignore_elements_observer<Subscriber>::make(std::move(dest))) {
75  return ignore_elements_observer<Subscriber>::make(std::move(dest));
76  }
77 };
78 
79 }
80 
83 template<class... AN>
84 auto ignore_elements(AN&&... an)
86  return operator_factory<ignore_elements_tag, AN...>(std::make_tuple(std::forward<AN>(an)...));
87 }
88 
89 }
90 
91 template<>
93 {
94  template<class Observable,
95  class SourceValue = rxu::value_type_t<Observable>,
96  class Enabled = rxu::enable_if_all_true_type_t<
98  class IgnoreElements = rxo::detail::ignore_elements<SourceValue>>
99  static auto member(Observable&& o)
100  -> decltype(o.template lift<SourceValue>(IgnoreElements())) {
101  return o.template lift<SourceValue>(IgnoreElements());
102  }
103 
104  template<class... AN>
105  static operators::detail::ignore_elements_invalid_t<AN...> member(AN...) {
106  std::terminate();
107  return {};
108  static_assert(sizeof...(AN) == 10000, "ignore_elements takes no arguments");
109  }
110 };
111 
112 }
113 
114 #endif
Definition: rx-all.hpp:26
typename std::decay< T >::type::value_type value_type_t
Definition: rx-util.hpp:35
Definition: rx-operators.hpp:69
auto AN
Definition: rx-finally.hpp:105
static auto member(Observable &&o) -> decltype(o.template lift< SourceValue >(IgnoreElements()))
Definition: rx-ignore_elements.hpp:99
Definition: rx-operators.hpp:47
Definition: rx-operators.hpp:241
typename std::enable_if< all_true_type< BN... >::value >::type enable_if_all_true_type_t
Definition: rx-util.hpp:114
static operators::detail::ignore_elements_invalid_t< AN... > member(AN...)
Definition: rx-ignore_elements.hpp:105
auto ignore_elements(AN &&...an) -> operator_factory< ignore_elements_tag, AN... >
Do not emit any items from the source Observable, but allow termination notification (either onError ...
Definition: rx-ignore_elements.hpp:84
Definition: rx-predef.hpp:177