-
Notifications
You must be signed in to change notification settings - Fork 0
/
either.h
655 lines (546 loc) · 22.2 KB
/
either.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
#pragma once
#include "./std_dependency.h"
#include "./assert.h"
#include "./fatal.h"
namespace rhetoric {
enum class Either2Tag : uint8_t {
Case0 = 0,
Case1 = 1
};
template <Either2Tag G, typename T> struct Either2CaseWrapper;
template <Either2Tag G, typename T>
Either2CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1>
class Either2 {
public:
Either2() = delete;
/* implicit */ Either2(const Either2CaseWrapper<Either2Tag::Case0, T0> & value);
/* implicit */ Either2(const Either2CaseWrapper<Either2Tag::Case1, T1> & value);
Either2(const Either2<T0, T1> & other);
template <typename U0, typename U1>
Either2(
const Either2<U0, U1> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value
> * = nullptr);
Either2<T0, T1> & operator= (const Either2<T0, T1> & other);
~Either2();
Either2Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
template <Either2Tag G>
const T0 & AsCase(std::enable_if_t< G == Either2Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either2Tag G>
const T1 & AsCase(std::enable_if_t< G == Either2Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
private:
union Storage {
T0 value0;
T1 value1;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void Deinit();
Storage storage_;
Either2Tag tag_;
};
template <Either2Tag G, typename T>
struct Either2CaseWrapper {
T value;
Either2CaseWrapper(const T & value);
};
enum class Either3Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2
};
template <Either3Tag G, typename T> struct Either3CaseWrapper;
template <Either3Tag G, typename T>
Either3CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2>
class Either3 {
public:
Either3() = delete;
/* implicit */ Either3(const Either3CaseWrapper<Either3Tag::Case0, T0> & value);
/* implicit */ Either3(const Either3CaseWrapper<Either3Tag::Case1, T1> & value);
/* implicit */ Either3(const Either3CaseWrapper<Either3Tag::Case2, T2> & value);
Either3(const Either3<T0, T1, T2> & other);
template <typename U0, typename U1, typename U2>
Either3(
const Either3<U0, U1, U2> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value
> * = nullptr);
Either3<T0, T1, T2> & operator= (const Either3<T0, T1, T2> & other);
~Either3();
Either3Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
template <Either3Tag G>
const T0 & AsCase(std::enable_if_t< G == Either3Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either3Tag G>
const T1 & AsCase(std::enable_if_t< G == Either3Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either3Tag G>
const T2 & AsCase(std::enable_if_t< G == Either3Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void Deinit();
Storage storage_;
Either3Tag tag_;
};
template <Either3Tag G, typename T>
struct Either3CaseWrapper {
T value;
Either3CaseWrapper(const T & value);
};
enum class Either4Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2,
Case3 = 3
};
template <Either4Tag G, typename T> struct Either4CaseWrapper;
template <Either4Tag G, typename T>
Either4CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2, typename T3>
class Either4 {
public:
Either4() = delete;
/* implicit */ Either4(const Either4CaseWrapper<Either4Tag::Case0, T0> & value);
/* implicit */ Either4(const Either4CaseWrapper<Either4Tag::Case1, T1> & value);
/* implicit */ Either4(const Either4CaseWrapper<Either4Tag::Case2, T2> & value);
/* implicit */ Either4(const Either4CaseWrapper<Either4Tag::Case3, T3> & value);
Either4(const Either4<T0, T1, T2, T3> & other);
template <typename U0, typename U1, typename U2, typename U3>
Either4(
const Either4<U0, U1, U2, U3> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value &&
std::is_convertible<U3, T3>::value
> * = nullptr);
Either4<T0, T1, T2, T3> & operator= (const Either4<T0, T1, T2, T3> & other);
~Either4();
Either4Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
const T3 & AsCase3() const;
template <Either4Tag G>
const T0 & AsCase(std::enable_if_t< G == Either4Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either4Tag G>
const T1 & AsCase(std::enable_if_t< G == Either4Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either4Tag G>
const T2 & AsCase(std::enable_if_t< G == Either4Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
template <Either4Tag G>
const T3 & AsCase(std::enable_if_t< G == Either4Tag::Case3 > * = nullptr) const
{ return AsCase3(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
T3 value3;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void InitValue3(const T3 & value);
void Deinit();
Storage storage_;
Either4Tag tag_;
};
template <Either4Tag G, typename T>
struct Either4CaseWrapper {
T value;
Either4CaseWrapper(const T & value);
};
enum class Either5Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2,
Case3 = 3,
Case4 = 4
};
template <Either5Tag G, typename T> struct Either5CaseWrapper;
template <Either5Tag G, typename T>
Either5CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2, typename T3, typename T4>
class Either5 {
public:
Either5() = delete;
/* implicit */ Either5(const Either5CaseWrapper<Either5Tag::Case0, T0> & value);
/* implicit */ Either5(const Either5CaseWrapper<Either5Tag::Case1, T1> & value);
/* implicit */ Either5(const Either5CaseWrapper<Either5Tag::Case2, T2> & value);
/* implicit */ Either5(const Either5CaseWrapper<Either5Tag::Case3, T3> & value);
/* implicit */ Either5(const Either5CaseWrapper<Either5Tag::Case4, T4> & value);
Either5(const Either5<T0, T1, T2, T3, T4> & other);
template <typename U0, typename U1, typename U2, typename U3, typename U4>
Either5(
const Either5<U0, U1, U2, U3, U4> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value &&
std::is_convertible<U3, T3>::value &&
std::is_convertible<U4, T4>::value
> * = nullptr);
Either5<T0, T1, T2, T3, T4> & operator= (const Either5<T0, T1, T2, T3, T4> & other);
~Either5();
Either5Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
const T3 & AsCase3() const;
const T4 & AsCase4() const;
template <Either5Tag G>
const T0 & AsCase(std::enable_if_t< G == Either5Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either5Tag G>
const T1 & AsCase(std::enable_if_t< G == Either5Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either5Tag G>
const T2 & AsCase(std::enable_if_t< G == Either5Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
template <Either5Tag G>
const T3 & AsCase(std::enable_if_t< G == Either5Tag::Case3 > * = nullptr) const
{ return AsCase3(); }
template <Either5Tag G>
const T4 & AsCase(std::enable_if_t< G == Either5Tag::Case4 > * = nullptr) const
{ return AsCase4(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
T3 value3;
T4 value4;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void InitValue3(const T3 & value);
void InitValue4(const T4 & value);
void Deinit();
Storage storage_;
Either5Tag tag_;
};
template <Either5Tag G, typename T>
struct Either5CaseWrapper {
T value;
Either5CaseWrapper(const T & value);
};
enum class Either6Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2,
Case3 = 3,
Case4 = 4,
Case5 = 5
};
template <Either6Tag G, typename T> struct Either6CaseWrapper;
template <Either6Tag G, typename T>
Either6CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
class Either6 {
public:
Either6() = delete;
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case0, T0> & value);
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case1, T1> & value);
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case2, T2> & value);
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case3, T3> & value);
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case4, T4> & value);
/* implicit */ Either6(const Either6CaseWrapper<Either6Tag::Case5, T5> & value);
Either6(const Either6<T0, T1, T2, T3, T4, T5> & other);
template <typename U0, typename U1, typename U2, typename U3, typename U4, typename U5>
Either6(
const Either6<U0, U1, U2, U3, U4, U5> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value &&
std::is_convertible<U3, T3>::value &&
std::is_convertible<U4, T4>::value &&
std::is_convertible<U5, T5>::value
> * = nullptr);
Either6<T0, T1, T2, T3, T4, T5> & operator= (const Either6<T0, T1, T2, T3, T4, T5> & other);
~Either6();
Either6Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
const T3 & AsCase3() const;
const T4 & AsCase4() const;
const T5 & AsCase5() const;
template <Either6Tag G>
const T0 & AsCase(std::enable_if_t< G == Either6Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either6Tag G>
const T1 & AsCase(std::enable_if_t< G == Either6Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either6Tag G>
const T2 & AsCase(std::enable_if_t< G == Either6Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
template <Either6Tag G>
const T3 & AsCase(std::enable_if_t< G == Either6Tag::Case3 > * = nullptr) const
{ return AsCase3(); }
template <Either6Tag G>
const T4 & AsCase(std::enable_if_t< G == Either6Tag::Case4 > * = nullptr) const
{ return AsCase4(); }
template <Either6Tag G>
const T5 & AsCase(std::enable_if_t< G == Either6Tag::Case5 > * = nullptr) const
{ return AsCase5(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
T3 value3;
T4 value4;
T5 value5;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void InitValue3(const T3 & value);
void InitValue4(const T4 & value);
void InitValue5(const T5 & value);
void Deinit();
Storage storage_;
Either6Tag tag_;
};
template <Either6Tag G, typename T>
struct Either6CaseWrapper {
T value;
Either6CaseWrapper(const T & value);
};
enum class Either7Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2,
Case3 = 3,
Case4 = 4,
Case5 = 5,
Case6 = 6
};
template <Either7Tag G, typename T> struct Either7CaseWrapper;
template <Either7Tag G, typename T>
Either7CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
class Either7 {
public:
Either7() = delete;
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case0, T0> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case1, T1> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case2, T2> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case3, T3> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case4, T4> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case5, T5> & value);
/* implicit */ Either7(const Either7CaseWrapper<Either7Tag::Case6, T6> & value);
Either7(const Either7<T0, T1, T2, T3, T4, T5, T6> & other);
template <typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6>
Either7(
const Either7<U0, U1, U2, U3, U4, U5, U6> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value &&
std::is_convertible<U3, T3>::value &&
std::is_convertible<U4, T4>::value &&
std::is_convertible<U5, T5>::value &&
std::is_convertible<U6, T6>::value
> * = nullptr);
Either7<T0, T1, T2, T3, T4, T5, T6> & operator= (const Either7<T0, T1, T2, T3, T4, T5, T6> & other);
~Either7();
Either7Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
const T3 & AsCase3() const;
const T4 & AsCase4() const;
const T5 & AsCase5() const;
const T6 & AsCase6() const;
template <Either7Tag G>
const T0 & AsCase(std::enable_if_t< G == Either7Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either7Tag G>
const T1 & AsCase(std::enable_if_t< G == Either7Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either7Tag G>
const T2 & AsCase(std::enable_if_t< G == Either7Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
template <Either7Tag G>
const T3 & AsCase(std::enable_if_t< G == Either7Tag::Case3 > * = nullptr) const
{ return AsCase3(); }
template <Either7Tag G>
const T4 & AsCase(std::enable_if_t< G == Either7Tag::Case4 > * = nullptr) const
{ return AsCase4(); }
template <Either7Tag G>
const T5 & AsCase(std::enable_if_t< G == Either7Tag::Case5 > * = nullptr) const
{ return AsCase5(); }
template <Either7Tag G>
const T6 & AsCase(std::enable_if_t< G == Either7Tag::Case6 > * = nullptr) const
{ return AsCase6(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
T3 value3;
T4 value4;
T5 value5;
T6 value6;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void InitValue3(const T3 & value);
void InitValue4(const T4 & value);
void InitValue5(const T5 & value);
void InitValue6(const T6 & value);
void Deinit();
Storage storage_;
Either7Tag tag_;
};
template <Either7Tag G, typename T>
struct Either7CaseWrapper {
T value;
Either7CaseWrapper(const T & value);
};
enum class Either8Tag : uint8_t {
Case0 = 0,
Case1 = 1,
Case2 = 2,
Case3 = 3,
Case4 = 4,
Case5 = 5,
Case6 = 6,
Case7 = 7
};
template <Either8Tag G, typename T> struct Either8CaseWrapper;
template <Either8Tag G, typename T>
Either8CaseWrapper<G, T> EitherCase(const T & value);
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
class Either8 {
public:
Either8() = delete;
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case0, T0> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case1, T1> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case2, T2> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case3, T3> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case4, T4> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case5, T5> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case6, T6> & value);
/* implicit */ Either8(const Either8CaseWrapper<Either8Tag::Case7, T7> & value);
Either8(const Either8<T0, T1, T2, T3, T4, T5, T6, T7> & other);
template <typename U0, typename U1, typename U2, typename U3, typename U4, typename U5, typename U6, typename U7>
Either8(
const Either8<U0, U1, U2, U3, U4, U5, U6, U7> & other,
std::enable_if_t<
std::is_convertible<U0, T0>::value &&
std::is_convertible<U1, T1>::value &&
std::is_convertible<U2, T2>::value &&
std::is_convertible<U3, T3>::value &&
std::is_convertible<U4, T4>::value &&
std::is_convertible<U5, T5>::value &&
std::is_convertible<U6, T6>::value &&
std::is_convertible<U7, T7>::value
> * = nullptr);
Either8<T0, T1, T2, T3, T4, T5, T6, T7> & operator= (const Either8<T0, T1, T2, T3, T4, T5, T6, T7> & other);
~Either8();
Either8Tag tag() const;
const T0 & AsCase0() const;
const T1 & AsCase1() const;
const T2 & AsCase2() const;
const T3 & AsCase3() const;
const T4 & AsCase4() const;
const T5 & AsCase5() const;
const T6 & AsCase6() const;
const T7 & AsCase7() const;
template <Either8Tag G>
const T0 & AsCase(std::enable_if_t< G == Either8Tag::Case0 > * = nullptr) const
{ return AsCase0(); }
template <Either8Tag G>
const T1 & AsCase(std::enable_if_t< G == Either8Tag::Case1 > * = nullptr) const
{ return AsCase1(); }
template <Either8Tag G>
const T2 & AsCase(std::enable_if_t< G == Either8Tag::Case2 > * = nullptr) const
{ return AsCase2(); }
template <Either8Tag G>
const T3 & AsCase(std::enable_if_t< G == Either8Tag::Case3 > * = nullptr) const
{ return AsCase3(); }
template <Either8Tag G>
const T4 & AsCase(std::enable_if_t< G == Either8Tag::Case4 > * = nullptr) const
{ return AsCase4(); }
template <Either8Tag G>
const T5 & AsCase(std::enable_if_t< G == Either8Tag::Case5 > * = nullptr) const
{ return AsCase5(); }
template <Either8Tag G>
const T6 & AsCase(std::enable_if_t< G == Either8Tag::Case6 > * = nullptr) const
{ return AsCase6(); }
template <Either8Tag G>
const T7 & AsCase(std::enable_if_t< G == Either8Tag::Case7 > * = nullptr) const
{ return AsCase7(); }
private:
union Storage {
T0 value0;
T1 value1;
T2 value2;
T3 value3;
T4 value4;
T5 value5;
T6 value6;
T7 value7;
Storage();
~Storage();
};
void InitValue0(const T0 & value);
void InitValue1(const T1 & value);
void InitValue2(const T2 & value);
void InitValue3(const T3 & value);
void InitValue4(const T4 & value);
void InitValue5(const T5 & value);
void InitValue6(const T6 & value);
void InitValue7(const T7 & value);
void Deinit();
Storage storage_;
Either8Tag tag_;
};
template <Either8Tag G, typename T>
struct Either8CaseWrapper {
T value;
Either8CaseWrapper(const T & value);
};
}
#include "./either_inline.h"