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 };
262  template<class Included>
264  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-merge_delay_error.hpp>");
265  };
266 };
267 
269  template<class Included>
271  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-multicast.hpp>");
272  };
273 };
274 
276  template<class Included>
278  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-observe_on.hpp>");
279  };
280 };
281 
283  template<class Included>
285  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-on_error_resume_next.hpp>");
286  };
287 };
288 
289 class empty_error: public std::runtime_error
290 {
291  public:
292  explicit empty_error(const std::string& msg):
293  std::runtime_error(msg)
294  {}
295 };
296 struct reduce_tag {
297  template<class Included>
299  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-reduce.hpp>");
300  };
301 };
302 struct first_tag : reduce_tag {};
303 struct last_tag : reduce_tag {};
304 struct sum_tag : reduce_tag {};
306 struct min_tag : reduce_tag {};
307 struct max_tag : reduce_tag {};
308 
310  template<class Included>
312  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-ref_count.hpp>");
313  };
314 };
315 
316 struct pairwise_tag {
317  template<class Included>
319  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-pairwise.hpp>");
320  };
321 };
322 
323 struct publish_tag {
324  template<class Included>
326  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-publish.hpp>");
327  };
328 };
330 
331 struct repeat_tag {
332  template<class Included>
334  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-repeat.hpp>");
335  };
336 };
337 
338 struct replay_tag {
339  template<class Included>
341  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-replay.hpp>");
342  };
343 };
344 
345 struct retry_tag {
346  template<class Included>
348  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-retry.hpp>");
349  };
350 };
351 
353  template<class Included>
355  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-sample_time.hpp>");
356  };
357 };
358 
359 struct scan_tag {
360  template<class Included>
362  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-scan.hpp>");
363  };
364 };
365 
367  template<class Included>
369  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-sequence_equal.hpp>");
370  };
371 };
372 
373 struct skip_tag {
374  template<class Included>
376  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip.hpp>");
377  };
378 };
379 
381  template<class Included>
383  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_while.hpp>");
384  };
385 };
386 
388  template<class Included>
390  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_last.hpp>");
391  };
392 };
393 
395  template<class Included>
397  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-skip_until.hpp>");
398  };
399 };
400 
402  template<class Included>
404  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-start_with.hpp>");
405  };
406 };
407 
409  template<class Included>
411  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-subscribe_on.hpp>");
412  };
413 };
414 
416  template<class Included>
418  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-switch_if_empty.hpp>");
419  };
420 };
422 
424  template<class Included>
426  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-switch_on_next.hpp>");
427  };
428 };
429 
430 struct take_tag {
431  template<class Included>
433  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take.hpp>");
434  };
435 };
436 
438  template<class Included>
440  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_last.hpp>");
441  };
442 };
443 
445  template<class Included>
447  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_while.hpp>");
448  };
449 };
450 
452  template<class Included>
454  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-take_until.hpp>");
455  };
456 };
457 
458 struct tap_tag {
459  template<class Included>
461  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-rap.hpp>");
462  };
463 };
464 
465 struct timeout_tag {
466  template<class Included>
468  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-timeout.hpp>");
469  };
470 };
471 
473  template<class Included>
475  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-time_interval.hpp>");
476  };
477 };
478 
480  template<class Included>
482  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-timestamp.hpp>");
483  };
484 };
485 
486 struct window_tag {
487  template<class Included>
489  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window.hpp>");
490  };
491 };
492 
494  template<class Included>
496  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_time.hpp>");
497  };
498 };
499 
501  template<class Included>
503  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_time_count.hpp>");
504  };
505 };
506 
508  template<class Included>
510  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-window_toggle.hpp>");
511  };
512 };
513 
515  template<class Included>
517  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-with_latest_from.hpp>");
518  };
519 };
520 
521 struct zip_tag {
522  template<class Included>
524  static_assert(Included::value, "missing include: please #include <rxcpp/operators/rx-zip.hpp>");
525  };
526 };
527 
528 }
529 
531 #include "operators/rx-publish.hpp"
533 
534 #endif
Definition: rx-operators.hpp:126
Definition: rx-operators.hpp:366
Definition: rx-operators.hpp:171
Definition: rx-operators.hpp:248
Definition: rx-operators.hpp:380
Definition: rx-operators.hpp:432
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:387
Definition: rx-operators.hpp:458
Definition: rx-all.hpp:26
empty_error(const std::string &msg)
Definition: rx-operators.hpp:292
Definition: rx-operators.hpp:250
typename std::decay< T >::type::value_type value_type_t
Definition: rx-util.hpp:47
operator_factory(tuple_type an)
Definition: rx-operators.hpp:78
Definition: rx-operators.hpp:329
Definition: rx-operators.hpp:187
Definition: rx-operators.hpp:208
Definition: rx-operators.hpp:444
Definition: rx-operators.hpp:157
Definition: rx-operators.hpp:282
static T value(AN **...)
Definition: rx-operators.hpp:57
auto observable_member(Tag, AN &&... an) -> decltype(Overload::member(std::forward< AN >(an)...))
Definition: rx-operators.hpp:63
Definition: rx-operators.hpp:180
Definition: rx-operators.hpp:389
Definition: rx-operators.hpp:289
Definition: rx-operators.hpp:69
Definition: rx-operators.hpp:296
Definition: rx-operators.hpp:309
Definition: rx-operators.hpp:352
Definition: rx-operators.hpp:347
Definition: rx-operators.hpp:340
Definition: rx-operators.hpp:410
Definition: rx-operators.hpp:421
Definition: rx-operators.hpp:500
Definition: rx-operators.hpp:394
Definition: rx-operators.hpp:472
Definition: rx-operators.hpp:331
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:521
Definition: rx-operators.hpp:311
Definition: rx-operators.hpp:345
typename std::decay< T >::type decay_t
Definition: rx-util.hpp:48
Definition: rx-operators.hpp:284
Definition: rx-operators.hpp:194
Definition: rx-operators.hpp:236
Definition: rx-operators.hpp:159
Definition: rx-operators.hpp:47
Definition: rx-operators.hpp:509
Definition: rx-operators.hpp:375
Definition: rx-operators.hpp:373
Definition: rx-operators.hpp:316
Definition: rx-operators.hpp:138
Definition: rx-operators.hpp:451
Definition: rx-operators.hpp:304
Definition: rx-operators.hpp:302
Definition: rx-operators.hpp:354
Definition: rx-operators.hpp:227
Definition: rx-operators.hpp:333
Definition: rx-operators.hpp:474
Definition: rx-operators.hpp:382
Definition: rx-operators.hpp:241
Definition: rx-operators.hpp:117
Definition: rx-operators.hpp:213
Definition: rx-operators.hpp:430
Definition: rx-operators.hpp:38
Definition: rx-operators.hpp:222
Definition: rx-operators.hpp:268
Definition: rx-operators.hpp:523
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:425
Definition: rx-operators.hpp:129
Definition: rx-operators.hpp:437
Definition: rx-operators.hpp:359
Definition: rx-operators.hpp:243
Definition: rx-operators.hpp:479
Definition: rx-operators.hpp:136
Definition: rx-operators.hpp:131
Definition: rx-operators.hpp:206
Definition: rx-operators.hpp:229
Definition: rx-operators.hpp:303
T value_type
Definition: rx-operators.hpp:18
Definition: rx-operators.hpp:192
Definition: rx-operators.hpp:270
Definition: rx-operators.hpp:103
Definition: rx-operators.hpp:488
Definition: rx-operators.hpp:396
source
Definition: rx-operators.hpp:91
Definition: rx-operators.hpp:486
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:307
Definition: rx-operators.hpp:220
Definition: rx-operators.hpp:481
Definition: rx-operators.hpp:185
Definition: rx-operators.hpp:121
Definition: rx-operators.hpp:325
Definition: rx-operators.hpp:465
Definition: rx-operators.hpp:446
Definition: rx-operators.hpp:261
Definition: rx-operators.hpp:275
typename types_checked_from< TN... >::type types_checked_t
Definition: rx-util.hpp:176
Definition: rx-operators.hpp:493
Definition: rx-operators.hpp:368
Definition: rx-operators.hpp:453
Definition: rx-operators.hpp:460
Definition: rx-operators.hpp:150
Definition: rx-operators.hpp:152
Definition: rx-operators.hpp:338
Definition: rx-operators.hpp:516
Definition: rx-operators.hpp:495
Definition: rx-operators.hpp:467
Definition: rx-operators.hpp:263
Definition: rx-operators.hpp:16
auto operator()(Observable source) const -> decltype(rxu::apply(std::tuple_cat(std::make_tuple(tag_type
Definition: rx-operators.hpp:90
Definition: rx-operators.hpp:361
Definition: rx-operators.hpp:164
Definition: rx-operators.hpp:323
Definition: rx-operators.hpp:507
Definition: rx-operators.hpp:215
Definition: rx-operators.hpp:417
Definition: rx-operators.hpp:403
Definition: rx-operators.hpp:423
Definition: rx-operators.hpp:119
Definition: rx-operators.hpp:306
Turn a cold observable hot and allow connections to the source to be independent of subscriptions...
Definition: rx-operators.hpp:178
rxu::value_type_t< delayed_type< T, AN... > > delayed_type_t
Definition: rx-operators.hpp:60
Definition: rx-operators.hpp:439
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:305
Definition: rx-operators.hpp:127
Definition: rx-operators.hpp:415
Definition: rx-operators.hpp:318
allows connections to the source to be independent of subscriptions.
Definition: rx-operators.hpp:277
Definition: rx-operators.hpp:408
T value_type
Definition: rx-operators.hpp:57
Definition: rx-operators.hpp:401
Definition: rx-operators.hpp:514
Definition: rx-operators.hpp:298