12
12
13
13
#include " llvm/ADT/Hashing.h"
14
14
#include " llvm/ADT/None.h"
15
+ #include " llvm/ADT/STLExtras.h"
15
16
#include " llvm/ADT/SmallVector.h"
16
17
#include < array>
17
18
#include < vector>
@@ -165,19 +166,16 @@ namespace llvm {
165
166
return std::equal (begin (), end (), RHS.begin ());
166
167
}
167
168
168
- // / slice(n) - Chop off the first N elements of the array.
169
- ArrayRef<T> slice (size_t N) const {
170
- assert (N <= size () && " Invalid specifier" );
171
- return ArrayRef<T>(data ()+N, size ()-N);
172
- }
173
-
174
169
// / slice(n, m) - Chop off the first N elements of the array, and keep M
175
170
// / elements in the array.
176
171
ArrayRef<T> slice (size_t N, size_t M) const {
177
172
assert (N+M <= size () && " Invalid specifier" );
178
173
return ArrayRef<T>(data ()+N, M);
179
174
}
180
175
176
+ // / slice(n) - Chop off the first N elements of the array.
177
+ ArrayRef<T> slice (size_t N) const { return slice (N, size () - N); }
178
+
181
179
// / \brief Drop the first \p N elements of the array.
182
180
ArrayRef<T> drop_front (size_t N = 1 ) const {
183
181
assert (size () >= N && " Dropping more elements than exist" );
@@ -190,6 +188,18 @@ namespace llvm {
190
188
return slice (0 , size () - N);
191
189
}
192
190
191
+ // / \brief Return a copy of *this with the first N elements satisfying the
192
+ // / given predicate removed.
193
+ template <class PredicateT > ArrayRef<T> drop_while (PredicateT Pred) const {
194
+ return ArrayRef<T>(find_if_not (*this , Pred), end ());
195
+ }
196
+
197
+ // / \brief Return a copy of *this with the first N elements not satisfying
198
+ // / the given predicate removed.
199
+ template <class PredicateT > ArrayRef<T> drop_until (PredicateT Pred) const {
200
+ return ArrayRef<T>(find_if (*this , Pred), end ());
201
+ }
202
+
193
203
// / \brief Return a copy of *this with only the first \p N elements.
194
204
ArrayRef<T> take_front (size_t N = 1 ) const {
195
205
if (N >= size ())
@@ -204,6 +214,18 @@ namespace llvm {
204
214
return drop_front (size () - N);
205
215
}
206
216
217
+ // / \brief Return the first N elements of this Array that satisfy the given
218
+ // / predicate.
219
+ template <class PredicateT > ArrayRef<T> take_while (PredicateT Pred) const {
220
+ return ArrayRef<T>(begin (), find_if_not (*this , Pred));
221
+ }
222
+
223
+ // / \brief Return the first N elements of this Array that don't satisfy the
224
+ // / given predicate.
225
+ template <class PredicateT > ArrayRef<T> take_until (PredicateT Pred) const {
226
+ return ArrayRef<T>(begin (), find_if (*this , Pred));
227
+ }
228
+
207
229
// / @}
208
230
// / @name Operator Overloads
209
231
// / @{
@@ -317,17 +339,16 @@ namespace llvm {
317
339
return data ()[this ->size ()-1 ];
318
340
}
319
341
320
- // / slice(n) - Chop off the first N elements of the array.
321
- MutableArrayRef<T> slice (size_t N) const {
322
- assert (N <= this ->size () && " Invalid specifier" );
323
- return MutableArrayRef<T>(data ()+N, this ->size ()-N);
324
- }
325
-
326
342
// / slice(n, m) - Chop off the first N elements of the array, and keep M
327
343
// / elements in the array.
328
344
MutableArrayRef<T> slice (size_t N, size_t M) const {
329
- assert (N+M <= this ->size () && " Invalid specifier" );
330
- return MutableArrayRef<T>(data ()+N, M);
345
+ assert (N + M <= this ->size () && " Invalid specifier" );
346
+ return MutableArrayRef<T>(this ->data () + N, M);
347
+ }
348
+
349
+ // / slice(n) - Chop off the first N elements of the array.
350
+ MutableArrayRef<T> slice (size_t N) const {
351
+ return slice (N, this ->size () - N);
331
352
}
332
353
333
354
// / \brief Drop the first \p N elements of the array.
@@ -341,6 +362,20 @@ namespace llvm {
341
362
return slice (0 , this ->size () - N);
342
363
}
343
364
365
+ // / \brief Return a copy of *this with the first N elements satisfying the
366
+ // / given predicate removed.
367
+ template <class PredicateT >
368
+ MutableArrayRef<T> drop_while (PredicateT Pred) const {
369
+ return MutableArrayRef<T>(find_if_not (*this , Pred), end ());
370
+ }
371
+
372
+ // / \brief Return a copy of *this with the first N elements not satisfying
373
+ // / the given predicate removed.
374
+ template <class PredicateT >
375
+ MutableArrayRef<T> drop_until (PredicateT Pred) const {
376
+ return MutableArrayRef<T>(find_if (*this , Pred), end ());
377
+ }
378
+
344
379
// / \brief Return a copy of *this with only the first \p N elements.
345
380
MutableArrayRef<T> take_front (size_t N = 1 ) const {
346
381
if (N >= this ->size ())
@@ -355,6 +390,20 @@ namespace llvm {
355
390
return drop_front (this ->size () - N);
356
391
}
357
392
393
+ // / \brief Return the first N elements of this Array that satisfy the given
394
+ // / predicate.
395
+ template <class PredicateT >
396
+ MutableArrayRef<T> take_while (PredicateT Pred) const {
397
+ return MutableArrayRef<T>(begin (), find_if_not (*this , Pred));
398
+ }
399
+
400
+ // / \brief Return the first N elements of this Array that don't satisfy the
401
+ // / given predicate.
402
+ template <class PredicateT >
403
+ MutableArrayRef<T> take_until (PredicateT Pred) const {
404
+ return MutableArrayRef<T>(begin (), find_if (*this , Pred));
405
+ }
406
+
358
407
// / @}
359
408
// / @name Operator Overloads
360
409
// / @{
0 commit comments