-
Notifications
You must be signed in to change notification settings - Fork 0
/
concepts.cpp
1168 lines (1037 loc) · 31.5 KB
/
concepts.cpp
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
#include <iostream>
#include <boost/mpl/size.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>//das kommt aber bitte nich in greatcontainer
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/set.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/copy_if.hpp>
#include <boost/mpl/inserter.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/erase_key.hpp>
namespace mpl = boost::mpl;
namespace stl {
namespace concepts {
struct container { };
struct random_access_container {
typedef mpl::vector1<container> implies;
};
struct adapter { };
struct sequence { };
struct type_holder { };
}
struct vector {
template<typename Before, typename After>
struct policy : public Before { };
typedef mpl::vector1<concepts::container> concept;
typedef mpl::vector1<concepts::type_holder> require_before;
};
template<typename T>
struct type {
template<typename Before, typename After>
struct policy : public Before {
typedef T value_type; // ...
};
typedef mpl::vector1<concepts::type_holder> concept;
};
struct stack {
template<typename Before, typename After>
struct policy : protected Before { };
typedef mpl::vector2<concepts::sequence, concepts::adapter> concept;
typedef mpl::vector2<concepts::type_holder, concepts::container> require_before;
typedef mpl::map1<mpl::pair<concepts::container, vector> > default_policy;
typedef boost::mpl::true_ shadow;
};
}
namespace concepts {
struct container {
};
struct random_access_container {
typedef mpl::vector1<container> implies;
};
struct foo {
typedef boost::mpl::false_ shadow;
};
struct bar {
typedef mpl::vector1<random_access_container> implies;
typedef boost::mpl::false_ shadow;
};
struct baz { typedef mpl::vector0< > implies; };
struct shads {
typedef mpl::vector1<random_access_container> implies;
typedef boost::mpl::true_ shadow;
};
struct implies_shads {
typedef mpl::vector1<shads> implies;
};
}
using namespace concepts;
struct policy0 {
template<typename Before, typename After>
struct policy : public Before { };
typedef mpl::vector2<container, foo> concept;
/* typedef mpl::vector<X> require;
typedef mpl::vector<X> require_before;
typedef mpl::vector<X> require_after;
typedef mpl::vector<X> demote_concepts;*/
};
struct policy1 {
template<typename Before, typename After>
struct policy : public Before { };
typedef mpl::vector1<bar> concept;
/*typedef mpl::vector<container> require;
typedef mpl::vector<X> require_before;
typedef mpl::vector<X> require_after;
typedef mpl::vector<X> demote_concepts;*/
};
struct policy2 {
template<typename Before, typename After>
struct policy : public Before { };
typedef mpl::vector1<random_access_container> concept;
/*typedef mpl::vector<container> require;
typedef mpl::vector<X> require_before;
typedef mpl::vector<X> require_after;
typedef mpl::vector<X> demote_concepts;*/
};
struct policy3 {
template<typename Before, typename After>
struct policy : public Before { };
typedef mpl::vector1<foo> concept;
typedef mpl::vector1<container> require_before;
/* typedef mpl::vector<X> require_before;
typedef mpl::vector<X> require_after;
typedef mpl::vector<X> demote_concepts;*/
};
template<typename Sequence>
struct policy_holder {
//
};
namespace utils {
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(implies)
template<typename PolicySeq, typename Concept,
bool empty = mpl::empty<PolicySeq>::value>
struct checker {
typedef typename mpl::front<PolicySeq>::type checked_concept;
template<typename CheckedConcept, bool = has_implies<CheckedConcept>::value>
struct implies {
static bool const value =
checker<typename CheckedConcept::implies, Concept>::value;
};
template<typename CheckedConcept>
struct implies<CheckedConcept, false> {
static bool const value = false;
};
static bool const value =
boost::is_same<checked_concept, Concept>::value ?
true :
( implies<checked_concept>::value ?
true :
checker<typename mpl::pop_front<PolicySeq>::type, Concept>::value);
};
template<typename PolicySeq, typename Concept>
struct checker<PolicySeq, Concept, true> {
static bool const value = false;
};
}
template<typename PolicyClass, typename Concept>
struct supports_concept
: boost::integral_constant<bool, detail::checker<typename PolicyClass::concept, Concept>::value>
{};
template<typename PolicyList, typename Concept>
struct has_concept
: boost::mpl::not_<
boost::is_same<
typename boost::mpl::find_if<
PolicyList,
supports_concept<boost::mpl::_1, Concept>
>::type,
typename boost::mpl::end<PolicyList>::type
>
>::type
{ };
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(require)
BOOST_MPL_HAS_XXX_TRAIT_DEF(require_before)
BOOST_MPL_HAS_XXX_TRAIT_DEF(require_after)
template<
typename Requirements,
typename Sequence,
bool empty = boost::mpl::empty<Requirements>::value
>
struct check_requirements
: boost::mpl::and_<
typename has_concept<
Sequence,
typename boost::mpl::front<Requirements>::type
>::type,
typename check_requirements<
typename boost::mpl::pop_front<Requirements>::type,
Sequence
>::type
>
{ };
template<
typename Requirements,
typename Sequence
>
struct check_requirements<Requirements, Sequence, true>
: boost::mpl::true_ { };
template<typename Sequence, typename Iterator>
struct check_requirements_all {
typedef typename detail::check_requirements<
typename boost::mpl::deref<Iterator>::type::require,
Sequence
>::type type;
};
template<typename Sequence, typename Iterator>
struct check_requirements_before {
typedef typename detail::check_requirements<
typename boost::mpl::deref<Iterator>::type::require_before,
boost::mpl::iterator_range<
typename boost::mpl::begin<Sequence>::type,
Iterator
>
>::type type;
};
template<typename Sequence, typename Iterator>
struct check_requirements_after {
typedef typename detail::check_requirements<
typename boost::mpl::deref<Iterator>::type::require_after,
boost::mpl::iterator_range<
typename boost::mpl::next<Iterator>::type,
typename boost::mpl::end<Sequence>::type
>
>::type type;
};
}
template<typename Sequence,
typename Iterator = typename boost::mpl::begin<Sequence>::type>
struct check_concepts;
namespace detail {
template<typename Sequence, typename Iterator>
struct check_concepts_impl
{
typedef
boost::mpl::and_<
check_concepts<
Sequence,
typename boost::mpl::next<Iterator>::type
>,
boost::mpl::eval_if<
detail::has_require<
typename boost::mpl::deref<Iterator>::type
>,
detail::check_requirements_all<Sequence, Iterator>,
boost::mpl::true_
>,
boost::mpl::eval_if<
detail::has_require_before<
typename boost::mpl::deref<Iterator>::type
>,
detail::check_requirements_before<Sequence, Iterator>,
boost::mpl::true_
>,
boost::mpl::eval_if<
detail::has_require_after<
typename boost::mpl::deref<Iterator>::type
>,
detail::check_requirements_after<Sequence, Iterator>,
boost::mpl::true_
>
>
type;
};
}
template<typename Sequence,
typename Iterator>
struct check_concepts
: boost::mpl::eval_if<
boost::is_same<Iterator, typename boost::mpl::end<Sequence>::type>,
boost::mpl::true_,
detail::check_concepts_impl<Sequence, Iterator>
>::type
{ };
namespace detail {
template<typename First, typename Last, typename Result>
struct flatten {
typedef typename boost::mpl::deref<First>::type deref;
template<typename T>
struct subflatten {
typedef
typename flatten<
typename boost::mpl::begin<typename T::implies>::type,
typename boost::mpl::end<typename T::implies>::type,
boost::mpl::vector0<>
>::type type;
};
typedef typename boost::mpl::insert_range<
Result,
typename boost::mpl::end<Result>::type,
typename boost::mpl::eval_if<
has_implies<deref>,
subflatten<deref>,
mpl::vector0<>
>::type
>::type with_implies;
typedef typename boost::mpl::insert<
with_implies,
typename boost::mpl::end<with_implies>::type,
deref
>::type with_deref;
typedef typename flatten<
typename boost::mpl::next<First>::type,
Last,
with_deref
>::type type;
};
template<typename First, typename Result>
struct flatten<First, First, Result> {
typedef Result type;
};
}
template<typename Sequence>
struct flatten {
typedef typename detail::flatten<
typename boost::mpl::begin<Sequence>::type,
typename boost::mpl::end<Sequence>::type,
boost::mpl::vector0<>
>::type
type;
};
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(shadow)
template<typename Concept, bool x = has_shadow<Concept>::value>
struct is_shadowing
: Concept::shadow
{ };
template<typename Concept>
struct is_shadowing<Concept, false>
: boost::mpl::false_
{ };
template<typename ConceptSeq,
typename Iterator = typename boost::mpl::begin<ConceptSeq>::type>
struct is_shadowing_concept_seq;
template<typename Concept, bool x = has_implies<Concept>::value>
struct is_shadowing_implies
: is_shadowing_concept_seq<typename Concept::implies>
{ };
template<typename Concept>
struct is_shadowing_implies<Concept, false>
: boost::mpl::false_
{ };
template<typename ConceptSeq, typename Iterator>
struct is_shadowing_concept_seq
: boost::mpl::eval_if<
is_shadowing<
typename boost::mpl::deref<Iterator>::type
>,
boost::mpl::true_,
boost::mpl::or_<
typename is_shadowing_implies<
typename boost::mpl::deref<Iterator>::type
>::type,
typename is_shadowing_concept_seq<
ConceptSeq,
typename boost::mpl::next<Iterator>::type
>::type
>
>::type
{ };
template<typename ConceptSeq>
struct is_shadowing_concept_seq
<
ConceptSeq,
typename boost::mpl::end<ConceptSeq>::type
>
: boost::mpl::false_
{ };
template<typename Concept>
struct is_shadowing_concept
: boost::mpl::or_<
typename is_shadowing<Concept>::type,
typename is_shadowing_implies<Concept>::type
>::type
{ };
template<
typename Sequence,
typename Iterator = typename boost::mpl::begin<Sequence>::type
>
struct do_shadowing {
typedef typename
boost::mpl::eval_if<
is_shadowing_concept<typename boost::mpl::deref<Iterator>::type>,
do_shadowing<
boost::mpl::iterator_range<
Iterator,
typename boost::mpl::end<Sequence>::type
>,
typename boost::mpl::next<Iterator>::type
>,
do_shadowing<
Sequence,
typename boost::mpl::next<Iterator>::type
>
>::type type;
};
template<typename Sequence>
struct do_shadowing<
Sequence,
typename boost::mpl::end<Sequence>::type
>
{
typedef Sequence type;
};
template<typename SeqA, typename SeqB>
struct concat {
typedef typename boost::mpl::insert_range<
SeqA,
typename boost::mpl::end<SeqA>::type,
SeqB
>::type type;
};
template<typename PolicySeq,
bool empty = boost::mpl::empty<PolicySeq>::value >
struct get_list_of_concepts {
typedef typename concat<
typename boost::mpl::front<PolicySeq>::type::concept,
typename get_list_of_concepts<
typename boost::mpl::pop_front<PolicySeq>::type
>::type
>::type
type;
};
template<typename PolicySeq>
struct get_list_of_concepts<PolicySeq, true> {
typedef PolicySeq type;
};
}
template<typename PolicySeq>
struct resulting_concept {
typedef typename flatten<
typename detail::do_shadowing<
typename detail::get_list_of_concepts<PolicySeq>::type
>::type
>::type
type;
};
namespace detail {
template<
typename PolicySeq,
typename Concept,
bool no_policies_left = boost::mpl::empty<PolicySeq>::value
>
struct get_matching_policy {
typedef typename boost::mpl::front<
PolicySeq
>::type front;
typedef typename boost::mpl::eval_if<
supports_concept<front, Concept>,
boost::mpl::identity<front>,
get_matching_policy<
typename boost::mpl::pop_front<
PolicySeq
>::type,
Concept
>
>::type type;
};
template<
typename PolicySeq,
typename Concept
>
struct get_matching_policy<
PolicySeq,
Concept,
true
>;
template<
typename Requirements,
typename PolicySeq,
typename Policy,
typename Graph,
template<typename, typename> class PairMaker,
bool no_requirements_left = boost::mpl::empty<Requirements>::value
>
struct policy_graph {
typedef typename PairMaker<
Policy,
typename get_matching_policy<
PolicySeq,
typename boost::mpl::front<Requirements>::type
>::type
>::type pair;
typedef boost::mpl::pair<
typename pair::first,
typename boost::mpl::insert<
typename boost::mpl::at<Graph, typename pair::first>::type,
typename pair::second
>::type
> real_pair;
typedef typename boost::mpl::insert<
Graph,
real_pair
>::type graph;
typedef typename policy_graph<
typename boost::mpl::pop_front<Requirements>::type,
PolicySeq,
Policy,
graph,
PairMaker
>::type type;
};
template<
typename Requirements,
typename PolicySeq,
typename Policy,
typename Graph,
template<typename, typename> class PairMaker
>
struct policy_graph<
Requirements,
PolicySeq,
Policy,
Graph,
PairMaker,
true
> {
typedef Graph type;
};
template<typename From, typename To>
struct before_pair {
typedef boost::mpl::pair<From, To> type;
};
template<typename To, typename From>
struct after_pair {
typedef boost::mpl::pair<From, To> type;
};
template<
typename PolicySeq,
typename Policy,
typename Graph,
bool has_require_before = has_require_before<Policy>::value
>
struct policy_graph_before {
typedef typename policy_graph<
typename Policy::require_before,
PolicySeq,
Policy,
Graph,
before_pair
>::type type;
};
template<typename PolicySeq, typename Policy, typename Graph>
struct policy_graph_before<PolicySeq, Policy, Graph, false> {
typedef Graph type;
};
template<
typename PolicySeq,
typename Policy,
typename Graph,
bool has_require_after = has_require_after<Policy>::value
>
struct policy_graph_after {
typedef typename policy_graph<
typename Policy::require_after,
PolicySeq,
Policy,
Graph,
after_pair
>::type type;
};
template<typename PolicySeq, typename Policy, typename Graph>
struct policy_graph_after<PolicySeq, Policy, Graph, false> {
typedef Graph type;
};
template<
typename PolicySeq,
bool empty = boost::mpl::empty<PolicySeq>::value
>
struct init_graph {
typedef typename boost::mpl::insert<
typename init_graph<
typename boost::mpl::pop_front<PolicySeq>::type
>::type,
boost::mpl::pair<
typename boost::mpl::front<PolicySeq>::type,
boost::mpl::set0<>
>
>::type type;
};
template<typename PolicySeq>
struct init_graph<PolicySeq, true> {
typedef boost::mpl::map0<> type;
};
template<
typename Graph,
typename First = typename boost::mpl::begin<Graph>::type,
typename Last = typename boost::mpl::end<Graph>::type,
typename Result = boost::mpl::map0<>
>
struct clean_graph {
typedef typename boost::mpl::deref<First>::type::first key;
typedef typename boost::mpl::if_<
typename boost::mpl::has_key<
Result,
key
>::type,
Result,
typename boost::mpl::insert<
Result,
boost::mpl::pair<
key,
typename boost::mpl::at<
Graph,
key
>::type
>
>::type
>::type next;
typedef typename clean_graph<
Graph,
typename boost::mpl::next<First>::type,
Last,
next
>::type type;
};
template<typename Graph, typename First, typename Result>
struct clean_graph<Graph, First, First, Result> {
typedef Result type;
};
template<
typename PolicySeq,
typename Graph = typename init_graph<PolicySeq>::type,
bool = boost::mpl::empty<PolicySeq>::value
>
struct order_graph {
typedef typename boost::mpl::front<PolicySeq>::type policy;
typedef typename policy_graph_before<
PolicySeq,
policy,
Graph
>::type before;
typedef typename policy_graph_after<
PolicySeq,
policy,
before
>::type after;
typedef typename order_graph<
typename boost::mpl::pop_front<PolicySeq>::type,
after
>::type type;
};
template<typename PolicySeq, typename Graph>
struct order_graph<PolicySeq, Graph, true> {
typedef typename clean_graph<Graph>::type type;
};
template<
typename Result,
typename After,
typename First,
typename Last
>
struct add_edges {
typedef typename boost::mpl::deref<First>::type x;
typedef typename boost::mpl::if_<
typename boost::mpl::has_key<Result, x>::type,
typename boost::mpl::at<Result, x>::type,
boost::mpl::set0<>
>::type old;
typedef boost::mpl::pair<
x,
typename boost::mpl::insert<
old,
After
>::type
> new_pair;
typedef typename boost::mpl::insert<
Result,
new_pair
>::type new_result;
typedef typename add_edges<
new_result,
After,
typename boost::mpl::next<First>::type,
Last
>::type type;
};
template<typename Result, typename After, typename First>
struct add_edges<Result, After, First, First> {
typedef Result type;
};
template<
typename First,
typename Last,
typename Result
>
struct reverse_graph {
typedef typename boost::mpl::deref<First>::type x;
typedef typename x::first after;
typedef typename x::second before;
typedef typename reverse_graph<
typename boost::mpl::next<First>::type,
Last,
typename add_edges<
Result,
after,
typename boost::mpl::begin<before>::type,
typename boost::mpl::end<before>::type
>::type
>::type type;
};
template<typename First, typename Result>
struct reverse_graph<First, First, Result> {
typedef typename clean_graph<Result>::type type;
};
template<
typename PolicySeq,
typename Policies,
typename Graph,
typename Result = boost::mpl::vector0<>,
typename NIt = typename boost::mpl::find_if<
Policies,
boost::mpl::empty<
boost::mpl::at<
Graph,
boost::mpl::_1
>
>
>::type,
typename End = typename boost::mpl::end<Policies>::type
>
struct reorder {
typedef typename boost::mpl::deref<NIt>::type N;
typedef typename boost::mpl::push_back<
Result,
N
>::type next;
typedef typename reverse_graph<
typename boost::mpl::begin<Graph>::type,
typename boost::mpl::end<Graph>::type,
typename init_graph<PolicySeq>::type
>::type reverse;
typedef typename clean_graph<
typename boost::mpl::insert<
reverse,
boost::mpl::pair<
N,
boost::mpl::set0<>
>
>::type
>::type deconnect_N;
typedef typename reverse_graph<
typename boost::mpl::begin<deconnect_N>::type,
typename boost::mpl::end<deconnect_N>::type,
typename init_graph<PolicySeq>::type
>::type next_graph;
typedef typename reorder<
PolicySeq,
typename boost::mpl::erase_key<
Policies,
N
>::type,
next_graph,
next
>::type type;
};
template<
typename PolicySeq,
typename Policies,
typename Graph,
typename Result,
typename It
>
struct reorder<PolicySeq, Policies, Graph, Result, It, It> {
// check for cycles
BOOST_STATIC_ASSERT((
boost::is_same<
typename boost::mpl::find_if<
Graph,
boost::mpl::not_<
boost::mpl::empty<
boost::mpl::second<
boost::mpl::_1
>
>
>
>::type,
typename boost::mpl::end<Graph>::type
>::value
));
typedef Result type;
};
}
/*
while (N = find node without incoming edge (Graph) )
output N
Graph = reverse<insert<reverse<Graph>, pair<N, set0<> > > > -- remove all edges E from N to M in Graph
*/
template<typename PolicySeq>
struct reorder {
typedef typename boost::mpl::copy<
PolicySeq,
boost::mpl::inserter<
boost::mpl::set0<>,
boost::mpl::insert<boost::mpl::_1, boost::mpl::_2>
>
>::type policies;
typedef typename detail::order_graph<PolicySeq>::type graph;
typedef typename detail::reorder<PolicySeq, policies, graph>::type type;
};
namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(default_policy)
template<
typename Policy,
bool has = has_require_before<Policy>::value
>
struct get_requirements_before {
typedef typename Policy::require_before type;
};
template<typename Policy>
struct get_requirements_before<Policy, false> {
typedef boost::mpl::vector0< > type;
};
template<
typename Policy,
bool has = has_require_after<Policy>::value
>
struct get_requirements_after {
typedef typename Policy::require_after type;
};
template<typename Policy>
struct get_requirements_after<Policy, false> {
typedef boost::mpl::vector0< > type;
};
template<
typename Policy,
bool has = has_require<Policy>::value
>
struct get_requirements {
typedef typename Policy::require type;
};
template<typename Policy>
struct get_requirements<Policy, false> {
typedef boost::mpl::vector0< > type;
};
template<
typename Policy,
typename Concept,
typename DefaultPolicy = typename Policy::default_policy
>
struct default_policy {
BOOST_STATIC_ASSERT((boost::mpl::has_key<DefaultPolicy, Concept>::value));
typedef typename boost::mpl::at<DefaultPolicy, Concept>::type type;
};
template<
typename Policy,
typename Concept
>
struct get_default_for {
BOOST_STATIC_ASSERT((has_default_policy<Policy, Concept>::value));
typedef typename default_policy<Policy, Concept>::type type;
};
template<typename Seq, typename Policy, typename Requirement>
struct add_default {
typedef typename boost::mpl::push_back<
Seq,
typename get_default_for<
Policy,
Requirement
>::type
>::type type;
};
template<
typename Policy,
typename Requirements,
typename PolicySeq,
bool no_requirements_left = boost::mpl::empty<Requirements>::value
>
struct match_or_apply_default_policy {
typedef typename boost::mpl::front<Requirements>::type requirement;
typedef typename boost::mpl::pop_front<Requirements>::type requ_seq;
typedef typename match_or_apply_default_policy<
Policy,
requ_seq,
PolicySeq
>::type next_default;
typedef typename boost::mpl::eval_if<
has_concept<
PolicySeq,
requirement
>,
boost::mpl::identity<next_default>,
add_default<next_default, Policy, requirement>
>::type type;
};
template<
typename Policy,
typename Requirements,
typename PolicySeq
>
struct match_or_apply_default_policy<
Policy,
Requirements,
PolicySeq,
true
>
{
typedef boost::mpl::vector0< > type;
};
template<
typename PolicySeq,
long i = 0,
long n = boost::mpl::size<PolicySeq>::value
>
struct apply_default_policies {
typedef typename boost::mpl::at_c<PolicySeq, i>::type policy;