-
Notifications
You must be signed in to change notification settings - Fork 1
/
tcalc.h
1221 lines (1026 loc) · 30.8 KB
/
tcalc.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
/*
C++ compile-time Prolog interpreter
By Andrey Budnik, Belarus
Public Domain
*/
#ifndef __TCALK_H
#define __TCALK_H
namespace tcalc {
template< typename T, T v = T() >
struct Value
{
enum { val = v };
typedef T value_type;
};
#define DECLARE_NAME( s, isVar ) \
struct Value_##s { \
static const char *val; \
typedef char *value_type; \
static const bool var = isVar; \
}; \
const char *Value_##s::val = #s; \
#define DECLARE_SYM( s ) DECLARE_NAME( s, false )
#define DECLARE_VAR( s ) DECLARE_NAME( s, true )
template< typename T1, typename T2>
struct TypeEqual
{
enum { val = 0 };
};
template< typename T >
struct TypeEqual< T, T >
{
enum { val = 1 };
};
// comparision
template< class V1, class V2>
struct Less
{
enum { val = V1::val < V2::val };
};
template< class V1, class V2>
struct LessOrEqual
{
enum { val = V1::val <= V2::val };
};
template< class V1, class V2 >
struct Equal
{
enum { val = V1::val == V2::val };
};
template< class V1, class V2 >
struct Greater
{
enum { val = V1::val > V2::val };
};
template< class V1, class V2 >
struct GreaterOrEqual
{
enum { val = V1::val >= V2::val };
};
template< class V1, class V2 >
class Min
{
template< class Vi1, class Vi2, int lesser >
struct MinR;
template< class Vi1, class Vi2 >
struct MinR< Vi1, Vi2, 1 >
{
typedef Vi1 NextType;
};
template< class Vi1, class Vi2 >
struct MinR< Vi1, Vi2, 0 >
{
typedef Vi2 NextType;
};
public:
typedef typename MinR< V1, V2, Less< V1, V2 >::val >::NextType NextType;
};
template< class V1, class V2 >
class Max
{
template< class Vi1, class Vi2, int lesser >
struct MaxR;
template< class Vi1, class Vi2 >
struct MaxR< Vi1, Vi2, 1 >
{
typedef Vi2 NextType;
};
template< class Vi1, class Vi2 >
struct MaxR< Vi1, Vi2, 0 >
{
typedef Vi1 NextType;
};
public:
typedef typename MaxR< V1, V2, Less< V1, V2 >::val >::NextType NextType;
};
// arithmetic
template< typename T, T v >
struct Negate
{
enum { val = -v };
};
template< class V1, class V2 >
struct Add
{
typedef Value< typename V1::value_type, V1::val + V2::val > NextType;
};
template< class V1, class V2 >
struct Sub
{
typedef Value< typename V1::value_type, V1::val - V2::val > NextType;
};
template< class V1, class V2 >
struct Mul
{
typedef Value< typename V1::value_type, V1::val * V2::val > NextType;
};
template< class V1, class V2 >
struct Div
{
typedef Value< typename V1::value_type, V1::val / V2::val > NextType;
};
template< class V, unsigned p >
struct Power
{
typedef Value< typename V::value_type, Power< V, p - 1 >::NextType::val * V::val > NextType;
};
template< class V >
struct Power< V, 1 >
{
typedef V NextType;
};
template< class V >
struct Power< V, 0 >
{
typedef Value< typename V::value_type, 1 > NextType;
};
// special-purpose
template< unsigned v >
struct Factorial
{
enum { val = Factorial< v - 1 >::val * v };
};
template<>
struct Factorial<0>
{
enum { val = 1 };
};
////////////////////////////////
namespace container {
namespace list {
struct NullItem
{
static void Print() { std::cout << std::endl; }
};
template< typename V, typename L >
struct List
{
typedef V value_type;
static void Print()
{
std::cout << value_type::val << ", ";
L::Print();
}
};
template< class List > struct ListLength;
template<>
struct ListLength< NullItem >
{
static const unsigned val = 0;
};
template< class V, class L >
struct ListLength< List< V, L > >
{
static const unsigned val = 1 + ListLength<L>::val;
};
template< class List > struct Next;
template< class V, class L >
struct Next< List< V, L > >
{
typedef L NextType;
};
template< class L, int step >
class Advance
{
typedef typename Next< L >::NextType Forward;
public:
typedef typename Advance< Forward, step - 1 >::NextType NextType;
};
template< class L >
class Advance< L, 1 >
{
public:
typedef typename Next< L >::NextType NextType;
};
template< class L >
class Advance< L, 0 >
{
public:
typedef L NextType;
};
template< class L, int length = ListLength< L >::val >
class Reverse
{
typedef typename Advance< L, length - 1 >::NextType::value_type Last;
public:
typedef List< Last, typename Reverse< L, length - 1 >::NextType > NextType;
};
template< class L >
class Reverse< L, 1 >
{
typedef typename L::value_type First;
public:
typedef List< First, NullItem > NextType;
};
template< class L >
class PopBack
{
template< class Li, int length >
class PopBackR
{
typedef typename Next< Li >::NextType Remaining;
public:
typedef List< typename Li::value_type, typename PopBackR< Remaining, length - 1 >::NextType > NextType;
};
template< class Li >
class PopBackR< Li, 2 >
{
public:
typedef List< typename Li::value_type, NullItem > NextType;
};
template< class Li >
class PopBackR< Li, 1 >
{
public:
typedef NullItem NextType;
};
public:
typedef typename PopBackR< L, ListLength< L >::val >::NextType NextType;
};
template< class L >
struct PopFront
{
typedef typename Next< L >::NextType NextType;
};
template< class V, class L >
class PushBack
{
typedef typename Reverse< L >::NextType Reversed;
typedef List< V, Reversed > ReversedA;
public:
typedef typename Reverse< ReversedA >::NextType NextType;
};
template< class V >
class PushBack< V, NullItem >
{
public:
typedef List< V, NullItem > NextType;
};
template< unsigned n, int i = 0, int until = n + i, class G = NullItem >
class Generate
{
typedef List< Value< int, i >, G > NewList;
public:
typedef typename Generate< n, i + 1, until, NewList >::NextType NextType;
};
template< unsigned n, int until, class G >
class Generate<n, until, until, G>
{
public:
typedef G NextType;
};
template< class L1, class L2 >
class Merge
{
typedef typename PushBack< typename L2::value_type, L1 >::NextType MergedWithFirst;
typedef typename Next< L2 >::NextType L2_NextType;
public:
typedef typename Merge< MergedWithFirst, L2_NextType >::NextType NextType;
};
template< class L1 >
class Merge< L1, NullItem >
{
public:
typedef L1 NextType;
};
template< class L, unsigned n, unsigned i = 0 >
class First
{
template< class Li, unsigned ni, class Ri, unsigned ii >
class FirstR
{
typedef typename PushBack< typename Li::value_type, Ri >::NextType Ls;
typedef typename Next< Li >::NextType Forward;
public:
typedef typename FirstR< Forward, ni, Ls, ii + 1 >::NextType NextType;
};
template< class Li, unsigned ni, class Ri >
class FirstR< Li, ni, Ri, ni >
{
public:
typedef Ri NextType;
};
typedef List< typename L::value_type, NullItem > Trivial;
typedef typename Next< L >::NextType Forward;
public:
typedef typename FirstR< Forward, n, Trivial, 1 >::NextType NextType;
};
template< class L, class Item, unsigned index, unsigned length = ListLength< L >::val >
class InsertAt
{
typedef typename First< L, index >::NextType L1;
typedef typename Advance< L, index >::NextType L2;
typedef typename PushBack< Item, L1 >::NextType L1PlusItem;
public:
typedef typename Merge< L1PlusItem, L2 >::NextType NextType;
};
template< class L, class Item, unsigned index >
class InsertAt< L, Item, index, index >
{
public:
typedef typename PushBack< Item, L >::NextType NextType;
};
template< class L, class Item, unsigned length >
class InsertAt< L, Item, 0, length >
{
public:
typedef List< Item, L > NextType;
};
template< class L, unsigned index >
class EraseAtIndex
{
typedef typename First<L, index>::NextType L1;
typedef typename Advance<L, index + 1>::NextType L2;
public:
typedef typename Merge< L1, L2 >::NextType NextType;
};
template< class L >
class EraseAtIndex< L, 0 >
{
public:
typedef typename Next<L>::NextType NextType;
};
template< class Ls, class it >
class Search
{
public:
static const int NOT_FOUND = -1;
private:
template< class L, class item, unsigned i, int eq >
class SearchR;
template< class L, class item, unsigned i >
class SearchR< L, item, i, 1 >
{
public:
enum { val = i };
};
template< class item, unsigned i >
class SearchR< NullItem, item, i, 1 >
{
public:
enum { val = i };
};
template< class item, unsigned i >
class SearchR< NullItem, item, i, 0 >
{
public:
enum { val = NOT_FOUND };
};
template< class L, class item, unsigned i >
class SearchR< L, item, i, 0 >
{
typedef typename Next<L>::NextType NextType;
public:
enum { val = SearchR< NextType, item, i + 1, Equal< typename NextType::value_type, item >::val >::val };
};
public:
enum { val = SearchR< Ls, it, 0, Equal< typename Ls::value_type, it >::val >::val };
};
template< class L, typename Min = typename L::value_type >
class FindMinimum
{
typedef typename Next<L>::NextType Forward;
typedef typename tcalc::Min< typename L::value_type, Min >::NextType CurrentMin;
public:
typedef typename FindMinimum< Forward, CurrentMin >::NextType NextType;
};
template< class Min >
class FindMinimum< NullItem, Min >
{
public:
typedef Min NextType;
};
template< class Ls, class it >
class LowerBound
{
template< class L, class item, unsigned i, int eq >
class LowerR;
template< class L, class item, unsigned i >
class LowerR< L, item, i, 1 >
{
public:
enum { val = i - 1 };
};
template< class L, class item >
class LowerR< L, item, 0, 1 >
{
public:
enum { val = 0 };
};
template< class item, unsigned i >
class LowerR< NullItem, item, i, 1 >
{
public:
enum { val = i - 1 };
};
template< class item, unsigned i >
class LowerR< NullItem, item, i, 0 >
{
public:
enum { val = i };
};
template< class L, class item, unsigned i >
class LowerR< L, item, i, 0 >
{
typedef typename Next<L>::NextType NextType;
public:
enum { val = LowerR< NextType, item, i + 1, Greater< typename L::value_type, item >::val >::val };
};
public:
enum { val = LowerR< Ls, it, 0, Greater< typename Ls::value_type, it >::val >::val };
};
template< class L1, class L2 >
class MergeSorted
{
typedef typename Next< L2 >::NextType L2MinusMin;
typedef typename L2::value_type Min;
typedef LowerBound< L1, Min > LB;
typedef typename InsertAt< L1, Min, LB::val >::NextType L1PlusMin;
public:
typedef typename MergeSorted< L1PlusMin, L2MinusMin >::NextType NextType;
};
template< class L1 >
class MergeSorted< L1, NullItem >
{
public:
typedef L1 NextType;
};
template< class L, unsigned length = ListLength< L >::val >
class MergeSort
{
typedef ListLength< L > Length;
typedef typename First< L, Length::val / 2 >::NextType L1;
typedef typename Advance< L, Length::val / 2 >::NextType L2;
typedef typename MergeSort< L1 >::NextType L1_sorted;
typedef typename MergeSort< L2 >::NextType L2_sorted;
public:
typedef typename MergeSorted< L1_sorted, L2_sorted >::NextType NextType;
};
template< class L >
class MergeSort< L, 2 >
{
typedef typename L::value_type E1;
typedef typename Next<L>::NextType Forward;
typedef typename Forward::value_type E2;
typedef typename Min<E1, E2>::NextType R1;
typedef typename Max<E1, E2>::NextType R2;
public:
typedef List< R1, List< R2, NullItem > > NextType;
};
template< class L >
class MergeSort< L, 1 >
{
public:
typedef L NextType;
};
// functional
template< class L, template<class, class> class F, class BindParam >
class Map
{
template< template<class, class> class T, class Param, class Value >
struct Mutator : T< Param, Value >
{
};
typedef typename L::value_type E;
typedef typename Mutator< F, BindParam, E >::NextType Mut;
typedef typename Next<L>::NextType Forward;
public:
typedef List< Mut, typename Map< Forward, F, BindParam >::NextType > NextType;
};
template< template<class, class> class F, class BindParam >
class Map< NullItem, F, BindParam >
{
public:
typedef NullItem NextType;
};
template< class L, template<class, class> class F, class Value >
class Fold
{
template< template<class, class> class T, class Param, class V >
struct Mutator : T< Param, V >
{
};
typedef typename L::value_type E;
typedef typename Mutator< F, Value, E >::NextType Mut;
typedef typename Next<L>::NextType Forward;
public:
typedef typename Fold< Forward, F, Mut >::NextType NextType;
};
template< template<class, class> class F, class Value >
class Fold< NullItem, F, Value >
{
public:
typedef Value NextType;
};
template< class L, template<class, class> class LeftPredicate, class BindParam, class G = NullItem >
class Filter
{
template< class Param, template<class, class> class P, class Value >
struct Predicate : P< Value, Param >
{
};
template< class Li, class V, int eq >
struct Match
{
typedef typename PushBack< V, Li >::NextType NextType;
};
template< class Li, class V >
struct Match< Li, V, 0 >
{
typedef Li NextType;
};
typedef typename L::value_type E;
typedef Predicate< BindParam, LeftPredicate, E > AppliedPredicate;
typedef typename Match< G, E, AppliedPredicate::val >::NextType Matched;
typedef typename Next<L>::NextType Forward;
public:
typedef typename Filter< Forward, LeftPredicate, BindParam, Matched >::NextType NextType;
};
template< template<class, class> class LeftPredicate, class BindParam, class G >
class Filter< NullItem, LeftPredicate, BindParam, G >
{
public:
typedef G NextType;
};
} // namespace list
namespace map {
using namespace list; // map implemented as list of Key-Value pairs
template< typename K, typename V >
struct Pair
{
typedef K Key;
typedef V Value;
};
template< typename Pair >
struct GetPairValue
{
typedef typename Pair::Value Value;
};
template<>
struct GetPairValue< NullItem >
{
typedef NullItem Value;
};
template< typename Key, typename Map >
class FindKey
{
template< typename K, typename M, int eq >
struct FindKeyR
{
typedef typename M::value_type NextType;
};
template< typename K, typename M >
struct FindKeyR< K, M, 0 >
{
typedef typename FindKey< K, typename Next< M >::NextType >::NextType NextType;
};
typedef typename Map::value_type Item;
typedef typename Item::Key K;
public:
typedef typename FindKeyR< Key, Map, TypeEqual< Key, K >::val >::NextType NextType;
};
template< typename Key >
class FindKey< Key, NullItem >
{
public:
typedef NullItem NextType;
};
template< class Pair, typename Map, unsigned index = 0, typename Forward = Map >
class AddKey
{
template< typename P, typename M, unsigned i, typename F, int eq > // eq => replace
class AddKeyR
{
typedef typename InsertAt< M, P, i >::NextType Left;
typedef typename First< Left, i + 1 >::NextType L1;
typedef typename Advance< M, i + 1 >::NextType Right;
public:
typedef typename Merge< L1, Right >::NextType NextType;
};
template< typename P, typename M, unsigned i, typename F >
class AddKeyR< P, M, i, F, 0 >
{
public:
typedef typename AddKey< P, M, i + 1, typename Next< F >::NextType >::NextType NextType;
};
template< typename P, unsigned i, typename F, int eq > // empty map
class AddKeyR< P, NullItem, i, F, eq >
{
public:
typedef List< P, NullItem > NextType;
};
typedef typename Forward::value_type Item;
typedef typename Item::Key K;
typedef typename Pair::Key Key;
public:
typedef typename AddKeyR< Pair, Map, index, Forward, TypeEqual< K, Key >::val >::NextType NextType;
};
template< class Pair, typename Map, unsigned index >
class AddKey< Pair, Map, index, NullItem >
{
public:
typedef List< Pair, Map > NextType;
};
template< class Key, typename Map, unsigned index = 0, typename Forward = Map >
class EraseKey
{
template< typename K, typename M, unsigned i, typename F, int eq >
class EraseKeyR
{
public:
typedef typename EraseAtIndex< M, i >::NextType NextType;
};
template< typename K, typename M, unsigned i, typename F >
class EraseKeyR< K, M, i, F, 0 >
{
public:
typedef typename EraseKey< K, M, i + 1, typename Next< F >::NextType >::NextType NextType;
};
template< typename K, unsigned i, typename F, int eq > // empty map
class EraseKeyR< K, NullItem, i, F, eq >
{
public:
typedef NullItem NextType;
};
typedef typename Forward::value_type Item;
typedef typename Item::Key K;
public:
typedef typename EraseKeyR< Key, Map, index, Forward, TypeEqual< K, Key >::val >::NextType NextType;
};
template< class Key, typename Map, unsigned index >
class EraseKey< Key, Map, index, NullItem >
{
public:
typedef Map NextType;
};
template< typename Map1, typename Map2 >
class MergeMap
{
typedef typename Map2::value_type Pair2;
typedef typename Next<Map2>::NextType Forward;
typedef typename AddKey< Pair2, Map1 >::NextType MergedWithFirst;
public:
typedef typename MergeMap< MergedWithFirst, Forward >::NextType NextType;
};
template< typename Map1 >
class MergeMap< Map1, NullItem >
{
public:
typedef Map1 NextType;
};
template< typename Map2 >
class MergeMap< NullItem, Map2 >
{
public:
typedef Map2 NextType;
};
template<>
class MergeMap< NullItem, NullItem >
{
public:
typedef NullItem NextType;
};
template< typename Map >
class PrintMap
{
typedef typename Map::value_type PairType;
typedef typename PairType::Key K;
typedef typename PairType::Value V;
typedef typename Next< Map >::NextType Forward;
public:
static void Print()
{
std::cout << "(" << K::val << ", " << V::val << "),";
PrintMap< Forward >::Print();
}
};
template<>
class PrintMap< NullItem >
{
public:
static void Print()
{
std::cout << std::endl;
}
};
} // namespace map
} // namespace container
namespace prolog {
using namespace container::list;
using namespace container::map;
template< typename Predicate, typename ArgList >
struct Term
{
typedef Predicate Pred;
typedef ArgList Args;
};
template< typename Term, typename TermList >
struct Rule
{
typedef Term Head;
typedef TermList Goals;
};
template< typename Rule, typename Parent = NullItem, typename Env = NullItem, unsigned i = 0 >
struct Goal
{
typedef Rule R;
typedef Parent P;
typedef Env E;
static const unsigned index = i;
};
template< typename SrcTerm, typename SrcEnv, typename DestTerm, typename DestEnv >
class Unify
{
template< typename ST, typename SE, typename DT, typename DE, unsigned nArgs, int i >
class UnifyR
{
typedef typename Advance< typename ST::Args, i >::NextType STT;
typedef typename STT::value_type SrcArg;
enum { sVar = SrcArg::var };
typedef typename Advance< typename DT::Args, i >::NextType DTT;
typedef typename DTT::value_type DestArg;
enum { dVar = DestArg::var };
template< typename sArg, typename sEnv, int isVar >
struct DefineSrcVal
{
typedef typename FindKey< sArg, sEnv >::NextType FoundPair;
typedef typename GetPairValue< FoundPair >::Value Val;
};
template< typename sArg, typename sEnv >
struct DefineSrcVal< sArg, sEnv, 0 >
{
typedef sArg Val;
};
typedef typename DefineSrcVal< SrcArg, SE, sVar >::Val SrcVal;
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii, int eq >
class CompareWithSrcVal
{
typedef UnifyR< STi, SEi, DTi, DEi, nArgsi, ii + 1 > Result; // next iteration
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii >
class CompareWithSrcVal< STi, SEi, DTi, DEi, nArgsi, ii, 0 >
{
public:
typedef DEi ResultEnv;
enum { ret = 0 };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii, typename DestVal, int eq >
class CheckDestVal
{
typedef typename AddKey< Pair< DestArg, SrcVal >, DEi >::NextType Updated;
typedef UnifyR< STi, SEi, DTi, Updated, nArgsi, ii + 1 > Result; // next iteration
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii, typename DestVal >
class CheckDestVal< STi, SEi, DTi, DEi, nArgsi, ii, DestVal, 0 >
{
typedef CompareWithSrcVal< STi, SEi, DTi, DEi, nArgsi, ii, TypeEqual< DestVal, SrcVal >::val > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii, int eq >
class CheckDestArg
{
typedef typename FindKey< DestArg, DE >::NextType DestVal;
typedef CheckDestVal< STi, SEi, DTi, DEi, nArgsi, ii, DestVal, TypeEqual< DestVal, NullItem >::val > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii >
class CheckDestArg< STi, SEi, DTi, DEi, nArgsi, ii, 0 >
{
typedef CompareWithSrcVal< STi, SEi, DTi, DEi, nArgsi, ii, TypeEqual< DestArg, SrcVal >::val > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii, int eq >
class CheckSrcVal
{
typedef UnifyR< STi, SEi, DTi, DEi, nArgsi, ii + 1 > Result; // next iteration
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename STi, typename SEi, typename DTi, typename DEi, unsigned nArgsi, int ii >
class CheckSrcVal< STi, SEi, DTi, DEi, nArgsi, ii, 0 >
{
typedef CheckDestArg< STi, SEi, DTi, DEi, nArgsi, ii, dVar > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
typedef CheckSrcVal< ST, SE, DT, DE, nArgs, i, TypeEqual< SrcVal, NullItem >::val > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename ST, typename SE, typename DT, typename DE, unsigned nArgs >
class UnifyR< ST, SE, DT, DE, nArgs, nArgs >
{
public:
typedef DE ResultEnv;
enum { ret = 1 };
};
template< typename ST, typename SE, typename DT, typename DE, unsigned nArgs, int eq >
class CmpPred
{
typedef UnifyR< ST, SE, DT, DE, nArgs, 0 > Result;
public:
typedef typename Result::ResultEnv ResultEnv;
enum { ret = Result::ret };
};
template< typename ST, typename SE, typename DT, typename DE, unsigned nArgs >
class CmpPred< ST, SE, DT, DE, nArgs, 0 >
{