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-operators.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 
5 #if !defined(RXCPP_RX_OPERATORS_HPP)
6 #define RXCPP_RX_OPERATORS_HPP
7 
8 #include "rx-includes.hpp"
9 
10 namespace rxcpp {
11 
12 namespace operators {
13 
14 struct tag_operator {};
15 template<class T>
17 {
18  typedef T value_type;
20 };
21 
22 namespace detail {
23 
24 template<class T, class =rxu::types_checked>
25 struct is_operator : std::false_type
26 {
27 };
28 
29 template<class T>
30 struct is_operator<T, rxu::types_checked_t<typename T::operator_tag>>
31  : std::is_convertible<typename T::operator_tag*, tag_operator*>
32 {
33 };
34 
35 }
36 
37 template<class T, class Decayed = rxu::decay_t<T>>
38 struct is_operator : detail::is_operator<Decayed>
39 {
40 };
41 
42 
43 }
44 namespace rxo=operators;
45 
46 template<class Tag>
48 {
49  template<class... AN>
50  static auto member(AN&&...) ->
51  typename Tag::template include_header<std::false_type> {
52  return typename Tag::template include_header<std::false_type>();
53  }
54 };
55 
56 template<class T, class... AN>
57 struct delayed_type{using value_type = T; static T value(AN**...) {return T{};}};
58 
59 template<class T, class... AN>
61 
62 template<class Tag, class... AN, class Overload = member_overload<rxu::decay_t<Tag>>>
63 auto observable_member(Tag, AN&&... an) ->
64  decltype(Overload::member(std::forward<AN>(an)...)) {
65  return Overload::member(std::forward<AN>(an)...);
66 }
67 
68 template<class Tag, class... AN>
70 {
71  using this_type = operator_factory<Tag, AN...>;
72  using tag_type = rxu::decay_t<Tag>;
73  using tuple_type = std::tuple<rxu::decay_t<AN>...>;
74 
75  tuple_type an;
76 
77 public:
78  operator_factory(tuple_type an)
79  : an(std::move(an))
80  {
81  }
82 
83  template<class... ZN>
84  auto operator()(tag_type t, ZN&&... zn) const
85  -> decltype(observable_member(t, std::forward<ZN>(zn)...)) {
86  return observable_member(t, std::forward<ZN>(zn)...);
87  }
88 
89  template<class Observable>
90  auto operator()(Observable source) const
91  -> decltype(rxu::apply(std::tuple_cat(std::make_tuple(tag_type{}, source), (*(tuple_type*)nullptr)), (*(this_type*)nullptr))) {
92  return rxu::apply(std::tuple_cat(std::make_tuple(tag_type{}, source), an), *this);
93  }
94 };
95 
96 }
97 
98 #include "operators/rx-lift.hpp"
100 
101 namespace rxcpp {
102 
103 struct amb_tag {
104  template<class Included>
106  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-amb.hpp>");
107  };
108 };
109 
110 struct all_tag {
111  template<class Included>
113  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-all.hpp>");
114  };
115 };
116 
117 struct is_empty_tag : all_tag {};
118 
119 struct any_tag {
120  template<class Included>
122  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-any.hpp>");
123  };
124 };
125 
126 struct exists_tag : any_tag {};
127 struct contains_tag : any_tag {};
128 
130  template<class Included>
132  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-buffer_count.hpp>");
133  };
134 };
135 
137  template<class Included>
139  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-buffer_time.hpp>");
140  };
141 };
142 
144  template<class Included>
146  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-buffer_time_count.hpp>");
147  };
148 };
149 
151  template<class Included>
153  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-combine_latest.hpp>");
154  };
155 };
156 
157 struct concat_tag {
158  template<class Included>
160  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-concat.hpp>");
161  };
162 };
163 
165  template<class Included>
167  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-concat_map.hpp>");
168  };
169 };
170 
172  template<class Included>
174  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-connect_forever.hpp>");
175  };
176 };
177 
178 struct debounce_tag {
179  template<class Included>
181  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-debounce.hpp>");
182  };
183 };
184 
185 struct delay_tag {
186  template<class Included>
188  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-delay.hpp>");
189  };
190 };
191 
192 struct distinct_tag {
193  template<class Included>
195  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-distinct.hpp>");
196  };
197 };
198 
200  template<class Included>
202  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-distinct_until_changed.hpp>");
203  };
204 };
205 
207  template<class Included>
209  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-element_at.hpp>");
210  };
211 };
212 
213 struct filter_tag {
214  template<class Included>
216  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-filter.hpp>");
217  };
218 };
219 
220 struct finally_tag {
221  template<class Included>
223  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-finally.hpp>");
224  };
225 };
226 
227 struct flat_map_tag {
228  template<class Included>
230  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-flat_map.hpp>");
231  };
232 };
233 
234 struct group_by_tag {
235  template<class Included>
237  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-group_by.hpp>");
238  };
239 };
240 
242  template<class Included>
244  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-ignore_elements.hpp>");
245  };
246 };
247 
248 struct map_tag {
249  template<class Included>
251  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-map.hpp>");
252  };
253 };
254 
255 struct merge_tag {
256  template<class Included>
258  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-merge.hpp>");
259  };
260 };
261 
263  template<class Included>
265  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-multicast.hpp>");
266  };
267 };
268 
270  template<class Included>
272  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-observe_on.hpp>");
273  };
274 };
275 
277  template<class Included>
279  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-on_error_resume_next.hpp>");
280  };
281 };
282 
283 class empty_error: public std::runtime_error
284 {
285  public:
286  explicit empty_error(const std::string& msg):
287  std::runtime_error(msg)
288  {}
289 };
290 struct reduce_tag {
291  template<class Included>
293  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-reduce.hpp>");
294  };
295 };
296 struct first_tag : reduce_tag {};
297 struct last_tag : reduce_tag {};
298 struct sum_tag : reduce_tag {};
300 struct min_tag : reduce_tag {};
301 struct max_tag : reduce_tag {};
302 
304  template<class Included>
306  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-ref_count.hpp>");
307  };
308 };
309 
310 struct pairwise_tag {
311  template<class Included>
313  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-pairwise.hpp>");
314  };
315 };
316 
317 struct publish_tag {
318  template<class Included>
320  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-publish.hpp>");
321  };
322 };
324 
325 struct repeat_tag {
326  template<class Included>
328  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-repeat.hpp>");
329  };
330 };
331 
332 struct replay_tag {
333  template<class Included>
335  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-replay.hpp>");
336  };
337 };
338 
339 struct retry_tag {
340  template<class Included>
342  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-retry.hpp>");
343  };
344 };
345 
347  template<class Included>
349  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-sample_time.hpp>");
350  };
351 };
352 
353 struct scan_tag {
354  template<class Included>
356  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-scan.hpp>");
357  };
358 };
359 
361  template<class Included>
363  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-sequence_equal.hpp>");
364  };
365 };
366 
367 struct skip_tag {
368  template<class Included>
370  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip.hpp>");
371  };
372 };
373 
375  template<class Included>
377  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_last.hpp>");
378  };
379 };
380 
382  template<class Included>
384  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_until.hpp>");
385  };
386 };
387 
389  template<class Included>
391  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-start_with.hpp>");
392  };
393 };
394 
396  template<class Included>
398  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-subscribe_on.hpp>");
399  };
400 };
401 
403  template<class Included>
405  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-switch_if_empty.hpp>");
406  };
407 };
409 
411  template<class Included>
413  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-switch_on_next.hpp>");
414  };
415 };
416 
417 struct take_tag {
418  template<class Included>
420  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take.hpp>");
421  };
422 };
423 
425  template<class Included>
427  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_last.hpp>");
428  };
429 };
430 
432  template<class Included>
434  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_while.hpp>");
435  };
436 };
437 
439  template<class Included>
441  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_until.hpp>");
442  };
443 };
444 
445 struct tap_tag {
446  template<class Included>
448  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-rap.hpp>");
449  };
450 };
451 
452 struct timeout_tag {
453  template<class Included>
455  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-timeout.hpp>");
456  };
457 };
458 
460  template<class Included>
462  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-time_interval.hpp>");
463  };
464 };
465 
467  template<class Included>
469  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-timestamp.hpp>");
470  };
471 };
472 
473 struct window_tag {
474  template<class Included>
476  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window.hpp>");
477  };
478 };
479 
481  template<class Included>
483  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_time.hpp>");
484  };
485 };
486 
488  template<class Included>
490  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_time_count.hpp>");
491  };
492 };
493 
495  template<class Included>
497  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_toggle.hpp>");
498  };
499 };
500 
502  template<class Included>
504  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-with_latest_from.hpp>");
505  };
506 };
507 
508 struct zip_tag {
509  template<class Included>
511  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-zip.hpp>");
512  };
513 };
514 
515 }
516 
518 #include "operators/rx-publish.hpp"
520 
521 #endif
Definition: rx-operators.hpp:126
Definition: rx-operators.hpp:360
Definition: rx-operators.hpp:171
Definition: rx-operators.hpp:248
Definition: rx-operators.hpp:419
Definition: rx-operators.hpp:112
Definition: rx-operators.hpp:166
Definition: rx-operators.hpp:257
Definition: rx-operators.hpp:143
Subscribe will cause the source observable to emit values to the provided subscriber.
Definition: rx-operators.hpp:374
Definition: rx-operators.hpp:445
Definition: rx-all.hpp:26
empty_error(const std::string &msg)
Definition: rx-operators.hpp:286
Definition: rx-operators.hpp:250
typename std::decay< T >::type::value_type value_type_t
Definition: rx-util.hpp:35
operator_factory(tuple_type an)
Definition: rx-operators.hpp:78
Definition: rx-operators.hpp:323
Definition: rx-operators.hpp:187
Definition: rx-operators.hpp:208
Definition: rx-operators.hpp:431
Definition: rx-operators.hpp:157
Definition: rx-operators.hpp:276
Definition: rx-operators.hpp:180
Definition: rx-operators.hpp:376
Definition: rx-operators.hpp:283
Definition: rx-operators.hpp:69
Definition: rx-operators.hpp:290
Definition: rx-operators.hpp:303
Definition: rx-operators.hpp:346
Definition: rx-operators.hpp:341
Definition: rx-operators.hpp:334
Definition: rx-operators.hpp:397
Definition: rx-operators.hpp:408
Definition: rx-operators.hpp:487
Definition: rx-operators.hpp:381
rxu::value_type_t< delayed_type< T, AN... >> delayed_type_t
Definition: rx-operators.hpp:60
Definition: rx-operators.hpp:459
Definition: rx-operators.hpp:325
Definition: rx-operators.hpp:234
auto AN
Definition: rx-finally.hpp:105
Definition: rx-operators.hpp:255
static auto member(AN &&...) -> typename Tag::template include_header< std::false_type >
Definition: rx-operators.hpp:50
Definition: rx-operators.hpp:199
Definition: rx-operators.hpp:508
Definition: rx-operators.hpp:305
Definition: rx-operators.hpp:339
auto operator()(Observable source) const -> decltype(rxu::apply(std::tuple_cat(std::make_tuple(tag_type
Definition: rx-operators.hpp:90
typename std::decay< T >::type decay_t
Definition: rx-util.hpp:36
Definition: rx-operators.hpp:278
Definition: rx-operators.hpp:194
Definition: rx-operators.hpp:236
Definition: rx-operators.hpp:159
Definition: rx-operators.hpp:47
Definition: rx-operators.hpp:496
Definition: rx-operators.hpp:369
Definition: rx-operators.hpp:367
Definition: rx-operators.hpp:310
Definition: rx-operators.hpp:138
Definition: rx-operators.hpp:438
Definition: rx-operators.hpp:298
Definition: rx-operators.hpp:296
Definition: rx-operators.hpp:348
Definition: rx-operators.hpp:227
Definition: rx-operators.hpp:327
Definition: rx-operators.hpp:461
auto operator()(tag_type t, ZN &&...zn) const -> decltype(observable_member(t, std::forward< ZN >(zn)...))
Definition: rx-operators.hpp:84
Definition: rx-operators.hpp:241
Definition: rx-operators.hpp:117
Definition: rx-operators.hpp:213
Definition: rx-operators.hpp:417
Definition: rx-operators.hpp:38
Definition: rx-operators.hpp:222
Definition: rx-operators.hpp:262
Definition: rx-operators.hpp:510
Definition: rx-operators.hpp:412
Definition: rx-operators.hpp:129
Definition: rx-operators.hpp:424
Definition: rx-operators.hpp:353
Definition: rx-operators.hpp:243
Definition: rx-operators.hpp:466
Definition: rx-operators.hpp:136
Definition: rx-operators.hpp:131
Definition: rx-operators.hpp:206
Definition: rx-operators.hpp:229
Definition: rx-operators.hpp:297
T value_type
Definition: rx-operators.hpp:18
Definition: rx-operators.hpp:192
Definition: rx-operators.hpp:264
Definition: rx-operators.hpp:103
Definition: rx-operators.hpp:475
Definition: rx-operators.hpp:383
source
Definition: rx-operators.hpp:91
Definition: rx-operators.hpp:473
Definition: rx-operators.hpp:110
Definition: rx-operators.hpp:57
takes any function that will take a subscriber for this observable and produce a subscriber. this is intended to allow externally defined operators, that use make_subscriber, to be connected into the expression.
Definition: rx-operators.hpp:14
Definition: rx-operators.hpp:301
Definition: rx-operators.hpp:220
Definition: rx-operators.hpp:468
Definition: rx-operators.hpp:185
Definition: rx-operators.hpp:121
Definition: rx-operators.hpp:319
Definition: rx-operators.hpp:452
Definition: rx-operators.hpp:433
Definition: rx-operators.hpp:269
typename types_checked_from< TN... >::type types_checked_t
Definition: rx-util.hpp:164
Definition: rx-operators.hpp:480
Definition: rx-operators.hpp:362
Definition: rx-operators.hpp:440
Definition: rx-operators.hpp:447
Definition: rx-operators.hpp:150
Definition: rx-operators.hpp:152
Definition: rx-operators.hpp:332
Definition: rx-operators.hpp:503
Definition: rx-operators.hpp:482
Definition: rx-operators.hpp:454
Definition: rx-operators.hpp:16
Definition: rx-operators.hpp:355
auto observable_member(Tag, AN &&...an) -> decltype(Overload::member(std::forward< AN >(an)...))
Definition: rx-operators.hpp:63
Definition: rx-operators.hpp:164
Definition: rx-operators.hpp:317
Definition: rx-operators.hpp:494
Definition: rx-operators.hpp:215
Definition: rx-operators.hpp:404
Definition: rx-operators.hpp:390
Definition: rx-operators.hpp:410
Definition: rx-operators.hpp:119
Definition: rx-operators.hpp:300
Turn a cold observable hot and allow connections to the source to be independent of subscriptions...
Definition: rx-operators.hpp:178
Definition: rx-operators.hpp:426
Definition: rx-operators.hpp:173
Definition: rx-operators.hpp:105
tag_operator operator_tag
Definition: rx-operators.hpp:19
takes a connectable_observable source and uses a ref_count of the subscribers to control the connecti...
Definition: rx-operators.hpp:299
Definition: rx-operators.hpp:127
Definition: rx-operators.hpp:402
Definition: rx-operators.hpp:312
allows connections to the source to be independent of subscriptions.
Definition: rx-operators.hpp:271
Definition: rx-operators.hpp:395
T value_type
Definition: rx-operators.hpp:57
Definition: rx-operators.hpp:388
Definition: rx-operators.hpp:501
Definition: rx-operators.hpp:292