summaryrefslogtreecommitdiff
path: root/Rx/v2/src/rxcpp/rx-observer.hpp
blob: 369339dc8938b60cace4e0f8911d2bee98a18e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.

#pragma once

#if !defined(RXCPP_RX_OBSERVER_HPP)
#define RXCPP_RX_OBSERVER_HPP

#include "rx-includes.hpp"

namespace rxcpp {


struct tag_observer {};
template<class T>
struct observer_root : public subscription_base
{
    typedef T value_type;
    typedef composite_subscription subscription_type;
    typedef typename subscription_type::weak_subscription weak_subscription;
    typedef tag_observer observer_tag;
};
template<class T>
struct observer_base : public observer_root<T>
{
private:
    typedef observer_base this_type;

    mutable typename this_type::subscription_type s;

public:
    observer_base()
    {
    }
    observer_base(typename this_type::subscription_type s)
        : s(std::move(s))
    {
    }
    observer_base(const observer_base& o)
        : s(o.s)
    {
    }
    observer_base(observer_base&& o)
        : s(std::move(o.s))
    {
    }
    observer_base& operator=(observer_base o) {
        swap(o);
        return *this;
    }
    void swap(observer_base& o) {
        using std::swap;
        swap(s, o.s);
    }
    typename this_type::subscription_type get_subscription() {
        return s;
    }
    bool is_subscribed() const {
        return s.is_subscribed();
    }
    typename this_type::weak_subscription add(dynamic_subscription ds) const {
        return s.add(std::move(ds));
    }
    void remove(typename this_type::weak_subscription ws) const {
        s.remove(ws);
    }
    void unsubscribe() const {
        s.unsubscribe();
    }
};
template<class T>
class is_observer
{
    template<class C>
    static typename C::observer_tag check(int);
    template<class C>
    static void check(...);
public:
    static const bool value = std::is_convertible<decltype(check<T>(0)), tag_observer>::value;
};

namespace detail {
template<class T>
struct OnNextEmpty
{
    void operator()(const T&) const {}
};
struct OnErrorEmpty
{
    void operator()(std::exception_ptr) const {}
};
struct OnCompletedEmpty
{
    void operator()() const {}
};

template<class T, class F>
struct is_on_next_of
{
    struct not_void {};
    template<class CT, class CF>
    static auto check(int) -> decltype((*(CF*)nullptr)(*(CT*)nullptr));
    template<class CT, class CF>
    static not_void check(...);

    typedef decltype(check<T, F>(0)) detail_result;
    static const bool value = std::is_same<detail_result, void>::value;
};

template<class F>
struct is_on_error
{
    struct not_void {};
    template<class CF>
    static auto check(int) -> decltype((*(CF*)nullptr)(*(std::exception_ptr*)nullptr));
    template<class CF>
    static not_void check(...);

    static const bool value = std::is_same<decltype(check<F>(0)), void>::value;
};

template<class F>
struct is_on_completed
{
    struct not_void {};
    template<class CF>
    static auto check(int) -> decltype((*(CF*)nullptr)());
    template<class CF>
    static not_void check(...);

    static const bool value = std::is_same<decltype(check<F>(0)), void>::value;
};

}

template<class T>
class dynamic_observer : public observer_base<T>
{
public:
    typedef std::function<void(T)> on_next_t;
    typedef std::function<void(std::exception_ptr)> on_error_t;
    typedef std::function<void()> on_completed_t;

private:
    typedef observer_base<T> base_type;

    on_next_t onnext;
    on_error_t onerror;
    on_completed_t oncompleted;

    struct tag_this_type {};
    struct tag_function {};

    template<class Arg>
    struct resolve_tag
    {
        typedef typename std::conditional<std::is_same<typename std::decay<Arg>::type, dynamic_observer<T>>::value, tag_this_type,
                    typename std::conditional<is_subscription<Arg>::value, tag_subscription, tag_function>::type
                >::type type;
    };

    template<class Arg, class Tag = typename resolve_tag<Arg>::type>
    struct resolve_cs;
    template<class Arg>
    struct resolve_cs<Arg, tag_this_type>
    {
        auto operator()(const Arg& a)
            -> decltype(a.cs) {
            return a.cs;
        }
        auto operator()(Arg&& a)
            -> decltype(a.cs) {
            return std::move(a.cs);
        }
    };
    template<class Arg>
    struct resolve_cs<Arg, tag_subscription>
    {
        Arg operator()(Arg a) {
            return std::move(a);
        }
    };
    template<class Arg>
    struct resolve_cs<Arg, tag_function>
    {
        composite_subscription operator()(const Arg& a) {
            return composite_subscription();
        }
    };

    template<class Arg, class Tag = typename resolve_tag<Arg>::type>
    struct resolve_onnext;
    template<class Arg>
    struct resolve_onnext<Arg, tag_this_type>
    {
        auto operator()(const Arg& a)
            -> decltype(a.onnext) {
            return a.onnext;
        }
        auto operator()(Arg&& a)
            -> decltype(a.onnext) {
            return std::move(a.onnext);
        }
    };
    template<class Arg>
    struct resolve_onnext<Arg, tag_subscription>
    {
        template<class Arg1>
        on_next_t operator()(const Arg1& a1) {
            return on_next_t();
        }
        template<class Arg1, class Arg2>
        Arg2 operator()(const Arg1&, Arg2 a2) {
            static_assert(detail::is_on_next_of<T, Arg2>::value || std::is_same<Arg2, std::nullptr_t>::value,
                "Function supplied for on_next must be a function with the signature void(T);");
            return std::move(a2);
        }
    };
    template<class Arg>
    struct resolve_onnext<Arg, tag_function>
    {
        template<class Arg1>
        Arg1 operator()(Arg1 a1) {
            static_assert(detail::is_on_next_of<T, Arg1>::value || std::is_same<Arg1, std::nullptr_t>::value,
                "Function supplied for on_next must be a function with the signature void(T);");
            return std::move(a1);
        }
        template<class Arg1, class Arg2>
        Arg operator()(Arg1 a1, const Arg2&) {
            static_assert(detail::is_on_next_of<T, Arg1>::value || std::is_same<Arg1, std::nullptr_t>::value,
                "Function supplied for on_next must be a function with the signature void(T);");
            return std::move(a1);
        }
    };

    template<class Arg, class Tag = typename resolve_tag<Arg>::type>
    struct resolve_onerror;
    template<class Arg>
    struct resolve_onerror<Arg, tag_this_type>
    {
        auto operator()(const Arg& a)
            -> decltype(a.onerror) {
            return a.onerror;
        }
        auto operator()(Arg&& a)
            -> decltype(a.onerror) {
            return std::move(a.onerror);
        }
    };
    template<class Arg>
    struct resolve_onerror<Arg, tag_subscription>
    {
        template<class Arg1>
        on_error_t operator()(const Arg1& a1) {
            return on_error_t();
        }
        template<class Arg1, class Arg2>
        Arg2 operator()(const Arg1&, Arg2 a2) {
            static_assert(detail::is_on_error<Arg2>::value || std::is_same<Arg2, std::nullptr_t>::value,
                "Function supplied for on_error must be a function with the signature void(std::exception_ptr);");
            return std::move(a2);
        }
    };
    template<class Arg>
    struct resolve_onerror<Arg, tag_function>
    {
        template<class Arg1>
        on_error_t operator()(const Arg1& a1) {
            return on_error_t();
        }
        template<class Arg1, class Arg2>
        Arg1 operator()(Arg1 a1, const Arg2&) {
            static_assert(detail::is_on_error<Arg1>::value || std::is_same<Arg1, std::nullptr_t>::value,
                "Function supplied for on_error must be a function with the signature void(std::exception_ptr);");
            return std::move(a1);
        }
    };

    template<class Arg, class Tag = typename resolve_tag<Arg>::type>
    struct resolve_oncompleted;
    template<class Arg>
    struct resolve_oncompleted<Arg, tag_this_type>
    {
        auto operator()(const Arg& a)
            -> decltype(a.oncompleted) {
            return a.oncompleted;
        }
        auto operator()(Arg&& a)
            -> decltype(a.oncompleted) {
            return std::move(a.oncompleted);
        }
    };
    template<class Arg>
    struct resolve_oncompleted<Arg, tag_subscription>
    {
        template<class Arg1>
        on_completed_t operator()(const Arg1& a1) {
            return on_completed_t();
        }
        template<class Arg1, class Arg2>
        Arg2 operator()(const Arg1&, Arg2 a2) {
            static_assert(detail::is_on_completed<Arg2>::value || std::is_same<Arg2, std::nullptr_t>::value,
                "Function supplied for on_completed must be a function with the signature void();");
            return std::move(a2);
        }
    };
    template<class Arg>
    struct resolve_oncompleted<Arg, tag_function>
    {
        template<class Arg1>
        on_completed_t operator()(const Arg1& a1) {
            return on_completed_t();
        }
        template<class Arg1, class Arg2>
        Arg1 operator()(Arg1 a1, const Arg2&) {
            static_assert(detail::is_on_completed<Arg1>::value || std::is_same<Arg1, std::nullptr_t>::value,
                "Function supplied for on_completed must be a function with the signature void();");
            return std::move(a1);
        }
    };

public:
    dynamic_observer()
    {
    }

    template<class Arg>
    explicit dynamic_observer(Arg a)
        : base_type(resolve_cs<Arg>()(a))
        , onnext(resolve_onnext<Arg>()(a))
        , onerror(resolve_onerror<Arg>()(a))
        , oncompleted(resolve_oncompleted<Arg>()(a))
    {
    }

    template<class Arg1, class Arg2>
    dynamic_observer(Arg1 a1, Arg2 a2)
        : base_type(resolve_cs<Arg1>()(a1))
        , onnext(resolve_onnext<Arg1>()(a1, a2))
        , onerror(resolve_onerror<Arg1>()(a2, on_error_t()))
        , oncompleted(resolve_oncompleted<Arg1>()(on_completed_t(), on_completed_t()))
    {
    }

    template<class Arg1, class Arg2, class Arg3>
    dynamic_observer(Arg1 a1, Arg2 a2, Arg3 a3)
        : base_type(resolve_cs<Arg1>()(a1))
        , onnext(resolve_onnext<Arg1>()(a1, a2))
        , onerror(resolve_onerror<Arg1>()(a2, a3))
        , oncompleted(resolve_oncompleted<Arg1>()(a3, on_completed_t()))
    {
    }

    template<class OnNext, class OnError, class OnCompleted>
    dynamic_observer(composite_subscription cs, OnNext n, OnError e, OnCompleted c)
        : base_type(std::move(cs))
        , onnext(std::move(n))
        , onerror(std::move(e))
        , oncompleted(std::move(c))
    {
        static_assert(detail::is_on_next_of<T, OnNext>::value || std::is_same<OnNext, std::nullptr_t>::value,
                "Function supplied for on_next must be a function with the signature void(T);");
        static_assert(detail::is_on_error<OnError>::value || std::is_same<OnError, std::nullptr_t>::value,
                "Function supplied for on_error must be a function with the signature void(std::exception_ptr);");
        static_assert(detail::is_on_completed<OnCompleted>::value || std::is_same<OnCompleted, std::nullptr_t>::value,
                "Function supplied for on_completed must be a function with the signature void();");
    }

    dynamic_observer& operator=(dynamic_observer o) {
        swap(o);
        return *this;
    }
    void swap(dynamic_observer& o) {
        using std::swap;
        observer_base<T>::swap(o);
        swap(onnext, o.onnext);
        swap(onerror, o.onerror);
        swap(oncompleted, o.oncompleted);
    }

    void on_next(T t) const {
        if (onnext) {
            onnext(std::move(t));
        }
    }
    void on_error(std::exception_ptr e) const {
        if (onerror) {
            onerror(e);
        }
    }
    void on_completed() const {
        if (oncompleted) {
            oncompleted();
        }
    }
};

template<class T, class OnNext, class OnError = detail::OnErrorEmpty, class OnCompleted = detail::OnCompletedEmpty>
class static_observer : public observer_base<T>
{
public:
    typedef OnNext on_next_t;
    typedef OnError on_error_t;
    typedef OnCompleted on_completed_t;

private:
    on_next_t onnext;
    on_error_t onerror;
    on_completed_t oncompleted;

public:
    static_assert(detail::is_on_next_of<T, on_next_t>::value,     "Function supplied for on_next must be a function with the signature void(T);");
    static_assert(detail::is_on_error<on_error_t>::value,         "Function supplied for on_error must be a function with the signature void(std::exception_ptr);");
    static_assert(detail::is_on_completed<on_completed_t>::value, "Function supplied for on_completed must be a function with the signature void();");

    explicit static_observer(on_next_t n = on_next_t(), on_error_t e = on_error_t(), on_completed_t c = on_completed_t())
        : observer_base<T>(composite_subscription())
        , onnext(std::move(n))
        , onerror(std::move(e))
        , oncompleted(std::move(c))
    {
    }
    explicit static_observer(composite_subscription cs, on_next_t n = on_next_t(), on_error_t e = on_error_t(), on_completed_t c = on_completed_t())
        : observer_base<T>(std::move(cs))
        , onnext(std::move(n))
        , onerror(std::move(e))
        , oncompleted(std::move(c))
    {
    }
    static_observer(const static_observer& o)
        : observer_base<T>(o)
        , onnext(o.onnext)
        , onerror(o.onerror)
        , oncompleted(o.oncompleted)
    {
    }
    static_observer(static_observer&& o)
        : observer_base<T>(std::move(o))
        , onnext(std::move(o.onnext))
        , onerror(std::move(o.onerror))
        , oncompleted(std::move(o.oncompleted))
    {
    }
    static_observer& operator=(static_observer o) {
        swap(o);
        return *this;
    }
    void swap(static_observer& o) {
        using std::swap;
        observer_base<T>::swap(o);
        swap(onnext, o.onnext);
        swap(onerror, o.onerror);
        swap(oncompleted, o.oncompleted);
    }

    void on_next(T t) const {
        onnext(std::move(t));
    }
    void on_error(std::exception_ptr e) const {
        onerror(e);
    }
    void on_completed() const {
        oncompleted();
    }
};

template<class T, class I>
class observer : public observer_root<T>
{
    typedef observer this_type;
    typedef typename std::conditional<is_observer<I>::value, I, dynamic_observer<T>>::type inner_t;

    struct detacher
    {
        ~detacher()
        {
            if (that) {
                that->unsubscribe();
            }
        }
        detacher(const observer<T,I>* that)
            : that(that)
        {
        }
        const observer<T,I>* that;
    };

    inner_t inner;
public:
    ~observer()
    {
    }
    observer(inner_t inner)
        : inner(std::move(inner))
    {
    }
    void on_next(T t) const {
        if (is_subscribed()) {
            detacher protect(this);
            inner.on_next(std::move(t));
            protect.that = nullptr;
        }
    }
    void on_error(std::exception_ptr e) const {
        if (is_subscribed()) {
            detacher protect(this);
            inner.on_error(e);
        }
    }
    void on_completed() const {
        if (is_subscribed()) {
            detacher protect(this);
            inner.on_completed();
        }
    }
    typename this_type::subscription_type get_subscription() {
        return inner.get_subscription();
    }
    bool is_subscribed() const {
        return inner.is_subscribed();
    }
    typename this_type::weak_subscription add(dynamic_subscription ds) const {
        return inner.add(std::move(ds));
    }
    void remove(typename this_type::weak_subscription ws) const {
        inner.remove(ws);
    }
    void unsubscribe() const {
        inner.unsubscribe();
    }
};
template<class T>
class observer<T, void> : public observer_root<T>
{
    typedef observer this_type;
public:
    observer()
    {
    }
    void on_next(T&&) const {
    }
    void on_error(std::exception_ptr) const {
    }
    void on_completed() const {
    }
    typename this_type::subscription_type get_subscription() {
        static typename this_type::subscription_type result;
        result.unsubscribe();
        return result;
    }
    bool is_subscribed() const {
        return false;
    }
    typename this_type::weak_subscription add(dynamic_subscription ds) const {
        ds.unsubscribe();
        return typename this_type::weak_subscription();
    }
    void remove(typename this_type::weak_subscription) const {
    }
    void unsubscribe() const {
    }
};

template<class T>
auto make_observer()
    ->     observer<T, void> {
    return observer<T, void>();
}

namespace detail {

struct tag_require_observer {};

struct tag_require_function {};

template<class I>
auto make_observer(I i, tag_observer&&)
    ->      observer<typename I::value_type, I> {
    return  observer<typename I::value_type, I>(std::move(i));
}

struct tag_function {};
template<class T, class OnNext>
auto make_observer(OnNext n, tag_function&&)
    ->      observer<T, static_observer<T, OnNext>> {
    return  observer<T, static_observer<T, OnNext>>(
                        static_observer<T, OnNext>(std::move(n)));
}

template<class T, class OnNext, class OnError>
auto make_observer(OnNext n, OnError e, tag_function&&)
    ->      observer<T, static_observer<T, OnNext, OnError>> {
    return  observer<T, static_observer<T, OnNext, OnError>>(
                        static_observer<T, OnNext, OnError>(std::move(n), std::move(e)));
}

template<class T, class OnNext, class OnError, class OnCompleted>
auto make_observer(OnNext n, OnError e, OnCompleted c, tag_function&&)
    ->      observer<T, static_observer<T, OnNext, OnError, OnCompleted>> {
    return  observer<T, static_observer<T, OnNext, OnError, OnCompleted>>(
                        static_observer<T, OnNext, OnError, OnCompleted>(std::move(n), std::move(e), std::move(c)));
}

template<class T, class OnNext>
auto make_observer(composite_subscription cs, OnNext n, tag_subscription&&)
    ->      observer<T, static_observer<T, OnNext>> {
    return  observer<T, static_observer<T, OnNext>>(
                        static_observer<T, OnNext>(std::move(cs), std::move(n)));
}

template<class T, class OnNext, class OnError>
auto make_observer(composite_subscription cs, OnNext n, OnError e, tag_subscription&&)
    ->      observer<T, static_observer<T, OnNext, OnError>> {
    return  observer<T, static_observer<T, OnNext, OnError>>(
                        static_observer<T, OnNext, OnError>(std::move(cs), std::move(n), std::move(e)));
}

}

template<class Arg>
auto make_observer(Arg a)
    -> decltype(detail::make_observer(std::move(a), typename std::conditional<is_observer<Arg>::value, tag_observer, detail::tag_require_observer>::type())) {
    return      detail::make_observer(std::move(a), typename std::conditional<is_observer<Arg>::value, tag_observer, detail::tag_require_observer>::type());
}

template<class T, class Arg>
auto make_observer(Arg a)
    -> decltype(detail::make_observer<T>(std::move(a), typename std::conditional<is_observer<Arg>::value, detail::tag_require_function, detail::tag_function>::type())) {
    return      detail::make_observer<T>(std::move(a), typename std::conditional<is_observer<Arg>::value, detail::tag_require_function, detail::tag_function>::type());
}

template<class T, class Arg1, class Arg2>
auto make_observer(Arg1 a1, Arg2 a2)
    -> decltype(detail::make_observer<T>(std::move(a1), std::move(a2), typename std::conditional<is_subscription<Arg1>::value, tag_subscription, detail::tag_function>::type())) {
    return      detail::make_observer<T>(std::move(a1), std::move(a2), typename std::conditional<is_subscription<Arg1>::value, tag_subscription, detail::tag_function>::type());
}

template<class T, class Arg1, class Arg2, class Arg3>
auto make_observer(Arg1 a1, Arg2 a2, Arg3 a3)
    -> decltype(detail::make_observer<T>(std::move(a1), std::move(a2), std::move(a3), typename std::conditional<is_subscription<Arg1>::value, tag_subscription, detail::tag_function>::type())) {
    return      detail::make_observer<T>(std::move(a1), std::move(a2), std::move(a3), typename std::conditional<is_subscription<Arg1>::value, tag_subscription, detail::tag_function>::type());
}

template<class T, class OnNext, class OnError, class OnCompleted>
auto make_observer(composite_subscription cs, OnNext n, OnError e, OnCompleted c)
    ->      observer<T, static_observer<T, OnNext, OnError, OnCompleted>> {
    return  observer<T, static_observer<T, OnNext, OnError, OnCompleted>>(
                        static_observer<T, OnNext, OnError, OnCompleted>(std::move(cs), std::move(n), std::move(e), std::move(c)));
}

template<class T, class OnNext>
auto make_observer_dynamic(OnNext n)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(n)));
}
template<class T, class OnNext, class OnError>
auto make_observer_dynamic(OnNext n, OnError e)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(n), std::move(e)));
}
template<class T, class OnNext, class OnError, class OnCompleted>
auto make_observer_dynamic(OnNext n, OnError e, OnCompleted c)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(n), std::move(e), std::move(c)));
}

template<class T, class OnNext>
auto make_observer_dynamic(composite_subscription cs, OnNext n)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(cs), std::move(n)));
}
template<class T, class OnNext, class OnError>
auto make_observer_dynamic(composite_subscription cs, OnNext n, OnError e)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(cs), std::move(n), std::move(e)));
}
template<class T, class OnNext, class OnError, class OnCompleted>
auto make_observer_dynamic(composite_subscription cs, OnNext n, OnError e, OnCompleted c)
    ->      observer<T> {
    return  observer<T>(dynamic_observer<T>(std::move(cs), std::move(n), std::move(e), std::move(c)));
}

}

#endif