-
Notifications
You must be signed in to change notification settings - Fork 194
/
container_concepts.h
247 lines (222 loc) · 9.28 KB
/
container_concepts.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
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
#ifndef __STL_CONTAINER_CONCEPTS_H
#define __STL_CONTAINER_CONCEPTS_H
#include <concept_checks.h>
#ifdef __STL_USE_CONCEPT_CHECKS
// This file covers the following concepts:
// _Container
// _ForwardContainer
// _ReversibleContainer
// _const_ReversibleContainer
// _RandomAccessContainer
//
struct _ERROR_IN_STL_CONTAINER {
/* Container expresssions */
template <class _Container>
static void
__begin_iterator_accessor_requirement_violation(_Container __c) {
__c.begin();
}
template <class _Container>
static void
__const_begin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.begin();
}
template <class _Container>
static void
__end_iterator_accessor_requirement_violation(_Container __c) {
__c.end();
}
template <class _Container>
static void
__const_end_iterator_accessor_requirement_violation(const _Container& __c) {
__c.end();
}
template <class _Container>
static void
__rbegin_iterator_accessor_requirement_violation(_Container __c) {
__c.rbegin();
}
template <class _Container>
static void
__const_rbegin_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rbegin();
}
template <class _Container>
static void
__rend_iterator_accessor_requirement_violation(_Container __c) {
__c.rend();
}
template <class _Container>
static void
__const_rend_iterator_accessor_requirement_violation(const _Container& __c) {
__c.rend();
}
template <class _Container>
static void
__size_function_must_be_const(const _Container& __c) {
__c.size();
}
template <class _Container>
static void
__size_function_requirement_violation(_Container& __c) {
__c.size();
__size_function_must_be_const(__c);
}
template <class _Container>
static void
__max_size_function_must_be_const(const _Container& __c) {
__c.max_size();
}
template <class _Container>
static void
__max_size_function_requirement_violation(_Container& __c) {
__c.max_size();
__max_size_function_must_be_const(__c);
}
template <class _Container>
static void
__empty_function_must_be_const(const _Container& __c) {
__c.empty();
}
template <class _Container>
static void
__empty_function_requirement_violation(_Container& __c) {
__c.empty();
__empty_function_must_be_const(__c);
}
template <class _Container>
static void
__swap_function_requirement_violation(_Container& __c) {
__c.swap(__c);
}
};
__STL_TYPEDEF_REQUIREMENT(iterator);
__STL_TYPEDEF_REQUIREMENT(const_iterator);
/* Containers */
template <class _Container>
struct _Container_concept_specification {
static void
_Container_requirement_violation(_Container __c) {
// Refinement of Assignable
_Assignable_concept_specification<_Container>::_Assignable_requirement_violation(__c);
// Associated Types
__value_type__typedef_requirement_violation<_Container>();
__difference_type__typedef_requirement_violation<_Container>();
__size_type__typedef_requirement_violation<_Container>();
__reference__typedef_requirement_violation<_Container>();
__const_reference__typedef_requirement_violation<_Container>();
__pointer__typedef_requirement_violation<_Container>();
__const_pointer__typedef_requirement_violation<_Container>();
__iterator__typedef_requirement_violation<_Container>();
__const_iterator__typedef_requirement_violation<_Container>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__begin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__end_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__max_size_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__empty_function_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__swap_function_requirement_violation(__c);
// Requirements on Iterators
typedef typename _Container::iterator iter;
typedef typename _Container::const_iterator const_iter;
_InputIterator_concept_specification<const_iter>::_InputIterator_requirement_violation(const_iter());
_InputIterator_concept_specification<iter>::_InputIterator_requirement_violation(iter());
}
};
template <class _ForwardContainer>
struct _ForwardContainer_concept_specification {
static void
_ForwardContainer_requirement_violation(_ForwardContainer __c) {
// Refinement of Container
_Container_concept_specification<_ForwardContainer>::_Container_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ForwardContainer::iterator iter;
typedef typename _ForwardContainer::const_iterator const_iter;
_ForwardIterator_concept_specification<const_iter>::_ForwardIterator_requirement_violation(const_iter());
_Mutable_ForwardIterator_concept_specification<iter>::_Mutable_ForwardIterator_requirement_violation(iter());
}
};
__STL_TYPEDEF_REQUIREMENT(reverse_iterator);
__STL_TYPEDEF_REQUIREMENT(const_reverse_iterator);
template <class _ReversibleContainer>
struct _ReversibleContainer_concept_specification {
static void
_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of ForwardContainer
_ForwardContainer_concept_specification<_ReversibleContainer>::_ForwardContainer_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
_BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
_Mutable_BidirectionalIterator_concept_specification<iter>::_Mutable_BidirectionalIterator_requirement_violation(iter());
}
};
template <class _ReversibleContainer>
struct _const_ReversibleContainer_concept_specification {
static void
_const_ReversibleContainer_requirement_violation(_ReversibleContainer __c) {
// Refinement of Container (JGS, not ForwardContainer)
_Container_concept_specification<_ReversibleContainer>::_Container_requirement_violation(__c);
// Associated types
__reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
__const_reverse_iterator__typedef_requirement_violation<_ReversibleContainer>();
// Valid Expressions
_ERROR_IN_STL_CONTAINER::__const_rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__const_rend_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rbegin_iterator_accessor_requirement_violation(__c);
_ERROR_IN_STL_CONTAINER::__rend_iterator_accessor_requirement_violation(__c);
// Requirements on Iterators
typedef typename _ReversibleContainer::iterator iter;
typedef typename _ReversibleContainer::const_iterator const_iter;
// This line won't compile on gcc 2.91 due to a compiler bug.
#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 91)
__BidirectionalIterator_concept_specification<const_iter>::_BidirectionalIterator_requirement_violation(const_iter());
#endif
}
};
template <class _RandomAccessContainer>
struct _RandomAccessContainer_concept_specification {
static void
_RandomAccessContainer_requirement_violation(_RandomAccessContainer __c) {
// Refinement of ReversibleContainer
_ReversibleContainer_concept_specification<_RandomAccessContainer>::_ReversibleContainer_requirement_violation(__c);
// Valid Expressions
typedef typename _RandomAccessContainer::value_type __T;
typedef typename _RandomAccessContainer::difference_type _Dist;
typedef typename _Mutable_trait<__T>::_Type Type;
typedef Type* _TypePtr;
typedef typename _Mutable_trait<_Dist>::_Type Dist;
_STL_ERROR::__element_access_operator_requirement_violation(__c,
_TypePtr(),
Dist());
// Requirements on Iterators
typedef typename _RandomAccessContainer::iterator iter;
typedef typename _RandomAccessContainer::const_iterator const_iter;
_RandomAccessIterator_concept_specification<const_iter>::_RandomAccessIterator_requirement_violation(const_iter());
_Mutable_RandomAccessIterator_concept_specification<iter>::_Mutable_RandomAccessIterator_requirement_violation(iter());
}
};
#endif /* if __STL_USE_CONCEPT_CHECKS */
#endif /* __STL_CONTAINER_CONCEPTS_H */