-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconcept_check.hpp
1076 lines (948 loc) · 33.8 KB
/
concept_check.hpp
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) Copyright Jeremy Siek 2000. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
//
// Revision History:
// 05 May 2001: Workarounds for HP aCC from Thomas Matelich. (Jeremy Siek)
// 02 April 2001: Removed limits header altogether. (Jeremy Siek)
// 01 April 2001: Modified to use new <boost/limits.hpp> header. (JMaddock)
//
// See http://www.boost.org/libs/concept_check for documentation.
#ifndef BOOST_CONCEPT_CHECKS_HPP
#define BOOST_CONCEPT_CHECKS_HPP
#include <boost/config.hpp>
#include <boost/iterator.hpp>
#include <boost/type_traits/conversion_traits.hpp>
#include <utility>
#include <boost/type_traits/conversion_traits.hpp>
#include <boost/static_assert.hpp>
#include <boost/type.hpp>
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__BORLANDC__)
#define BOOST_FPTR
#else
#define BOOST_FPTR &
#endif
namespace boost {
/*
"inline" is used for ignore_unused_variable_warning()
and function_requires() to make sure there is no
overhead with g++.
*/
template <class T> inline void ignore_unused_variable_warning(const T&) { }
// the unused, defaulted parameter is a workaround for MSVC and Compaq C++
template <class Concept>
inline void function_requires(type<Concept>* = 0)
{
#if !defined(NDEBUG)
void (Concept::*x)() = BOOST_FPTR Concept::constraints;
ignore_unused_variable_warning(x);
#endif
}
#define BOOST_CLASS_REQUIRE(type_var, ns, concept) \
typedef void (ns::concept <type_var>::* func##type_var##concept)(); \
template <func##type_var##concept _Tp1> \
struct concept_checking_##type_var##concept { }; \
typedef concept_checking_##type_var##concept< \
BOOST_FPTR ns::concept<type_var>::constraints> \
concept_checking_typedef_##type_var##concept
#define BOOST_CLASS_REQUIRE2(type_var1, type_var2, ns, concept) \
typedef void (ns::concept <type_var1,type_var2>::* \
func##type_var1##type_var2##concept)(); \
template <func##type_var1##type_var2##concept _Tp1> \
struct concept_checking_##type_var1##type_var2##concept { }; \
typedef concept_checking_##type_var1##type_var2##concept< \
BOOST_FPTR ns::concept<type_var1,type_var2>::constraints> \
concept_checking_typedef_##type_var1##type_var2##concept
#define BOOST_CLASS_REQUIRE3(tv1, tv2, tv3, ns, concept) \
typedef void (ns::concept <tv1,tv2,tv3>::* \
func##tv1##tv2##tv3##concept)(); \
template <func##tv1##tv2##tv3##concept _Tp1> \
struct concept_checking_##tv1##tv2##tv3##concept { }; \
typedef concept_checking_##tv1##tv2##tv3##concept< \
BOOST_FPTR ns::concept<tv1,tv2,tv3>::constraints> \
concept_checking_typedef_##tv1##tv2##tv3##concept
#define BOOST_CLASS_REQUIRE4(tv1, tv2, tv3, tv4, ns, concept) \
typedef void (ns::concept <tv1,tv2,tv3,tv4>::* \
func##tv1##tv2##tv3##tv4##concept)(); \
template <func##tv1##tv2##tv3##tv4##concept _Tp1> \
struct concept_checking_##tv1##tv2##tv3##tv4##concept { }; \
typedef concept_checking_##tv1##tv2##tv3##tv4##concept< \
BOOST_FPTR ns::concept<tv1,tv2,tv3,tv4>::constraints> \
concept_checking_typedef_##tv1##tv2##tv3##tv4##concept
// NOTE: The BOOST_CLASS_REQUIRES (with an 'S' at the end) is deprecated.
// The BOOST_CLASS_REQUIRES macros use function pointers as
// template parameters, which VC++ does not support.
#if defined(BOOST_NO_FUNCTION_PTR_TEMPLATE_PARAMETERS)
#define BOOST_CLASS_REQUIRES(type_var, concept)
#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept)
#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept)
#define BOOST_CLASS_REQUIRES4(type_var1, type_var2, type_var3, type_var4, concept)
#else
#define BOOST_CLASS_REQUIRES(type_var, concept) \
typedef void (concept <type_var>::* func##type_var##concept)(); \
template <func##type_var##concept _Tp1> \
struct concept_checking_##type_var##concept { }; \
typedef concept_checking_##type_var##concept< \
BOOST_FPTR concept <type_var>::constraints> \
concept_checking_typedef_##type_var##concept
#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept) \
typedef void (concept <type_var1,type_var2>::* func##type_var1##type_var2##concept)(); \
template <func##type_var1##type_var2##concept _Tp1> \
struct concept_checking_##type_var1##type_var2##concept { }; \
typedef concept_checking_##type_var1##type_var2##concept< \
BOOST_FPTR concept <type_var1,type_var2>::constraints> \
concept_checking_typedef_##type_var1##type_var2##concept
#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept) \
typedef void (concept <type_var1,type_var2,type_var3>::* func##type_var1##type_var2##type_var3##concept)(); \
template <func##type_var1##type_var2##type_var3##concept _Tp1> \
struct concept_checking_##type_var1##type_var2##type_var3##concept { }; \
typedef concept_checking_##type_var1##type_var2##type_var3##concept< \
BOOST_FPTR concept <type_var1,type_var2,type_var3>::constraints> \
concept_checking_typedef_##type_var1##type_var2##type_var3##concept
#define BOOST_CLASS_REQUIRES4(type_var1, type_var2, type_var3, type_var4, concept) \
typedef void (concept <type_var1,type_var2,type_var3,type_var4>::* func##type_var1##type_var2##type_var3##type_var4##concept)(); \
template <func##type_var1##type_var2##type_var3##type_var4##concept _Tp1> \
struct concept_checking_##type_var1##type_var2##type_var3##type_var4##concept { }; \
typedef concept_checking_##type_var1##type_var2##type_var3##type_var4##concept< \
BOOST_FPTR concept <type_var1,type_var2,type_var3,type_var4>::constraints> \
concept_checking_typedef_##type_var1##type_var2##type_var3##type_var4##concept
#endif
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T, class U>
struct require_same { };
template <class T>
struct require_same<T,T> { typedef T type; };
#else
// This version does not perform checking, but will not do any harm.
template <class T, class U>
struct require_same { typedef T type; };
#endif
template <class T>
struct IntegerConcept {
void constraints() {
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
x.error_type_must_be_an_integer_type();
#endif
}
T x;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <> struct IntegerConcept<short> { void constraints() {} };
template <> struct IntegerConcept<unsigned short> { void constraints() {} };
template <> struct IntegerConcept<int> { void constraints() {} };
template <> struct IntegerConcept<unsigned int> { void constraints() {} };
template <> struct IntegerConcept<long> { void constraints() {} };
template <> struct IntegerConcept<unsigned long> { void constraints() {} };
// etc.
#endif
template <class T>
struct SignedIntegerConcept {
void constraints() {
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
x.error_type_must_be_a_signed_integer_type();
#endif
}
T x;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <> struct SignedIntegerConcept<short> { void constraints() {} };
template <> struct SignedIntegerConcept<int> { void constraints() {} };
template <> struct SignedIntegerConcept<long> { void constraints() {} };
# if defined(BOOST_HAS_LONG_LONG)
template <> struct SignedIntegerConcept<long long> { void constraints() {} };
# endif
// etc.
#endif
template <class T>
struct UnsignedIntegerConcept {
void constraints() {
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
x.error_type_must_be_an_unsigned_integer_type();
#endif
}
T x;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <> struct UnsignedIntegerConcept<unsigned short>
{ void constraints() {} };
template <> struct UnsignedIntegerConcept<unsigned int>
{ void constraints() {} };
template <> struct UnsignedIntegerConcept<unsigned long>
{ void constraints() {} };
// etc.
#endif
//===========================================================================
// Basic Concepts
template <class TT>
struct DefaultConstructibleConcept
{
void constraints() {
TT a; // require default constructor
ignore_unused_variable_warning(a);
}
};
template <class TT>
struct AssignableConcept
{
void constraints() {
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = a; // require assignment operator
#endif
const_constraints(a);
}
void const_constraints(const TT& b) {
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = b; // const required for argument to assignment
#endif
}
TT a;
};
template <class TT>
struct CopyConstructibleConcept
{
void constraints() {
TT a(b); // require copy constructor
TT* ptr = &a; // require address of operator
const_constraints(a);
ignore_unused_variable_warning(ptr);
}
void const_constraints(const TT& a) {
TT c(a); // require const copy constructor
const TT* ptr = &a; // require const address of operator
ignore_unused_variable_warning(c);
ignore_unused_variable_warning(ptr);
}
TT b;
};
// The SGI STL version of Assignable requires copy constructor and operator=
template <class TT>
struct SGIAssignableConcept
{
void constraints() {
TT b(a);
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = a; // require assignment operator
#endif
const_constraints(a);
ignore_unused_variable_warning(b);
}
void const_constraints(const TT& b) {
TT c(b);
#if !defined(_ITERATOR_) // back_insert_iterator broken for VC++ STL
a = b; // const required for argument to assignment
#endif
ignore_unused_variable_warning(c);
}
TT a;
};
template <class X, class Y>
struct ConvertibleConcept
{
void constraints() {
Y y = x;
ignore_unused_variable_warning(y);
}
X x;
};
// The C++ standard requirements for many concepts talk about return
// types that must be "convertible to bool". The problem with this
// requirement is that it leaves the door open for evil proxies that
// define things like operator|| with strange return types. Two
// possible solutions are:
// 1) require the return type to be exactly bool
// 2) stay with convertible to bool, and also
// specify stuff about all the logical operators.
// For now we just test for convertible to bool.
template <class TT>
void require_boolean_expr(const TT& t) {
bool x = t;
ignore_unused_variable_warning(x);
}
template <class TT>
struct EqualityComparableConcept
{
void constraints() {
require_boolean_expr(a == b);
require_boolean_expr(a != b);
}
TT a, b;
};
template <class TT>
struct LessThanComparableConcept
{
void constraints() {
require_boolean_expr(a < b);
}
TT a, b;
};
// This is equivalent to SGI STL's LessThanComparable.
template <class TT>
struct ComparableConcept
{
void constraints() {
require_boolean_expr(a < b);
require_boolean_expr(a > b);
require_boolean_expr(a <= b);
require_boolean_expr(a >= b);
}
TT a, b;
};
#define BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(OP,NAME) \
template <class First, class Second> \
struct NAME { \
void constraints() { (void)constraints_(); } \
bool constraints_() { \
return a OP b; \
} \
First a; \
Second b; \
}
#define BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(OP,NAME) \
template <class Ret, class First, class Second> \
struct NAME { \
void constraints() { (void)constraints_(); } \
Ret constraints_() { \
return a OP b; \
} \
First a; \
Second b; \
}
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, EqualOpConcept);
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(!=, NotEqualOpConcept);
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<, LessThanOpConcept);
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(<=, LessEqualOpConcept);
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>, GreaterThanOpConcept);
BOOST_DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(>=, GreaterEqualOpConcept);
BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(+, PlusOpConcept);
BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(*, TimesOpConcept);
BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(/, DivideOpConcept);
BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(-, SubtractOpConcept);
BOOST_DEFINE_BINARY_OPERATOR_CONSTRAINT(%, ModOpConcept);
//===========================================================================
// Function Object Concepts
template <class Func, class Return>
struct GeneratorConcept
{
void constraints() {
const Return& r = f(); // require operator() member function
ignore_unused_variable_warning(r);
}
Func f;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Func>
struct GeneratorConcept<Func,void>
{
void constraints() {
f(); // require operator() member function
}
Func f;
};
#endif
template <class Func, class Return, class Arg>
struct UnaryFunctionConcept
{
// required in case any of our template args are const-qualified:
UnaryFunctionConcept();
void constraints() {
r = f(arg); // require operator()
}
Func f;
Arg arg;
Return r;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Func, class Arg>
struct UnaryFunctionConcept<Func, void, Arg> {
void constraints() {
f(arg); // require operator()
}
Func f;
Arg arg;
};
#endif
template <class Func, class Return, class First, class Second>
struct BinaryFunctionConcept
{
void constraints() {
r = f(first, second); // require operator()
}
Func f;
First first;
Second second;
Return r;
};
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class Func, class First, class Second>
struct BinaryFunctionConcept<Func, void, First, Second>
{
void constraints() {
f(first, second); // require operator()
}
Func f;
First first;
Second second;
};
#endif
template <class Func, class Arg>
struct UnaryPredicateConcept
{
void constraints() {
require_boolean_expr(f(arg)); // require operator() returning bool
}
Func f;
Arg arg;
};
template <class Func, class First, class Second>
struct BinaryPredicateConcept
{
void constraints() {
require_boolean_expr(f(a, b)); // require operator() returning bool
}
Func f;
First a;
Second b;
};
// use this when functor is used inside a container class like std::set
template <class Func, class First, class Second>
struct Const_BinaryPredicateConcept {
void constraints() {
const_constraints(f);
}
void const_constraints(const Func& fun) {
function_requires<BinaryPredicateConcept<Func, First, Second> >();
// operator() must be a const member function
require_boolean_expr(fun(a, b));
}
Func f;
First a;
Second b;
};
template <class Func, class Return>
struct AdaptableGeneratorConcept
{
void constraints() {
typedef typename Func::result_type result_type;
BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
function_requires< GeneratorConcept<Func, result_type> >();
}
};
template <class Func, class Return, class Arg>
struct AdaptableUnaryFunctionConcept
{
void constraints() {
typedef typename Func::argument_type argument_type;
typedef typename Func::result_type result_type;
BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
BOOST_STATIC_ASSERT((is_convertible<Arg, argument_type>::value));
function_requires< UnaryFunctionConcept<Func, result_type, argument_type> >();
}
};
template <class Func, class Return, class First, class Second>
struct AdaptableBinaryFunctionConcept
{
void constraints() {
typedef typename Func::first_argument_type first_argument_type;
typedef typename Func::second_argument_type second_argument_type;
typedef typename Func::result_type result_type;
BOOST_STATIC_ASSERT((is_convertible<result_type, Return>::value));
BOOST_STATIC_ASSERT((is_convertible<First, first_argument_type>::value));
BOOST_STATIC_ASSERT((is_convertible<Second, second_argument_type>::value));
function_requires< BinaryFunctionConcept<Func, result_type,
first_argument_type, second_argument_type> >();
}
};
template <class Func, class Arg>
struct AdaptablePredicateConcept
{
void constraints() {
function_requires< UnaryPredicateConcept<Func, Arg> >();
function_requires< AdaptableUnaryFunctionConcept<Func, bool, Arg> >();
}
};
template <class Func, class First, class Second>
struct AdaptableBinaryPredicateConcept
{
void constraints() {
function_requires< BinaryPredicateConcept<Func, First, Second> >();
function_requires< AdaptableBinaryFunctionConcept<Func, bool, First, Second> >();
}
};
//===========================================================================
// Iterator Concepts
template <class TT>
struct TrivialIteratorConcept
{
void constraints() {
function_requires< AssignableConcept<TT> >();
function_requires< DefaultConstructibleConcept<TT> >();
function_requires< EqualityComparableConcept<TT> >();
(void)*i; // require dereference operator
}
TT i;
};
template <class TT>
struct Mutable_TrivialIteratorConcept
{
void constraints() {
function_requires< TrivialIteratorConcept<TT> >();
*i = *j; // require dereference and assignment
}
TT i, j;
};
template <class TT>
struct InputIteratorConcept
{
void constraints() {
function_requires< TrivialIteratorConcept<TT> >();
// require iterator_traits typedef's
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<TT>::difference_type D;
// Hmm, the following is a bit fragile
//function_requires< SignedIntegerConcept<D> >();
typedef typename std::iterator_traits<TT>::reference R;
typedef typename std::iterator_traits<TT>::pointer P;
typedef typename std::iterator_traits<TT>::iterator_category C;
function_requires< ConvertibleConcept<C, std::input_iterator_tag> >();
#endif
++i; // require preincrement operator
i++; // require postincrement operator
}
TT i;
};
template <class TT, class ValueT>
struct OutputIteratorConcept
{
void constraints() {
function_requires< AssignableConcept<TT> >();
++i; // require preincrement operator
i++; // require postincrement operator
*i++ = t; // require postincrement and assignment
}
TT i, j;
ValueT t;
};
template <class TT>
struct ForwardIteratorConcept
{
void constraints() {
function_requires< InputIteratorConcept<TT> >();
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<TT>::iterator_category C;
function_requires< ConvertibleConcept<C, std::forward_iterator_tag> >();
typedef typename std::iterator_traits<TT>::reference reference;
reference r = *i;
ignore_unused_variable_warning(r);
#endif
}
TT i;
};
template <class TT>
struct Mutable_ForwardIteratorConcept
{
void constraints() {
function_requires< ForwardIteratorConcept<TT> >();
*i++ = *i; // require postincrement and assignment
}
TT i;
};
template <class TT>
struct BidirectionalIteratorConcept
{
void constraints() {
function_requires< ForwardIteratorConcept<TT> >();
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<TT>::iterator_category C;
function_requires< ConvertibleConcept<C,
std::bidirectional_iterator_tag> >();
#endif
--i; // require predecrement operator
i--; // require postdecrement operator
}
TT i;
};
template <class TT>
struct Mutable_BidirectionalIteratorConcept
{
void constraints() {
function_requires< BidirectionalIteratorConcept<TT> >();
function_requires< Mutable_ForwardIteratorConcept<TT> >();
*i-- = *i; // require postdecrement and assignment
}
TT i;
};
template <class TT>
struct RandomAccessIteratorConcept
{
void constraints() {
function_requires< BidirectionalIteratorConcept<TT> >();
function_requires< ComparableConcept<TT> >();
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typedef typename std::iterator_traits<TT>::iterator_category C;
function_requires< ConvertibleConcept< C,
std::random_access_iterator_tag> >();
typedef typename std::iterator_traits<TT>::reference R;
#endif
i += n; // require assignment addition operator
i = i + n; i = n + i; // require addition with difference type
i -= n; // require assignment subtraction operator
i = i - n; // require subtraction with difference type
n = i - j; // require difference operator
(void)i[n]; // require element access operator
}
TT a, b;
TT i, j;
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typename std::iterator_traits<TT>::difference_type n;
#else
std::ptrdiff_t n;
#endif
};
template <class TT>
struct Mutable_RandomAccessIteratorConcept
{
void constraints() {
function_requires< RandomAccessIteratorConcept<TT> >();
function_requires< Mutable_BidirectionalIteratorConcept<TT> >();
i[n] = *i; // require element access and assignment
}
TT i;
#ifndef BOOST_NO_STD_ITERATOR_TRAITS
typename std::iterator_traits<TT>::difference_type n;
#else
std::ptrdiff_t n;
#endif
};
//===========================================================================
// Container Concepts
template <class Container>
struct ContainerConcept
{
typedef typename Container::value_type value_type;
typedef typename Container::difference_type difference_type;
typedef typename Container::size_type size_type;
typedef typename Container::const_reference const_reference;
typedef typename Container::const_pointer const_pointer;
typedef typename Container::const_iterator const_iterator;
void constraints() {
function_requires< InputIteratorConcept<const_iterator> >();
function_requires< AssignableConcept<Container> >();
const_constraints(c);
}
void const_constraints(const Container& c) {
i = c.begin();
i = c.end();
n = c.size();
n = c.max_size();
b = c.empty();
}
Container c;
bool b;
const_iterator i;
size_type n;
};
template <class Container>
struct Mutable_ContainerConcept
{
typedef typename Container::value_type value_type;
typedef typename Container::reference reference;
typedef typename Container::iterator iterator;
typedef typename Container::pointer pointer;
void constraints() {
function_requires< ContainerConcept<Container> >();
function_requires< AssignableConcept<value_type> >();
function_requires< InputIteratorConcept<iterator> >();
i = c.begin();
i = c.end();
c.swap(c2);
}
iterator i;
Container c, c2;
};
template <class ForwardContainer>
struct ForwardContainerConcept
{
void constraints() {
function_requires< ContainerConcept<ForwardContainer> >();
typedef typename ForwardContainer::const_iterator const_iterator;
function_requires< ForwardIteratorConcept<const_iterator> >();
}
};
template <class ForwardContainer>
struct Mutable_ForwardContainerConcept
{
void constraints() {
function_requires< ForwardContainerConcept<ForwardContainer> >();
function_requires< Mutable_ContainerConcept<ForwardContainer> >();
typedef typename ForwardContainer::iterator iterator;
function_requires< Mutable_ForwardIteratorConcept<iterator> >();
}
};
template <class ReversibleContainer>
struct ReversibleContainerConcept
{
typedef typename ReversibleContainer::const_iterator const_iterator;
typedef typename ReversibleContainer::const_reverse_iterator
const_reverse_iterator;
void constraints() {
function_requires< ForwardContainerConcept<ReversibleContainer> >();
function_requires< BidirectionalIteratorConcept<const_iterator> >();
function_requires<
BidirectionalIteratorConcept<const_reverse_iterator> >();
const_constraints(c);
}
void const_constraints(const ReversibleContainer& c) {
const_reverse_iterator i = c.rbegin();
i = c.rend();
}
ReversibleContainer c;
};
template <class ReversibleContainer>
struct Mutable_ReversibleContainerConcept
{
typedef typename ReversibleContainer::iterator iterator;
typedef typename ReversibleContainer::reverse_iterator reverse_iterator;
void constraints() {
function_requires< ReversibleContainerConcept<ReversibleContainer> >();
function_requires<
Mutable_ForwardContainerConcept<ReversibleContainer> >();
function_requires< Mutable_BidirectionalIteratorConcept<iterator> >();
function_requires<
Mutable_BidirectionalIteratorConcept<reverse_iterator> >();
reverse_iterator i = c.rbegin();
i = c.rend();
}
ReversibleContainer c;
};
template <class RandomAccessContainer>
struct RandomAccessContainerConcept
{
typedef typename RandomAccessContainer::size_type size_type;
typedef typename RandomAccessContainer::const_reference const_reference;
typedef typename RandomAccessContainer::const_iterator const_iterator;
typedef typename RandomAccessContainer::const_reverse_iterator
const_reverse_iterator;
void constraints() {
function_requires< ReversibleContainerConcept<RandomAccessContainer> >();
function_requires< RandomAccessIteratorConcept<const_iterator> >();
function_requires<
RandomAccessIteratorConcept<const_reverse_iterator> >();
const_constraints(c);
}
void const_constraints(const RandomAccessContainer& c) {
const_reference r = c[n];
ignore_unused_variable_warning(r);
}
RandomAccessContainer c;
size_type n;
};
template <class RandomAccessContainer>
struct Mutable_RandomAccessContainerConcept
{
typedef typename RandomAccessContainer::size_type size_type;
typedef typename RandomAccessContainer::reference reference;
typedef typename RandomAccessContainer::iterator iterator;
typedef typename RandomAccessContainer::reverse_iterator reverse_iterator;
void constraints() {
function_requires<
RandomAccessContainerConcept<RandomAccessContainer> >();
function_requires<
Mutable_ReversibleContainerConcept<RandomAccessContainer> >();
function_requires< Mutable_RandomAccessIteratorConcept<iterator> >();
function_requires<
Mutable_RandomAccessIteratorConcept<reverse_iterator> >();
reference r = c[i];
ignore_unused_variable_warning(r);
}
size_type i;
RandomAccessContainer c;
};
// A Sequence is inherently mutable
template <class Sequence>
struct SequenceConcept
{
typedef typename Sequence::reference reference;
typedef typename Sequence::const_reference const_reference;
void constraints() {
// Matt Austern's book puts DefaultConstructible here, the C++
// standard places it in Container
// function_requires< DefaultConstructible<Sequence> >();
function_requires< Mutable_ForwardContainerConcept<Sequence> >();
function_requires< DefaultConstructibleConcept<Sequence> >();
Sequence
c(n),
c2(n, t),
c3(first, last);
c.insert(p, t);
c.insert(p, n, t);
c.insert(p, first, last);
c.erase(p);
c.erase(p, q);
reference r = c.front();
ignore_unused_variable_warning(c);
ignore_unused_variable_warning(c2);
ignore_unused_variable_warning(c3);
ignore_unused_variable_warning(r);
const_constraints(c);
}
void const_constraints(const Sequence& c) {
const_reference r = c.front();
ignore_unused_variable_warning(r);
}
typename Sequence::value_type t;
typename Sequence::size_type n;
typename Sequence::value_type* first, *last;
typename Sequence::iterator p, q;
};
template <class FrontInsertionSequence>
struct FrontInsertionSequenceConcept
{
void constraints() {
function_requires< SequenceConcept<FrontInsertionSequence> >();
c.push_front(t);
c.pop_front();
}
FrontInsertionSequence c;
typename FrontInsertionSequence::value_type t;
};
template <class BackInsertionSequence>
struct BackInsertionSequenceConcept
{
typedef typename BackInsertionSequence::reference reference;
typedef typename BackInsertionSequence::const_reference const_reference;
void constraints() {
function_requires< SequenceConcept<BackInsertionSequence> >();
c.push_back(t);
c.pop_back();
reference r = c.back();
ignore_unused_variable_warning(r);
}
void const_constraints(const BackInsertionSequence& c) {
const_reference r = c.back();
ignore_unused_variable_warning(r);
};
BackInsertionSequence c;
typename BackInsertionSequence::value_type t;
};
template <class AssociativeContainer>
struct AssociativeContainerConcept
{
void constraints() {
function_requires< ForwardContainerConcept<AssociativeContainer> >();
function_requires< DefaultConstructibleConcept<AssociativeContainer> >();
i = c.find(k);
r = c.equal_range(k);
c.erase(k);
c.erase(i);
c.erase(r.first, r.second);
const_constraints(c);
}
void const_constraints(const AssociativeContainer& c) {
ci = c.find(k);
n = c.count(k);
cr = c.equal_range(k);
}
typedef typename AssociativeContainer::iterator iterator;
typedef typename AssociativeContainer::const_iterator const_iterator;
AssociativeContainer c;
iterator i;
std::pair<iterator,iterator> r;
const_iterator ci;
std::pair<const_iterator,const_iterator> cr;
typename AssociativeContainer::key_type k;
typename AssociativeContainer::size_type n;
};
template <class UniqueAssociativeContainer>
struct UniqueAssociativeContainerConcept
{
void constraints() {
function_requires< AssociativeContainerConcept<UniqueAssociativeContainer> >();
UniqueAssociativeContainer c(first, last);
pos_flag = c.insert(t);
c.insert(first, last);
ignore_unused_variable_warning(c);
}
std::pair<typename UniqueAssociativeContainer::iterator, bool> pos_flag;
typename UniqueAssociativeContainer::value_type t;
typename UniqueAssociativeContainer::value_type* first, *last;
};
template <class MultipleAssociativeContainer>
struct MultipleAssociativeContainerConcept
{
void constraints() {
function_requires< AssociativeContainerConcept<MultipleAssociativeContainer> >();
MultipleAssociativeContainer c(first, last);
pos = c.insert(t);
c.insert(first, last);
ignore_unused_variable_warning(c);
ignore_unused_variable_warning(pos);
}
typename MultipleAssociativeContainer::iterator pos;
typename MultipleAssociativeContainer::value_type t;