-
Notifications
You must be signed in to change notification settings - Fork 2
/
designcontext.h
1097 lines (950 loc) · 29.2 KB
/
designcontext.h
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
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <sstream>
namespace designcontextdef {
namespace shapes {
template<class Payload = void>
struct state;
struct subscription
{
bool is_stopped() const;
void insert(const subscription& s) const;
void erase(const subscription& s) const;
void insert(function<void()> stopper) const;
state<> make_state(subscription) const;
template<class Payload, class... ArgN>
state<Payload> make_state(subscription, ArgN... argn) const;
void stop() const;
};
template<class Payload>
struct state {
subscription lifetime;
Payload& get();
};
struct starter {
template<class Context>
subscription start(Context);
};
struct receiver {
template<class T>
void next(T);
template<class E>
void error(E);
void complete();
};
struct subscriber {
template<class Context>
receiver create(Context);
};
struct sender {
starter bind(subscriber);
};
struct lifter {
subscriber lift(subscriber);
};
struct adaptor {
sender adapt(sender);
};
struct terminator {
starter terminate(sender);
};
}
using std::decay_t;
template<class Payload = void>
struct state;
///
/// \brief A subscription represents the scope of an async operation.
/// Holds a set of nested lifetimes.
/// Can be used to make state that is scoped to the subscription.
/// Can call arbitratry functions at the end of the lifetime.
///
struct subscription
{
private:
struct shared
{
~shared(){
auto expired = std::move(destructors);
for (auto& d : expired) {
d();
}
}
shared() : stopped(false) {info("new lifetime");}
bool stopped;
set<subscription> others;
deque<function<void()>> stoppers;
deque<function<void()>> destructors;
};
public:
subscription() : store(make_shared<shared>()) {}
explicit subscription(shared_ptr<shared> o) : store(o) {}
/// \brief used to exit loops or otherwise stop work scoped to this subscription.
/// \returns bool - if true do not access any state objects.
bool is_stopped() const {
return store->stopped;
}
/// \brief
void insert(const subscription& s) const {
if (s == *this) {std::abort();}
// nest
store->others.insert(s);
// unnest when child is stopped
weak_ptr<shared> p = store;
weak_ptr<shared> c = s.store;
s.insert([p, c](){
auto storep = p.lock();
auto storec = c.lock();
if (storep && storec) {
auto that = subscription(storep);
auto s = subscription(storec);
that.erase(s);
}
});
if (store->stopped) stop();
}
void erase(const subscription& s) const {
if (s == *this) {std::abort();}
store->others.erase(s);
}
void insert(function<void()> stopper) const {
store->stoppers.emplace_front(stopper);
if (store->stopped) stop();
}
template<class Payload, class... ArgN>
state<Payload> make_state(ArgN... argn) const;
state<> make_state() const;
void stop() const {
store->stopped = true;
{
auto others = std::move(store->others);
for (auto& o : others) {
o.stop();
}
}
{
auto stoppers = std::move(store->stoppers);
for (auto& s : stoppers) {
s();
}
}
}
private:
shared_ptr<shared> store;
friend bool operator==(const subscription&, const subscription&);
friend bool operator<(const subscription&, const subscription&);
};
bool operator==(const subscription& lhs, const subscription& rhs) {
return lhs.store == rhs.store;
}
bool operator!=(const subscription& lhs, const subscription& rhs) {
return !(lhs == rhs);
}
bool operator<(const subscription& lhs, const subscription& rhs) {
return lhs.store < rhs.store;
}
template<class Payload>
struct state
{
subscription lifetime;
state(subscription l, Payload* p) : lifetime(l), p(p) {}
Payload& get() {
return *p;
}
Payload& get() const {
return *p;
}
private:
mutable Payload* p;
};
template<>
struct state<void>
{
subscription lifetime;
};
template<class Payload, class... ArgN>
state<Payload> subscription::make_state(ArgN... argn) const {
auto p = make_unique<Payload>(argn...);
auto result = state<Payload>{*this, p.get()};
store->destructors.emplace_front(
[d=p.release()]() mutable {
auto p = d;
d = nullptr;
delete p;
});
return result;
}
state<> subscription::make_state() const {
auto result = state<>{*this};
return result;
}
namespace detail {
template<class T>
struct state_check : public false_type {};
template<class Payload>
struct state_check<state<Payload>> : public true_type {};
template<class T>
using for_state = enable_if_t<state_check<std::decay_t<T>>::value>;
template<class T>
using not_state = enable_if_t<!state_check<std::decay_t<T>>::value>;
template<class T>
struct subscription_check : public false_type {};
template<>
struct subscription_check<subscription> : public true_type {};
template<class T>
using for_subscription = enable_if_t<subscription_check<std::decay_t<T>>::value>;
template<class T>
using not_subscription = enable_if_t<!subscription_check<std::decay_t<T>>::value>;
}
template<class Start>
struct starter {
Start s;
template<class Context>
subscription start(Context&& c) const {
return s(forward<Context>(c));
}
};
template<class Start>
starter<Start> make_starter(Start&& s) {
return {forward<Start>(s)};
}
namespace detail {
template<class T>
struct starter_check : public false_type {};
template<class Start>
struct starter_check<starter<Start>> : public true_type {};
template<class T>
using for_starter = enable_if_t<starter_check<decay_t<T>>::value>;
template<class T>
using not_starter = enable_if_t<!starter_check<decay_t<T>>::value>;
}
template<class Next, class Error, class Complete, class Delegatee = void>
struct receiver;
namespace detail {
template<class T>
struct receiver_check : public false_type {};
template<class Next, class Error, class Complete, class Delegatee>
struct receiver_check<receiver<Next, Error, Complete, Delegatee>> : public true_type {};
template<class T>
using for_receiver = enable_if_t<receiver_check<decay_t<T>>::value>;
template<class T>
using not_receiver = enable_if_t<!receiver_check<decay_t<T>>::value>;
auto report = [](auto&& e, auto&& f, auto&&... args){
try{f(args...);} catch(...) {e(current_exception());}
};
auto enforce = [](const subscription& lifetime, auto&& f) {
return [&](auto&&... args){
if (!lifetime.is_stopped()) f(args...);
};
};
auto end = [](const subscription& lifetime, auto&& f, auto&&... cap) {
return [&](auto&&... args){
if (!lifetime.is_stopped()) {
f(cap..., args...);
lifetime.stop();
}
};
};
struct noop
{
template<class V, class CheckV = not_receiver<V>>
void operator()(V&&) const {
}
template<class Delegatee, class V>
void operator()(const Delegatee& d, V&& v) const {
d.next(std::forward<V>(v));
}
inline void operator()() const {
}
template<class Delegatee, class Check = for_receiver<Delegatee>>
void operator()(const Delegatee& d) const {
d.complete();
}
};
struct ignore
{
template<class E>
void operator()(E&&) const {
}
template<class Delegatee, class E, class CheckD = for_receiver<Delegatee>>
void operator()(const Delegatee& d, E&& e) const {
d.error(forward<E>(e));
}
};
struct fail
{
template<class E>
void operator()(E&&) const {
info("abort! ");
std::abort();
}
template<class Delegatee, class E, class CheckD = for_receiver<Delegatee>>
void operator()(const Delegatee&, E&&) const {
info("abort! ");
std::abort();
}
};
}
template<class Next, class Error, class Complete>
struct receiver<Next, Error, Complete, void> {
subscription lifetime;
Next n;
Error e;
Complete c;
template<class V>
void next(V&& v) const {
using namespace detail;
report(end(lifetime, e), enforce(lifetime, n), std::forward<V>(v));
}
template<class E>
void error(E&& err) const {
using namespace detail;
report(fail{}, end(lifetime, e), std::forward<E>(err));
}
void complete() const {
using namespace detail;
report(fail{}, end(lifetime, c));
}
};
template<class Delegatee, class Next, class Error, class Complete>
struct receiver {
Delegatee d;
subscription lifetime;
Next n;
Error e;
Complete c;
template<class V>
void next(V&& v) const {
using namespace detail;
report(end(lifetime, e, d), enforce(lifetime, n), d, std::forward<V>(v));
}
template<class E>
void error(E&& err) const {
using namespace detail;
report(fail{}, end(lifetime, e), d, std::forward<E>(err));
}
void complete() const {
using namespace detail;
report(fail{}, end(lifetime, c), d);
}
};
template<class Next = detail::noop, class Error = detail::fail, class Complete = detail::noop,
class CheckN = detail::not_receiver<Next>>
auto make_receiver(subscription lifetime, Next&& n = Next{}, Error&& e = Error{}, Complete&& c = Complete{}) {
return receiver<decay_t<Next>, decay_t<Error>, decay_t<Complete>, void>{
lifetime,
forward<Next>(n),
forward<Error>(e),
forward<Complete>(c)
};
}
template<class Delegatee, class Next = detail::noop, class Error = detail::fail, class Complete = detail::noop,
class CheckD = detail::for_receiver<Delegatee>>
auto make_receiver(Delegatee&& d, subscription lifetime, Next&& n = Next{}, Error&& e = Error{}, Complete&& c = Complete{}) {
return receiver<decay_t<Delegatee>, decay_t<Next>, decay_t<Error>, decay_t<Complete>>{
forward<Delegatee>(d),
lifetime,
forward<Next>(n),
forward<Error>(e),
forward<Complete>(c)
};
}
template<class Create>
struct subscriber {
Create c;
/// \brief returns receiver
template<class Context>
auto create(Context& ctx) const {
return c(ctx);
}
};
template<class Create>
subscriber<Create> make_subscriber(Create&& c) {
return {forward<Create>(c)};
}
auto make_subscriber() {
return make_subscriber([](auto ctx){return make_receiver(ctx.lifetime);});
}
namespace detail {
template<class T>
struct subscriber_check : public false_type {};
template<class Create>
struct subscriber_check<subscriber<Create>> : public true_type {};
template<class T>
using for_subscriber = enable_if_t<subscriber_check<decay_t<T>>::value>;
template<class T>
using not_subscriber = enable_if_t<!subscriber_check<decay_t<T>>::value>;
}
template<class Bind>
struct sender {
Bind b;
/// \brief returns starter
template<class Subscriber>
auto bind(Subscriber&& s) const {
return b(s);
}
};
template<class Bind>
sender<Bind> make_sender(Bind&& b) {
return {forward<Bind>(b)};
}
namespace detail {
template<class T>
struct sender_check : public false_type {};
template<class Bind>
struct sender_check<sender<Bind>> : public true_type {};
template<class T>
using for_sender = enable_if_t<sender_check<decay_t<T>>::value>;
template<class T>
using not_sender = enable_if_t<!sender_check<decay_t<T>>::value>;
}
template<class Lift>
struct lifter {
Lift l;
/// \brief returns subscriber
template<class Subscriber>
auto lift(Subscriber&& s) const {
return l(forward<Subscriber>(s));
}
};
template<class Lift>
lifter<Lift> make_lifter(Lift&& l) {
return {forward<Lift>(l)};
}
namespace detail {
template<class T>
struct lifter_check : public false_type {};
template<class Lift>
struct lifter_check<lifter<Lift>> : public true_type {};
template<class T>
using for_lifter = enable_if_t<lifter_check<decay_t<T>>::value>;
template<class T>
using not_lifter = enable_if_t<!lifter_check<decay_t<T>>::value>;
}
template<class Adapt>
struct adaptor {
Adapt a;
/// \brief returns sender
template<class Sender>
auto adapt(Sender&& s) const {
return a(forward<Sender>(s));
}
};
template<class Adapt>
adaptor<Adapt> make_adaptor(Adapt&& l) {
return {forward<Adapt>(l)};
}
namespace detail {
template<class T>
struct adaptor_check : public false_type {};
template<class Adapt>
struct adaptor_check<adaptor<Adapt>> : public true_type {};
template<class T>
using for_adaptor = enable_if_t<adaptor_check<decay_t<T>>::value>;
template<class T>
using not_adaptor = enable_if_t<!adaptor_check<decay_t<T>>::value>;
}
template<class Terminate>
struct terminator {
Terminate t;
/// \brief returns sender
template<class Sender>
auto terminate(Sender&& s) const {
return t(forward<Sender>(s));
}
};
template<class Terminate>
terminator<Terminate> make_terminator(Terminate&& t) {
return {forward<Terminate>(t)};
}
namespace detail {
template<class T>
struct terminator_check : public false_type {};
template<class Adapt>
struct terminator_check<terminator<Adapt>> : public true_type {};
template<class T>
using for_terminator = enable_if_t<terminator_check<decay_t<T>>::value>;
template<class T>
using not_terminator = enable_if_t<!terminator_check<decay_t<T>>::value>;
}
inline state<> start(subscription lifetime = subscription{}) {
return lifetime.make_state();
}
template<class Payload>
auto start(subscription lifetime = subscription{}) {
return lifetime.template make_state<Payload>();
}
template<class Payload, class... ArgN>
auto start(subscription lifetime, ArgN&&... an) {
return lifetime.template make_state<Payload>(forward<ArgN>(an)...);
}
const auto ints = [](auto first, auto last){
info("new ints");
return make_sender([=](auto scrb){
info("ints bound to subscriber");
return make_starter([=](auto ctx) {
auto r = scrb.create(ctx);
info("ints started");
for(auto i = first;!ctx.lifetime.is_stopped(); ++i){
r.next(i);
if (i == last) break;
}
r.complete();
return ctx.lifetime;
});
});
};
const auto copy_if = [](auto pred){
info("new copy_if");
return make_lifter([=](auto scbr){
info("copy_if bound to subscriber");
return make_subscriber([=](auto& ctx){
info("copy_if bound to context");
auto r = scbr.create(ctx);
return make_receiver(r, ctx.lifetime, [=](auto& r, auto v){
if (pred(v)) r.next(v);
});
});
});
};
const auto transform = [](auto f){
info("new transform");
return make_lifter([=](auto scbr){
info("transform bound to subscriber");
return make_subscriber([=](auto& ctx){
info("transform bound to context");
auto r = scbr.create(ctx);
return make_receiver(r, ctx.lifetime, [=](auto& r, auto v){
r.next(f(v));
});
});
});
};
const auto last_or_default = [](auto def){
info("new last_or_default");
return make_lifter([=](auto scbr){
info("last_or_default bound to subscriber");
return make_subscriber([=](auto& ctx){
info("last_or_default bound to context");
auto r = scbr.create(ctx);
auto last = ctx.lifetime.template make_state<std::decay_t<decltype(def)>>(def);
return make_receiver(r, ctx.lifetime,
[last](auto& r, auto v){
last.get() = v;
},
detail::ignore{},
[last](auto& r){
r.next(last.get());
r.complete();
});
});
});
};
const auto take = [](int n){
info("new take");
return make_adaptor([=](auto source){
info("take bound to source");
return make_sender([=](auto scrb){
info("take bound to subscriber");
return source.bind(
make_subscriber([=](auto ctx){
info("take bound to context");
auto r = scrb.create(ctx);
auto remaining = ctx.lifetime.template make_state<int>(n);
return make_receiver(r, ctx.lifetime,
[remaining](auto& r, auto v){
if (remaining.get()-- == 0) {
r.complete();
return;
}
r.next(v);
});
}));
});
});
};
const auto merge = [](){
info("new merge");
return make_adaptor([=](auto source){
info("merge bound to source");
return make_sender([=](auto scrb){
info("merge bound to subscriber");
return source.bind(
make_subscriber([=](auto ctx){
info("merge bound to context");
using payload_t = decay_t<decltype(ctx.get())>;
auto pending = ctx.lifetime.template make_state<set<subscription>>();
pending.get().insert(ctx.lifetime);
subscription destlifetime;
destlifetime.insert([pending](){
while (!pending.get().empty()) {
(*pending.get().begin()).stop();
}
info("merge-output stopped");
});
auto destctx = destlifetime.template make_state<payload_t>(ctx.get());
auto r = scrb.create(destctx);
ctx.lifetime.insert([pending, r, l = ctx.lifetime](){
pending.get().erase(l);
if (pending.get().empty()){
r.complete();
}
info("merge-input stopped");
});
return make_receiver(r, destlifetime,
[pending, destctx](auto r, auto v){
v.bind(
make_subscriber([=](auto ctx){
info("merge-nested bound to context");
pending.get().insert(ctx.lifetime);
ctx.lifetime.insert([pending, r, l = ctx.lifetime](){
pending.get().erase(l);
if (pending.get().empty()){
r.complete();
}
info("merge-nested stopped");
});
return make_receiver(r, ctx.lifetime,
[pending](auto& r, auto v){
r.next(v);
},
[](auto& r, auto e){
r.error(e);
},
[](auto& r){
// not complete until all pending streams have stopped
});
})) |
start<payload_t>(subscription{}, destctx.get());
},
[](auto& r, auto e){
r.error(e);
},
[](auto& r){
// not complete until all pending streams have stopped
});
}));
});
});
};
template<class F>
auto transform_merge(F&& f) {
return transform(forward<F>(f)) | merge();
};
const auto printto = [](auto& output){
info("new printto");
return make_subscriber([&](auto& ctx) {
info("printto bound to context");
auto values = ctx.lifetime.template make_state<int>(0);
return make_receiver(
ctx.lifetime,
[&, values](auto v) {
++values.get();
output << v << endl;
},
[&](exception_ptr ep){
output << what(ep) << endl;
},
[&, values](){
output << values.get() << " values received - done!" << endl;
});
});
};
const auto ignore = [](){
info("new ignore");
return make_subscriber([&](auto& ctx) {
info("ignore bound to context");
return make_receiver(ctx.lifetime);
});
};
/// \brief chain operator overload for
/// Subscriber = Lifter | Subscriber
/// \param lifter
/// \param subscriber
/// \returns subscriber
template<class Lifter, class Subscriber,
class CheckL = detail::for_lifter<Lifter>,
class CheckScbr = detail::for_subscriber<Subscriber>>
auto operator|(Lifter&& l, Subscriber&& scbr) {
return l.lift(forward<Subscriber>(scbr));
}
/// \brief chain operator overload for
/// Lifter = Lifter | Lifter
/// \param lifter
/// \param lifter
/// \returns Lifter
template<class LifterL, class LifterR,
class CheckLl = detail::for_lifter<LifterL>,
class CheckLr = detail::for_lifter<LifterR>,
class _5 = void>
auto operator|(LifterL lhs, LifterR rhs) {
return make_lifter([lhs = move(lhs), rhs = move(rhs)](auto&& scbr){
lhs.lift(rhs.lift(forward<decltype(scbr)>(scbr)));
});
}
/// \brief chain operator overload for
/// Sender = Sender | Lifter
/// \param sender
/// \param lifter
/// \returns sender
template<class Sender, class Lifter,
class CheckS = detail::for_sender<Sender>,
class CheckL = detail::for_lifter<Lifter>,
class _5 = void,
class _6 = void>
auto operator|(Sender&& s, Lifter&& l) {
return make_sender([=](auto&& scrb){
return s.bind(l.lift(forward<decltype(scrb)>(scrb)));
});
}
/// \brief chain operator overload for
/// Starter = Sender | Subscriber
/// \param sender
/// \param subscriber
/// \returns starter
template<class Sender, class Subscriber,
class CheckS = detail::for_sender<Sender>,
class CheckScbr = detail::for_subscriber<Subscriber>,
class _5 = void,
class _6 = void,
class _7 = void>
auto operator|(Sender&& s, Subscriber&& scbr) {
return s.bind(forward<Subscriber>(scbr));
}
/// \brief chain operator overload for
/// subscription = Starter | State
/// \param starter
/// \param state
/// \returns subscription
template<class Starter, class State,
class CheckS = detail::for_starter<Starter>,
class CheckSt = detail::for_state<State>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void>
subscription operator|(Starter&& s, State&& st) {
return s.start(forward<State>(st));
}
/// \brief chain operator overload for
/// Adaptor = Adaptor | Adaptor
/// \param adaptor
/// \param adaptor
/// \returns adaptor
template<class AdaptorL, class AdaptorR,
class CheckAL = detail::for_adaptor<AdaptorL>,
class CheckAR = detail::for_adaptor<AdaptorR>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void>
auto operator|(AdaptorL&& lhs, AdaptorR&& rhs) {
return make_adaptor([=](auto source){
return rhs.adapt(lhs.adapt(source));
});
}
/// \brief chain operator overload for
/// Adaptor = Adaptor | Lifter
/// \param adaptor
/// \param lifter
/// \returns adaptor
template<class Adapter, class Lifter,
class CheckA = detail::for_adaptor<Adapter>,
class CheckL = detail::for_lifter<Lifter>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void,
class _10 = void>
auto operator|(Adapter&& a, Lifter&& l) {
return make_adaptor([=](auto source){
auto s = a.adapt(source);
return make_sender([=](auto&& scrb){
return s.bind(l.lift(forward<decltype(scrb)>(scrb)));
});
});
}
/// \brief chain operator overload for
/// Adaptor = Lifter | Adaptor
/// \param lifter
/// \param adaptor
/// \returns adaptor
template<class Lifter, class Adapter,
class CheckL = detail::for_lifter<Lifter>,
class CheckA = detail::for_adaptor<Adapter>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void,
class _10 = void,
class _11 = void>
auto operator|(Lifter&& l, Adapter&& a) {
return make_adaptor([=](auto source){
return a.adapt(make_sender([=](auto&& scrb){
return source.bind(l.lift(forward<decltype(scrb)>(scrb)));
}));
});
}
/// \brief chain operator overload for
/// Sender = Sender | Adaptor
/// \param sender
/// \param adaptor
/// \returns sender
template<class Sender, class Adaptor,
class CheckS = detail::for_sender<Sender>,
class CheckA = detail::for_adaptor<Adaptor>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void,
class _10 = void,
class _11 = void,
class _12 = void>
auto operator|(Sender&& s, Adaptor&& a) {
return a.adapt(forward<Sender>(s));
}
/// \brief chain operator overload for
/// Terminator = Adaptor | Subscriber
/// \param adaptor
/// \param subscriber
/// \returns terminator
template<class Adapter, class Subscriber,
class CheckA = detail::for_adaptor<Adapter>,
class CheckS = detail::for_subscriber<Subscriber>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void,
class _10 = void,
class _11 = void,
class _12 = void,
class _13 = void>
auto operator|(Adapter&& a, Subscriber&& scrb) {
return make_terminator([=](auto source){
return a.adapt(source).bind(scrb);
});
}
/// \brief chain operator overload for
/// starter = Sender | Terminator
/// \param sender
/// \param terminator
/// \returns starter
template<class Sender, class Terminator,
class CheckS = detail::for_sender<Sender>,
class CheckA = detail::for_terminator<Terminator>,
class _5 = void,
class _6 = void,
class _7 = void,
class _8 = void,
class _9 = void,
class _10 = void,
class _11 = void,
class _12 = void,
class _13 = void,
class _14 = void>
auto operator|(Sender&& s, Terminator&& t) {
return t.terminate(forward<Sender>(s));
}
}
extern"C" {
void designcontext(int, int);
}
void designcontext(int first, int last){
using namespace std::chrono;
using namespace designcontextdef;
using designcontextdef::copy_if;
using designcontextdef::transform;
using designcontextdef::merge;
auto lastof3even = copy_if(even) |
take(50000000) |
last_or_default(42);
{
auto lifetime = ints(0, 2) |
transform_merge([=](int){