1 #include "rxcpp/rx.hpp"
2 // create alias' to simplify code
3 // these are owned by the user so that
4 // conflicts can be managed by the user.
5 namespace rx=rxcpp;
6 namespace rxu=rxcpp::util;
7
8 #include<string>
9
10 // At this time, RxCpp will fail to compile if the contents
11 // of the std namespace are merged into the global namespace
12 // DO NOT USE: 'using namespace std;'
13
14 #if 0
15 //
16 // println will insert values into the specified stream
17 //
18 template<class OStream>
19 struct println_function
20 {
21 OStream& os;
22 println_function(OStream& os) : os(os) {}
23
24 template<class... TN>
25 void operator()(const TN&... tn) const {
26 bool inserts[] = {(os << tn, true)...};
27 os << std::endl;
28 }
29
30 template<class... TN>
31 void operator()(const std::tuple<TN...>& tpl) const {
32 apply(tpl, *this);
33 }
34 };
35 template<class OStream>
36 auto println(OStream& os)
37 -> println_function<OStream> {
38 return println_function<OStream>(os);
39 }
40 #endif
41
42 #ifdef UNICODE
wmain()43 int wmain()
44 #else
45 int main()
46 #endif
47 {
48 auto get_names = [](){return rx::observable<>::from<std::string>(
49 "Matthew",
50 "Aaron"
51 );};
52
53 std::cout << "===== println stream of std::string =====" << std::endl;
54 auto hello_str = [&](){return get_names().map([](std::string n){
55 return "Hello, " + n + "!";
56 }).as_dynamic();};
57
58 hello_str().subscribe(rxu::println(std::cout));
59
60 std::cout << "===== println stream of std::tuple =====" << std::endl;
61 auto hello_tpl = [&](){return get_names().map([](std::string n){
62 return std::make_tuple("Hello, ", n, "! (", n.size(), ")");
63 }).as_dynamic();};
64
65 hello_tpl().subscribe(rxu::println(std::cout));
66
67 hello_tpl().subscribe(rxu::print_followed_by(std::cout, " and "), rxu::endline(std::cout));
68 return 0;
69 }
70