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-subscribe.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 
53 #if !defined(RXCPP_OPERATORS_RX_SUBSCRIBE_HPP)
54 #define RXCPP_OPERATORS_RX_SUBSCRIBE_HPP
55 
56 #include "../rx-includes.hpp"
57 
58 namespace rxcpp {
59 
60 namespace operators {
61 
62 namespace detail {
63 
64 template<class Subscriber>
65 class subscribe_factory;
66 
67 template<class T, class I>
68 class subscribe_factory<subscriber<T, I>>
69 {
70  subscriber<T, I> scrbr;
71 public:
72  subscribe_factory(subscriber<T, I> s)
73  : scrbr(std::move(s))
74  {}
75  template<class Observable>
76  auto operator()(Observable&& source)
77  -> decltype(std::forward<Observable>(source).subscribe(std::move(scrbr))) {
78  return std::forward<Observable>(source).subscribe(std::move(scrbr));
79  }
80 };
81 
82 }
83 
86 template<class T, class... ArgN>
87 auto subscribe(ArgN&&... an)
88  -> detail::subscribe_factory<decltype (make_subscriber<T>(std::forward<ArgN>(an)...))> {
89  return detail::subscribe_factory<decltype (make_subscriber<T>(std::forward<ArgN>(an)...))>
90  (make_subscriber<T>(std::forward<ArgN>(an)...));
91 }
92 
93 namespace detail {
94 
95 class dynamic_factory
96 {
97 public:
98  template<class Observable>
99  auto operator()(Observable&& source)
101  return observable<rxu::value_type_t<rxu::decay_t<Observable>>>(std::forward<Observable>(source));
102  }
103 };
104 
105 }
106 
117 inline auto as_dynamic()
118  -> detail::dynamic_factory {
119  return detail::dynamic_factory();
120 }
121 
122 namespace detail {
123 
124 class blocking_factory
125 {
126 public:
127  template<class Observable>
128  auto operator()(Observable&& source)
129  -> decltype(std::forward<Observable>(source).as_blocking()) {
130  return std::forward<Observable>(source).as_blocking();
131  }
132 };
133 
134 }
135 
144 inline auto as_blocking()
145  -> detail::blocking_factory {
146  return detail::blocking_factory();
147 }
148 
149 
150 }
151 
152 }
153 
154 #endif
Definition: rx-all.hpp:26
auto as_blocking() -> detail::blocking_factory
Definition: rx-subscribe.hpp:144
a source of values. subscribe or use one of the operator methods that return a new observable...
Definition: rx-observable.hpp:510
auto as_dynamic() -> detail::dynamic_factory
Definition: rx-subscribe.hpp:117
auto subscribe(ArgN &&...an) -> detail::subscribe_factory< decltype(make_subscriber< T >(std::forward< ArgN >(an)...))>
Subscribe will cause the source observable to emit values to the provided subscriber.
Definition: rx-subscribe.hpp:87