Debian Codegraph @

yo/advancedtemplates/concepts/examples/section17.cc

raw
1 template <typename Type = int, int N = 10>
2 concept bool C3 = true;
3
4 template <typename Type>
5 concept bool ID()
6 {
7 return true;
8 }
9
10 template <typename Type>
11 concept bool IncAndDec()
12 {
13 return
14 requires(Type par)
15 {
16 ++par; // `Type' variables/objects must
17 --par; // support pre- and postfix
18 par++; // increment and decrement
19 par--; // operators
20 };
21 }
22
23 template <typename Type>
24 concept bool ReturnTypes()
25 {
26 return
27 requires(Type par)
28 {
29 { ++par } -> Type &; // prefix inc. returns a Type &
30 { par[0] } -> char; // the index operator returns a char
31 };
32 }
33
34 template <typename Type>
35 concept bool MultiArgs()
36 {
37 return
38 requires(Type lhs, Type rhs)
39 {
40 { lhs + rhs } -> Type;
41 { lhs += rhs } -> Type &;
42 { lhs.c_str() } -> char const *;
43 };
44 }
45
46 template <typename Type>
47 concept bool CombiOps()
48 {
49 return
50 requires(Type lhs, Type rhs)
51 {
52 { lhs + rhs } -> Type;
53 { lhs += rhs } -> Type &;
54 }
55 and
56 requires(Type lhs)
57 {
58 { lhs.c_str() } -> char const *;
59 };
60 }
61
62 template <typename Type>
63 concept bool ValueType()
64 {
65 return
66 requires()
67 {
68 typename Type::value_type;
69 };
70 }
71
72 template <ValueType Type>
73 class Data
74 {
75 };
76
77 struct EnumStruct
78 {
79 enum value_type
80 {
81 VALUE
82 };
83 };
84
85 template <typename Type>
86 concept bool InputIterator()
87 {
88 return true;
89 }
90
91 template <typename Type>
92 concept bool OutputIterator()
93 {
94 return true;
95 }
96
97 template <typename Type>
98 concept bool ForwardIterator()
99 {
100 return
101 requires
102 {
103 requires InputIterator<Type>();
104 requires OutputIterator<Type>();
105 };
106 }
107
108 template <typename Type>
109 concept bool BidirectionalIterator()
110 {
111 return
112 requires
113 {
114 requires ForwardIterator<Type>();
115 requires IncAndDec<Type>();
116 };
117 }
118
119 template <typename Type>
120 concept bool RandomAccessIterator()
121 {
122 return
123 requires
124 {
125 requires BidirectionalIterator<Type>();
126 }
127 and
128 requires(Type lhs, Type rhs)
129 {
130 { lhs + rhs };
131 { lhs - rhs };
132 };
133 }
134
135 template <BidirectionalIterator Type>
136 struct Iterator
137 {
138 void fun();
139 };
140
141 template <RandomAccessIterator RAI>
142 void rSort(RAI begin, RAI end)
143 {}
144
145 int main()
146 {
147 // Data<EnumStruct> data;
148
149 Iterator<int> iter;
150 iter = iter;
151
152 rSort(10, 20);
153
154 iter.fun();
155 }