LLVM  6.0.0svn
STLExtras.h
Go to the documentation of this file.
1 //===- llvm/ADT/STLExtras.h - Useful STL related functions ------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains some templates that are useful if you are working with the
11 // STL at all.
12 //
13 // No library is required when using these functions.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #ifndef LLVM_ADT_STLEXTRAS_H
18 #define LLVM_ADT_STLEXTRAS_H
19 
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/iterator.h"
25 #include <algorithm>
26 #include <cassert>
27 #include <cstddef>
28 #include <cstdint>
29 #include <cstdlib>
30 #include <functional>
31 #include <initializer_list>
32 #include <iterator>
33 #include <limits>
34 #include <memory>
35 #include <tuple>
36 #include <type_traits>
37 #include <utility>
38 
39 namespace llvm {
40 
41 // Only used by compiler if both template types are the same. Useful when
42 // using SFINAE to test for the existence of member functions.
43 template <typename T, T> struct SameType;
44 
45 namespace detail {
46 
47 template <typename RangeT>
48 using IterOfRange = decltype(std::begin(std::declval<RangeT &>()));
49 
50 template <typename RangeT>
51 using ValueOfRange = typename std::remove_reference<decltype(
52  *std::begin(std::declval<RangeT &>()))>::type;
53 
54 } // end namespace detail
55 
56 //===----------------------------------------------------------------------===//
57 // Extra additions to <functional>
58 //===----------------------------------------------------------------------===//
59 
60 template <class Ty> struct identity {
61  using argument_type = Ty;
62 
63  Ty &operator()(Ty &self) const {
64  return self;
65  }
66  const Ty &operator()(const Ty &self) const {
67  return self;
68  }
69 };
70 
71 template <class Ty> struct less_ptr {
72  bool operator()(const Ty* left, const Ty* right) const {
73  return *left < *right;
74  }
75 };
76 
77 template <class Ty> struct greater_ptr {
78  bool operator()(const Ty* left, const Ty* right) const {
79  return *right < *left;
80  }
81 };
82 
83 /// An efficient, type-erasing, non-owning reference to a callable. This is
84 /// intended for use as the type of a function parameter that is not used
85 /// after the function in question returns.
86 ///
87 /// This class does not own the callable, so it is not in general safe to store
88 /// a function_ref.
89 template<typename Fn> class function_ref;
90 
91 template<typename Ret, typename ...Params>
92 class function_ref<Ret(Params...)> {
93  Ret (*callback)(intptr_t callable, Params ...params) = nullptr;
94  intptr_t callable;
95 
96  template<typename Callable>
97  static Ret callback_fn(intptr_t callable, Params ...params) {
98  return (*reinterpret_cast<Callable*>(callable))(
99  std::forward<Params>(params)...);
100  }
101 
102 public:
103  function_ref() = default;
104 
105  template <typename Callable>
106  function_ref(Callable &&callable,
107  typename std::enable_if<
108  !std::is_same<typename std::remove_reference<Callable>::type,
109  function_ref>::value>::type * = nullptr)
110  : callback(callback_fn<typename std::remove_reference<Callable>::type>),
111  callable(reinterpret_cast<intptr_t>(&callable)) {}
112 
113  Ret operator()(Params ...params) const {
114  return callback(callable, std::forward<Params>(params)...);
115  }
116 
117  operator bool() const { return callback; }
118 };
119 
120 // deleter - Very very very simple method that is used to invoke operator
121 // delete on something. It is used like this:
122 //
123 // for_each(V.begin(), B.end(), deleter<Interval>);
124 template <class T>
125 inline void deleter(T *Ptr) {
126  delete Ptr;
127 }
128 
129 //===----------------------------------------------------------------------===//
130 // Extra additions to <iterator>
131 //===----------------------------------------------------------------------===//
132 
133 // mapped_iterator - This is a simple iterator adapter that causes a function to
134 // be applied whenever operator* is invoked on the iterator.
135 
136 template <typename ItTy, typename FuncTy,
137  typename FuncReturnTy =
138  decltype(std::declval<FuncTy>()(*std::declval<ItTy>()))>
140  : public iterator_adaptor_base<
141  mapped_iterator<ItTy, FuncTy>, ItTy,
142  typename std::iterator_traits<ItTy>::iterator_category,
143  typename std::remove_reference<FuncReturnTy>::type> {
144 public:
145  mapped_iterator(ItTy U, FuncTy F)
146  : mapped_iterator::iterator_adaptor_base(std::move(U)), F(std::move(F)) {}
147 
148  ItTy getCurrent() { return this->I; }
149 
150  FuncReturnTy operator*() { return F(*this->I); }
151 
152 private:
153  FuncTy F;
154 };
155 
156 // map_iterator - Provide a convenient way to create mapped_iterators, just like
157 // make_pair is useful for creating pairs...
158 template <class ItTy, class FuncTy>
160  return mapped_iterator<ItTy, FuncTy>(std::move(I), std::move(F));
161 }
162 
163 /// Helper to determine if type T has a member called rbegin().
164 template <typename Ty> class has_rbegin_impl {
165  using yes = char[1];
166  using no = char[2];
167 
168  template <typename Inner>
169  static yes& test(Inner *I, decltype(I->rbegin()) * = nullptr);
170 
171  template <typename>
172  static no& test(...);
173 
174 public:
175  static const bool value = sizeof(test<Ty>(nullptr)) == sizeof(yes);
176 };
177 
178 /// Metafunction to determine if T& or T has a member called rbegin().
179 template <typename Ty>
180 struct has_rbegin : has_rbegin_impl<typename std::remove_reference<Ty>::type> {
181 };
182 
183 // Returns an iterator_range over the given container which iterates in reverse.
184 // Note that the container must have rbegin()/rend() methods for this to work.
185 template <typename ContainerTy>
186 auto reverse(ContainerTy &&C,
187  typename std::enable_if<has_rbegin<ContainerTy>::value>::type * =
188  nullptr) -> decltype(make_range(C.rbegin(), C.rend())) {
189  return make_range(C.rbegin(), C.rend());
190 }
191 
192 // Returns a std::reverse_iterator wrapped around the given iterator.
193 template <typename IteratorTy>
194 std::reverse_iterator<IteratorTy> make_reverse_iterator(IteratorTy It) {
195  return std::reverse_iterator<IteratorTy>(It);
196 }
197 
198 // Returns an iterator_range over the given container which iterates in reverse.
199 // Note that the container must have begin()/end() methods which return
200 // bidirectional iterators for this to work.
201 template <typename ContainerTy>
202 auto reverse(
203  ContainerTy &&C,
204  typename std::enable_if<!has_rbegin<ContainerTy>::value>::type * = nullptr)
209 }
210 
211 /// An iterator adaptor that filters the elements of given inner iterators.
212 ///
213 /// The predicate parameter should be a callable object that accepts the wrapped
214 /// iterator's reference type and returns a bool. When incrementing or
215 /// decrementing the iterator, it will call the predicate on each element and
216 /// skip any where it returns false.
217 ///
218 /// \code
219 /// int A[] = { 1, 2, 3, 4 };
220 /// auto R = make_filter_range(A, [](int N) { return N % 2 == 1; });
221 /// // R contains { 1, 3 }.
222 /// \endcode
223 template <typename WrappedIteratorT, typename PredicateT>
225  : public iterator_adaptor_base<
226  filter_iterator<WrappedIteratorT, PredicateT>, WrappedIteratorT,
227  typename std::common_type<
228  std::forward_iterator_tag,
229  typename std::iterator_traits<
230  WrappedIteratorT>::iterator_category>::type> {
233  typename std::common_type<
234  std::forward_iterator_tag,
235  typename std::iterator_traits<WrappedIteratorT>::iterator_category>::
236  type>;
237 
238  struct PayloadType {
239  WrappedIteratorT End;
240  PredicateT Pred;
241  };
242 
243  Optional<PayloadType> Payload;
244 
245  void findNextValid() {
246  assert(Payload && "Payload should be engaged when findNextValid is called");
247  while (this->I != Payload->End && !Payload->Pred(*this->I))
248  BaseT::operator++();
249  }
250 
251  // Construct the begin iterator. The begin iterator requires to know where end
252  // is, so that it can properly stop when it hits end.
253  filter_iterator(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
254  : BaseT(std::move(Begin)),
255  Payload(PayloadType{std::move(End), std::move(Pred)}) {
256  findNextValid();
257  }
258 
259  // Construct the end iterator. It's not incrementable, so Payload doesn't
260  // have to be engaged.
261  filter_iterator(WrappedIteratorT End) : BaseT(End) {}
262 
263 public:
264  using BaseT::operator++;
265 
267  BaseT::operator++();
268  findNextValid();
269  return *this;
270  }
271 
272  template <typename RT, typename PT>
274  make_filter_range(RT &&, PT);
275 };
276 
277 /// Convenience function that takes a range of elements and a predicate,
278 /// and return a new filter_iterator range.
279 ///
280 /// FIXME: Currently if RangeT && is a rvalue reference to a temporary, the
281 /// lifetime of that temporary is not kept by the returned range object, and the
282 /// temporary is going to be dropped on the floor after the make_iterator_range
283 /// full expression that contains this function call.
284 template <typename RangeT, typename PredicateT>
286 make_filter_range(RangeT &&Range, PredicateT Pred) {
287  using FilterIteratorT =
289  return make_range(FilterIteratorT(std::begin(std::forward<RangeT>(Range)),
290  std::end(std::forward<RangeT>(Range)),
291  std::move(Pred)),
292  FilterIteratorT(std::end(std::forward<RangeT>(Range))));
293 }
294 
295 // forward declarations required by zip_shortest/zip_first
296 template <typename R, typename UnaryPredicate>
297 bool all_of(R &&range, UnaryPredicate P);
298 
299 template <size_t... I> struct index_sequence;
300 
301 template <class... Ts> struct index_sequence_for;
302 
303 namespace detail {
304 
305 using std::declval;
306 
307 // We have to alias this since inlining the actual type at the usage site
308 // in the parameter list of iterator_facade_base<> below ICEs MSVC 2017.
309 template<typename... Iters> struct ZipTupleType {
310  using type = std::tuple<decltype(*declval<Iters>())...>;
311 };
312 
313 template <typename ZipType, typename... Iters>
315  ZipType, typename std::common_type<std::bidirectional_iterator_tag,
316  typename std::iterator_traits<
317  Iters>::iterator_category...>::type,
318  // ^ TODO: Implement random access methods.
319  typename ZipTupleType<Iters...>::type,
320  typename std::iterator_traits<typename std::tuple_element<
321  0, std::tuple<Iters...>>::type>::difference_type,
322  // ^ FIXME: This follows boost::make_zip_iterator's assumption that all
323  // inner iterators have the same difference_type. It would fail if, for
324  // instance, the second field's difference_type were non-numeric while the
325  // first is.
326  typename ZipTupleType<Iters...>::type *,
327  typename ZipTupleType<Iters...>::type>;
328 
329 template <typename ZipType, typename... Iters>
330 struct zip_common : public zip_traits<ZipType, Iters...> {
331  using Base = zip_traits<ZipType, Iters...>;
332  using value_type = typename Base::value_type;
333 
334  std::tuple<Iters...> iterators;
335 
336 protected:
337  template <size_t... Ns> value_type deref(index_sequence<Ns...>) const {
338  return value_type(*std::get<Ns>(iterators)...);
339  }
340 
341  template <size_t... Ns>
342  decltype(iterators) tup_inc(index_sequence<Ns...>) const {
343  return std::tuple<Iters...>(std::next(std::get<Ns>(iterators))...);
344  }
345 
346  template <size_t... Ns>
347  decltype(iterators) tup_dec(index_sequence<Ns...>) const {
348  return std::tuple<Iters...>(std::prev(std::get<Ns>(iterators))...);
349  }
350 
351 public:
352  zip_common(Iters &&... ts) : iterators(std::forward<Iters>(ts)...) {}
353 
355 
356  const value_type operator*() const {
358  }
359 
360  ZipType &operator++() {
361  iterators = tup_inc(index_sequence_for<Iters...>{});
362  return *reinterpret_cast<ZipType *>(this);
363  }
364 
365  ZipType &operator--() {
366  static_assert(Base::IsBidirectional,
367  "All inner iterators must be at least bidirectional.");
368  iterators = tup_dec(index_sequence_for<Iters...>{});
369  return *reinterpret_cast<ZipType *>(this);
370  }
371 };
372 
373 template <typename... Iters>
374 struct zip_first : public zip_common<zip_first<Iters...>, Iters...> {
375  using Base = zip_common<zip_first<Iters...>, Iters...>;
376 
377  bool operator==(const zip_first<Iters...> &other) const {
378  return std::get<0>(this->iterators) == std::get<0>(other.iterators);
379  }
380 
381  zip_first(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {}
382 };
383 
384 template <typename... Iters>
385 class zip_shortest : public zip_common<zip_shortest<Iters...>, Iters...> {
386  template <size_t... Ns>
387  bool test(const zip_shortest<Iters...> &other, index_sequence<Ns...>) const {
388  return all_of(std::initializer_list<bool>{std::get<Ns>(this->iterators) !=
389  std::get<Ns>(other.iterators)...},
390  identity<bool>{});
391  }
392 
393 public:
394  using Base = zip_common<zip_shortest<Iters...>, Iters...>;
395 
396  zip_shortest(Iters &&... ts) : Base(std::forward<Iters>(ts)...) {}
397 
398  bool operator==(const zip_shortest<Iters...> &other) const {
399  return !test(other, index_sequence_for<Iters...>{});
400  }
401 };
402 
403 template <template <typename...> class ItType, typename... Args> class zippy {
404 public:
405  using iterator = ItType<decltype(std::begin(std::declval<Args>()))...>;
406  using iterator_category = typename iterator::iterator_category;
407  using value_type = typename iterator::value_type;
408  using difference_type = typename iterator::difference_type;
409  using pointer = typename iterator::pointer;
410  using reference = typename iterator::reference;
411 
412 private:
413  std::tuple<Args...> ts;
414 
415  template <size_t... Ns> iterator begin_impl(index_sequence<Ns...>) const {
416  return iterator(std::begin(std::get<Ns>(ts))...);
417  }
418  template <size_t... Ns> iterator end_impl(index_sequence<Ns...>) const {
419  return iterator(std::end(std::get<Ns>(ts))...);
420  }
421 
422 public:
423  zippy(Args &&... ts_) : ts(std::forward<Args>(ts_)...) {}
424 
425  iterator begin() const { return begin_impl(index_sequence_for<Args...>{}); }
426  iterator end() const { return end_impl(index_sequence_for<Args...>{}); }
427 };
428 
429 } // end namespace detail
430 
431 /// zip iterator for two or more iteratable types.
432 template <typename T, typename U, typename... Args>
434  Args &&... args) {
435  return detail::zippy<detail::zip_shortest, T, U, Args...>(
436  std::forward<T>(t), std::forward<U>(u), std::forward<Args>(args)...);
437 }
438 
439 /// zip iterator that, for the sake of efficiency, assumes the first iteratee to
440 /// be the shortest.
441 template <typename T, typename U, typename... Args>
443  Args &&... args) {
444  return detail::zippy<detail::zip_first, T, U, Args...>(
445  std::forward<T>(t), std::forward<U>(u), std::forward<Args>(args)...);
446 }
447 
448 /// Iterator wrapper that concatenates sequences together.
449 ///
450 /// This can concatenate different iterators, even with different types, into
451 /// a single iterator provided the value types of all the concatenated
452 /// iterators expose `reference` and `pointer` types that can be converted to
453 /// `ValueT &` and `ValueT *` respectively. It doesn't support more
454 /// interesting/customized pointer or reference types.
455 ///
456 /// Currently this only supports forward or higher iterator categories as
457 /// inputs and always exposes a forward iterator interface.
458 template <typename ValueT, typename... IterTs>
460  : public iterator_facade_base<concat_iterator<ValueT, IterTs...>,
461  std::forward_iterator_tag, ValueT> {
462  using BaseT = typename concat_iterator::iterator_facade_base;
463 
464  /// We store both the current and end iterators for each concatenated
465  /// sequence in a tuple of pairs.
466  ///
467  /// Note that something like iterator_range seems nice at first here, but the
468  /// range properties are of little benefit and end up getting in the way
469  /// because we need to do mutation on the current iterators.
470  std::tuple<std::pair<IterTs, IterTs>...> IterPairs;
471 
472  /// Attempts to increment a specific iterator.
473  ///
474  /// Returns true if it was able to increment the iterator. Returns false if
475  /// the iterator is already at the end iterator.
476  template <size_t Index> bool incrementHelper() {
477  auto &IterPair = std::get<Index>(IterPairs);
478  if (IterPair.first == IterPair.second)
479  return false;
480 
481  ++IterPair.first;
482  return true;
483  }
484 
485  /// Increments the first non-end iterator.
486  ///
487  /// It is an error to call this with all iterators at the end.
488  template <size_t... Ns> void increment(index_sequence<Ns...>) {
489  // Build a sequence of functions to increment each iterator if possible.
490  bool (concat_iterator::*IncrementHelperFns[])() = {
491  &concat_iterator::incrementHelper<Ns>...};
492 
493  // Loop over them, and stop as soon as we succeed at incrementing one.
494  for (auto &IncrementHelperFn : IncrementHelperFns)
495  if ((this->*IncrementHelperFn)())
496  return;
497 
498  llvm_unreachable("Attempted to increment an end concat iterator!");
499  }
500 
501  /// Returns null if the specified iterator is at the end. Otherwise,
502  /// dereferences the iterator and returns the address of the resulting
503  /// reference.
504  template <size_t Index> ValueT *getHelper() const {
505  auto &IterPair = std::get<Index>(IterPairs);
506  if (IterPair.first == IterPair.second)
507  return nullptr;
508 
509  return &*IterPair.first;
510  }
511 
512  /// Finds the first non-end iterator, dereferences, and returns the resulting
513  /// reference.
514  ///
515  /// It is an error to call this with all iterators at the end.
516  template <size_t... Ns> ValueT &get(index_sequence<Ns...>) const {
517  // Build a sequence of functions to get from iterator if possible.
518  ValueT *(concat_iterator::*GetHelperFns[])() const = {
519  &concat_iterator::getHelper<Ns>...};
520 
521  // Loop over them, and return the first result we find.
522  for (auto &GetHelperFn : GetHelperFns)
523  if (ValueT *P = (this->*GetHelperFn)())
524  return *P;
525 
526  llvm_unreachable("Attempted to get a pointer from an end concat iterator!");
527  }
528 
529 public:
530  /// Constructs an iterator from a squence of ranges.
531  ///
532  /// We need the full range to know how to switch between each of the
533  /// iterators.
534  template <typename... RangeTs>
535  explicit concat_iterator(RangeTs &&... Ranges)
536  : IterPairs({std::begin(Ranges), std::end(Ranges)}...) {}
537 
538  using BaseT::operator++;
539 
541  increment(index_sequence_for<IterTs...>());
542  return *this;
543  }
544 
545  ValueT &operator*() const { return get(index_sequence_for<IterTs...>()); }
546 
547  bool operator==(const concat_iterator &RHS) const {
548  return IterPairs == RHS.IterPairs;
549  }
550 };
551 
552 namespace detail {
553 
554 /// Helper to store a sequence of ranges being concatenated and access them.
555 ///
556 /// This is designed to facilitate providing actual storage when temporaries
557 /// are passed into the constructor such that we can use it as part of range
558 /// based for loops.
559 template <typename ValueT, typename... RangeTs> class concat_range {
560 public:
561  using iterator =
563  decltype(std::begin(std::declval<RangeTs &>()))...>;
564 
565 private:
566  std::tuple<RangeTs...> Ranges;
567 
568  template <size_t... Ns> iterator begin_impl(index_sequence<Ns...>) {
569  return iterator(std::get<Ns>(Ranges)...);
570  }
571  template <size_t... Ns> iterator end_impl(index_sequence<Ns...>) {
572  return iterator(make_range(std::end(std::get<Ns>(Ranges)),
573  std::end(std::get<Ns>(Ranges)))...);
574  }
575 
576 public:
577  concat_range(RangeTs &&... Ranges)
578  : Ranges(std::forward<RangeTs>(Ranges)...) {}
579 
580  iterator begin() { return begin_impl(index_sequence_for<RangeTs...>{}); }
581  iterator end() { return end_impl(index_sequence_for<RangeTs...>{}); }
582 };
583 
584 } // end namespace detail
585 
586 /// Concatenated range across two or more ranges.
587 ///
588 /// The desired value type must be explicitly specified.
589 template <typename ValueT, typename... RangeTs>
590 detail::concat_range<ValueT, RangeTs...> concat(RangeTs &&... Ranges) {
591  static_assert(sizeof...(RangeTs) > 1,
592  "Need more than one range to concatenate!");
593  return detail::concat_range<ValueT, RangeTs...>(
594  std::forward<RangeTs>(Ranges)...);
595 }
596 
597 //===----------------------------------------------------------------------===//
598 // Extra additions to <utility>
599 //===----------------------------------------------------------------------===//
600 
601 /// \brief Function object to check whether the first component of a std::pair
602 /// compares less than the first component of another std::pair.
603 struct less_first {
604  template <typename T> bool operator()(const T &lhs, const T &rhs) const {
605  return lhs.first < rhs.first;
606  }
607 };
608 
609 /// \brief Function object to check whether the second component of a std::pair
610 /// compares less than the second component of another std::pair.
611 struct less_second {
612  template <typename T> bool operator()(const T &lhs, const T &rhs) const {
613  return lhs.second < rhs.second;
614  }
615 };
616 
617 // A subset of N3658. More stuff can be added as-needed.
618 
619 /// \brief Represents a compile-time sequence of integers.
620 template <class T, T... I> struct integer_sequence {
621  using value_type = T;
622 
623  static constexpr size_t size() { return sizeof...(I); }
624 };
625 
626 /// \brief Alias for the common case of a sequence of size_ts.
627 template <size_t... I>
628 struct index_sequence : integer_sequence<std::size_t, I...> {};
629 
630 template <std::size_t N, std::size_t... I>
631 struct build_index_impl : build_index_impl<N - 1, N - 1, I...> {};
632 template <std::size_t... I>
633 struct build_index_impl<0, I...> : index_sequence<I...> {};
634 
635 /// \brief Creates a compile-time integer sequence for a parameter pack.
636 template <class... Ts>
637 struct index_sequence_for : build_index_impl<sizeof...(Ts)> {};
638 
639 /// Utility type to build an inheritance chain that makes it easy to rank
640 /// overload candidates.
641 template <int N> struct rank : rank<N - 1> {};
642 template <> struct rank<0> {};
643 
644 /// \brief traits class for checking whether type T is one of any of the given
645 /// types in the variadic list.
646 template <typename T, typename... Ts> struct is_one_of {
647  static const bool value = false;
648 };
649 
650 template <typename T, typename U, typename... Ts>
651 struct is_one_of<T, U, Ts...> {
652  static const bool value =
653  std::is_same<T, U>::value || is_one_of<T, Ts...>::value;
654 };
655 
656 /// \brief traits class for checking whether type T is a base class for all
657 /// the given types in the variadic list.
658 template <typename T, typename... Ts> struct are_base_of {
659  static const bool value = true;
660 };
661 
662 template <typename T, typename U, typename... Ts>
663 struct are_base_of<T, U, Ts...> {
664  static const bool value =
665  std::is_base_of<T, U>::value && are_base_of<T, Ts...>::value;
666 };
667 
668 //===----------------------------------------------------------------------===//
669 // Extra additions for arrays
670 //===----------------------------------------------------------------------===//
671 
672 /// Find the length of an array.
673 template <class T, std::size_t N>
674 constexpr inline size_t array_lengthof(T (&)[N]) {
675  return N;
676 }
677 
678 /// Adapt std::less<T> for array_pod_sort.
679 template<typename T>
680 inline int array_pod_sort_comparator(const void *P1, const void *P2) {
681  if (std::less<T>()(*reinterpret_cast<const T*>(P1),
682  *reinterpret_cast<const T*>(P2)))
683  return -1;
684  if (std::less<T>()(*reinterpret_cast<const T*>(P2),
685  *reinterpret_cast<const T*>(P1)))
686  return 1;
687  return 0;
688 }
689 
690 /// get_array_pod_sort_comparator - This is an internal helper function used to
691 /// get type deduction of T right.
692 template<typename T>
693 inline int (*get_array_pod_sort_comparator(const T &))
694  (const void*, const void*) {
695  return array_pod_sort_comparator<T>;
696 }
697 
698 /// array_pod_sort - This sorts an array with the specified start and end
699 /// extent. This is just like std::sort, except that it calls qsort instead of
700 /// using an inlined template. qsort is slightly slower than std::sort, but
701 /// most sorts are not performance critical in LLVM and std::sort has to be
702 /// template instantiated for each type, leading to significant measured code
703 /// bloat. This function should generally be used instead of std::sort where
704 /// possible.
705 ///
706 /// This function assumes that you have simple POD-like types that can be
707 /// compared with std::less and can be moved with memcpy. If this isn't true,
708 /// you should use std::sort.
709 ///
710 /// NOTE: If qsort_r were portable, we could allow a custom comparator and
711 /// default to std::less.
712 template<class IteratorTy>
713 inline void array_pod_sort(IteratorTy Start, IteratorTy End) {
714  // Don't inefficiently call qsort with one element or trigger undefined
715  // behavior with an empty sequence.
716  auto NElts = End - Start;
717  if (NElts <= 1) return;
718  qsort(&*Start, NElts, sizeof(*Start), get_array_pod_sort_comparator(*Start));
719 }
720 
721 template <class IteratorTy>
722 inline void array_pod_sort(
723  IteratorTy Start, IteratorTy End,
724  int (*Compare)(
725  const typename std::iterator_traits<IteratorTy>::value_type *,
726  const typename std::iterator_traits<IteratorTy>::value_type *)) {
727  // Don't inefficiently call qsort with one element or trigger undefined
728  // behavior with an empty sequence.
729  auto NElts = End - Start;
730  if (NElts <= 1) return;
731  qsort(&*Start, NElts, sizeof(*Start),
732  reinterpret_cast<int (*)(const void *, const void *)>(Compare));
733 }
734 
735 //===----------------------------------------------------------------------===//
736 // Extra additions to <algorithm>
737 //===----------------------------------------------------------------------===//
738 
739 /// For a container of pointers, deletes the pointers and then clears the
740 /// container.
741 template<typename Container>
742 void DeleteContainerPointers(Container &C) {
743  for (auto V : C)
744  delete V;
745  C.clear();
746 }
747 
748 /// In a container of pairs (usually a map) whose second element is a pointer,
749 /// deletes the second elements and then clears the container.
750 template<typename Container>
751 void DeleteContainerSeconds(Container &C) {
752  for (auto &V : C)
753  delete V.second;
754  C.clear();
755 }
756 
757 /// Provide wrappers to std::for_each which take ranges instead of having to
758 /// pass begin/end explicitly.
759 template <typename R, typename UnaryPredicate>
760 UnaryPredicate for_each(R &&Range, UnaryPredicate P) {
761  return std::for_each(std::begin(Range), std::end(Range), P);
762 }
763 
764 /// Provide wrappers to std::all_of which take ranges instead of having to pass
765 /// begin/end explicitly.
766 template <typename R, typename UnaryPredicate>
767 bool all_of(R &&Range, UnaryPredicate P) {
768  return std::all_of(std::begin(Range), std::end(Range), P);
769 }
770 
771 /// Provide wrappers to std::any_of which take ranges instead of having to pass
772 /// begin/end explicitly.
773 template <typename R, typename UnaryPredicate>
774 bool any_of(R &&Range, UnaryPredicate P) {
775  return std::any_of(std::begin(Range), std::end(Range), P);
776 }
777 
778 /// Provide wrappers to std::none_of which take ranges instead of having to pass
779 /// begin/end explicitly.
780 template <typename R, typename UnaryPredicate>
781 bool none_of(R &&Range, UnaryPredicate P) {
782  return std::none_of(std::begin(Range), std::end(Range), P);
783 }
784 
785 /// Provide wrappers to std::find which take ranges instead of having to pass
786 /// begin/end explicitly.
787 template <typename R, typename T>
788 auto find(R &&Range, const T &Val) -> decltype(std::begin(Range)) {
789  return std::find(std::begin(Range), std::end(Range), Val);
790 }
791 
792 /// Provide wrappers to std::find_if which take ranges instead of having to pass
793 /// begin/end explicitly.
794 template <typename R, typename UnaryPredicate>
795 auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) {
796  return std::find_if(std::begin(Range), std::end(Range), P);
797 }
798 
799 template <typename R, typename UnaryPredicate>
800 auto find_if_not(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) {
801  return std::find_if_not(std::begin(Range), std::end(Range), P);
802 }
803 
804 /// Provide wrappers to std::remove_if which take ranges instead of having to
805 /// pass begin/end explicitly.
806 template <typename R, typename UnaryPredicate>
807 auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) {
808  return std::remove_if(std::begin(Range), std::end(Range), P);
809 }
810 
811 /// Provide wrappers to std::copy_if which take ranges instead of having to
812 /// pass begin/end explicitly.
813 template <typename R, typename OutputIt, typename UnaryPredicate>
814 OutputIt copy_if(R &&Range, OutputIt Out, UnaryPredicate P) {
815  return std::copy_if(std::begin(Range), std::end(Range), Out, P);
816 }
817 
818 /// Wrapper function around std::find to detect if an element exists
819 /// in a container.
820 template <typename R, typename E>
821 bool is_contained(R &&Range, const E &Element) {
822  return std::find(std::begin(Range), std::end(Range), Element) !=
823  std::end(Range);
824 }
825 
826 /// Wrapper function around std::count to count the number of times an element
827 /// \p Element occurs in the given range \p Range.
828 template <typename R, typename E>
829 auto count(R &&Range, const E &Element) -> typename std::iterator_traits<
830  decltype(std::begin(Range))>::difference_type {
831  return std::count(std::begin(Range), std::end(Range), Element);
832 }
833 
834 /// Wrapper function around std::count_if to count the number of times an
835 /// element satisfying a given predicate occurs in a range.
836 template <typename R, typename UnaryPredicate>
837 auto count_if(R &&Range, UnaryPredicate P) -> typename std::iterator_traits<
838  decltype(std::begin(Range))>::difference_type {
839  return std::count_if(std::begin(Range), std::end(Range), P);
840 }
841 
842 /// Wrapper function around std::transform to apply a function to a range and
843 /// store the result elsewhere.
844 template <typename R, typename OutputIt, typename UnaryPredicate>
845 OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P) {
846  return std::transform(std::begin(Range), std::end(Range), d_first, P);
847 }
848 
849 /// Provide wrappers to std::partition which take ranges instead of having to
850 /// pass begin/end explicitly.
851 template <typename R, typename UnaryPredicate>
852 auto partition(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range)) {
853  return std::partition(std::begin(Range), std::end(Range), P);
854 }
855 
856 /// Provide wrappers to std::lower_bound which take ranges instead of having to
857 /// pass begin/end explicitly.
858 template <typename R, typename ForwardIt>
859 auto lower_bound(R &&Range, ForwardIt I) -> decltype(std::begin(Range)) {
860  return std::lower_bound(std::begin(Range), std::end(Range), I);
861 }
862 
863 /// \brief Given a range of type R, iterate the entire range and return a
864 /// SmallVector with elements of the vector. This is useful, for example,
865 /// when you want to iterate a range and then sort the results.
866 template <unsigned Size, typename R>
868 to_vector(R &&Range) {
869  return {std::begin(Range), std::end(Range)};
870 }
871 
872 /// Provide a container algorithm similar to C++ Library Fundamentals v2's
873 /// `erase_if` which is equivalent to:
874 ///
875 /// C.erase(remove_if(C, pred), C.end());
876 ///
877 /// This version works for any container with an erase method call accepting
878 /// two iterators.
879 template <typename Container, typename UnaryPredicate>
880 void erase_if(Container &C, UnaryPredicate P) {
881  C.erase(remove_if(C, P), C.end());
882 }
883 
884 //===----------------------------------------------------------------------===//
885 // Extra additions to <memory>
886 //===----------------------------------------------------------------------===//
887 
888 // Implement make_unique according to N3656.
889 
890 /// \brief Constructs a `new T()` with the given args and returns a
891 /// `unique_ptr<T>` which owns the object.
892 ///
893 /// Example:
894 ///
895 /// auto p = make_unique<int>();
896 /// auto p = make_unique<std::tuple<int, int>>(0, 1);
897 template <class T, class... Args>
898 typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
899 make_unique(Args &&... args) {
900  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
901 }
902 
903 /// \brief Constructs a `new T[n]` with the given args and returns a
904 /// `unique_ptr<T[]>` which owns the object.
905 ///
906 /// \param n size of the new array.
907 ///
908 /// Example:
909 ///
910 /// auto p = make_unique<int[]>(2); // value-initializes the array with 0's.
911 template <class T>
912 typename std::enable_if<std::is_array<T>::value && std::extent<T>::value == 0,
913  std::unique_ptr<T>>::type
914 make_unique(size_t n) {
915  return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]());
916 }
917 
918 /// This function isn't used and is only here to provide better compile errors.
919 template <class T, class... Args>
920 typename std::enable_if<std::extent<T>::value != 0>::type
921 make_unique(Args &&...) = delete;
922 
923 struct FreeDeleter {
924  void operator()(void* v) {
925  ::free(v);
926  }
927 };
928 
929 template<typename First, typename Second>
930 struct pair_hash {
931  size_t operator()(const std::pair<First, Second> &P) const {
932  return std::hash<First>()(P.first) * 31 + std::hash<Second>()(P.second);
933  }
934 };
935 
936 /// A functor like C++14's std::less<void> in its absence.
937 struct less {
938  template <typename A, typename B> bool operator()(A &&a, B &&b) const {
939  return std::forward<A>(a) < std::forward<B>(b);
940  }
941 };
942 
943 /// A functor like C++14's std::equal<void> in its absence.
944 struct equal {
945  template <typename A, typename B> bool operator()(A &&a, B &&b) const {
946  return std::forward<A>(a) == std::forward<B>(b);
947  }
948 };
949 
950 /// Binary functor that adapts to any other binary functor after dereferencing
951 /// operands.
952 template <typename T> struct deref {
953  T func;
954 
955  // Could be further improved to cope with non-derivable functors and
956  // non-binary functors (should be a variadic template member function
957  // operator()).
958  template <typename A, typename B>
959  auto operator()(A &lhs, B &rhs) const -> decltype(func(*lhs, *rhs)) {
960  assert(lhs);
961  assert(rhs);
962  return func(*lhs, *rhs);
963  }
964 };
965 
966 namespace detail {
967 
968 template <typename R> class enumerator_iter;
969 
970 template <typename R> struct result_pair {
971  friend class enumerator_iter<R>;
972 
973  result_pair() = default;
974  result_pair(std::size_t Index, IterOfRange<R> Iter)
975  : Index(Index), Iter(Iter) {}
976 
978  Index = Other.Index;
979  Iter = Other.Iter;
980  return *this;
981  }
982 
983  std::size_t index() const { return Index; }
984  const ValueOfRange<R> &value() const { return *Iter; }
985  ValueOfRange<R> &value() { return *Iter; }
986 
987 private:
988  std::size_t Index = std::numeric_limits<std::size_t>::max();
989  IterOfRange<R> Iter;
990 };
991 
992 template <typename R>
993 class enumerator_iter
994  : public iterator_facade_base<
995  enumerator_iter<R>, std::forward_iterator_tag, result_pair<R>,
996  typename std::iterator_traits<IterOfRange<R>>::difference_type,
997  typename std::iterator_traits<IterOfRange<R>>::pointer,
998  typename std::iterator_traits<IterOfRange<R>>::reference> {
999  using result_type = result_pair<R>;
1000 
1001 public:
1003  : Result(std::numeric_limits<size_t>::max(), EndIter) {}
1004 
1005  enumerator_iter(std::size_t Index, IterOfRange<R> Iter)
1006  : Result(Index, Iter) {}
1007 
1008  result_type &operator*() { return Result; }
1009  const result_type &operator*() const { return Result; }
1010 
1012  assert(Result.Index != std::numeric_limits<size_t>::max());
1013  ++Result.Iter;
1014  ++Result.Index;
1015  return *this;
1016  }
1017 
1018  bool operator==(const enumerator_iter<R> &RHS) const {
1019  // Don't compare indices here, only iterators. It's possible for an end
1020  // iterator to have different indices depending on whether it was created
1021  // by calling std::end() versus incrementing a valid iterator.
1022  return Result.Iter == RHS.Result.Iter;
1023  }
1024 
1026  Result = Other.Result;
1027  return *this;
1028  }
1029 
1030 private:
1031  result_type Result;
1032 };
1033 
1034 template <typename R> class enumerator {
1035 public:
1036  explicit enumerator(R &&Range) : TheRange(std::forward<R>(Range)) {}
1037 
1039  return enumerator_iter<R>(0, std::begin(TheRange));
1040  }
1041 
1043  return enumerator_iter<R>(std::end(TheRange));
1044  }
1045 
1046 private:
1047  R TheRange;
1048 };
1049 
1050 } // end namespace detail
1051 
1052 /// Given an input range, returns a new range whose values are are pair (A,B)
1053 /// such that A is the 0-based index of the item in the sequence, and B is
1054 /// the value from the original sequence. Example:
1055 ///
1056 /// std::vector<char> Items = {'A', 'B', 'C', 'D'};
1057 /// for (auto X : enumerate(Items)) {
1058 /// printf("Item %d - %c\n", X.index(), X.value());
1059 /// }
1060 ///
1061 /// Output:
1062 /// Item 0 - A
1063 /// Item 1 - B
1064 /// Item 2 - C
1065 /// Item 3 - D
1066 ///
1067 template <typename R> detail::enumerator<R> enumerate(R &&TheRange) {
1068  return detail::enumerator<R>(std::forward<R>(TheRange));
1069 }
1070 
1071 namespace detail {
1072 
1073 template <typename F, typename Tuple, std::size_t... I>
1075  -> decltype(std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...)) {
1076  return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
1077 }
1078 
1079 } // end namespace detail
1080 
1081 /// Given an input tuple (a1, a2, ..., an), pass the arguments of the
1082 /// tuple variadically to f as if by calling f(a1, a2, ..., an) and
1083 /// return the result.
1084 template <typename F, typename Tuple>
1085 auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl(
1086  std::forward<F>(f), std::forward<Tuple>(t),
1088  std::tuple_size<typename std::decay<Tuple>::type>::value>{})) {
1089  using Indices = build_index_impl<
1090  std::tuple_size<typename std::decay<Tuple>::type>::value>;
1091 
1092  return detail::apply_tuple_impl(std::forward<F>(f), std::forward<Tuple>(t),
1093  Indices{});
1094 }
1095 
1096 } // end namespace llvm
1097 
1098 #endif // LLVM_ADT_STLEXTRAS_H
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&... Ranges)
Concatenated range across two or more ranges.
Definition: STLExtras.h:590
result_pair(std::size_t Index, IterOfRange< R > Iter)
Definition: STLExtras.h:974
void DeleteContainerSeconds(Container &C)
In a container of pairs (usually a map) whose second element is a pointer, deletes the second element...
Definition: STLExtras.h:751
uint64_t CallInst * C
void DeleteContainerPointers(Container &C)
For a container of pointers, deletes the pointers and then clears the container.
Definition: STLExtras.h:742
bool operator()(const Ty *left, const Ty *right) const
Definition: STLExtras.h:78
ZipType & operator++()
Definition: STLExtras.h:360
bool operator==(const enumerator_iter< R > &RHS) const
Definition: STLExtras.h:1018
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:244
zippy(Args &&... ts_)
Definition: STLExtras.h:423
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Ret operator()(Params ...params) const
Definition: STLExtras.h:113
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:235
bool operator()(const T &lhs, const T &rhs) const
Definition: STLExtras.h:604
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
typename std::remove_reference< decltype(*std::begin(std::declval< RangeT & >()))>::type ValueOfRange
Definition: STLExtras.h:52
decltype(iterators) tup_inc(index_sequence< Ns... >) const
Definition: STLExtras.h:342
Function object to check whether the second component of a std::pair compares less than the second co...
Definition: STLExtras.h:611
OutputIt copy_if(R &&Range, OutputIt Out, UnaryPredicate P)
Provide wrappers to std::copy_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:814
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:807
typename iterator::value_type value_type
Definition: STLExtras.h:407
const Ty & operator()(const Ty &self) const
Definition: STLExtras.h:66
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
int(*)(const void *, const void *) get_array_pod_sort_comparator(const T &)
get_array_pod_sort_comparator - This is an internal helper function used to get type deduction of T r...
Definition: STLExtras.h:693
bool operator()(const T &lhs, const T &rhs) const
Definition: STLExtras.h:612
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:89
A functor like C++14&#39;s std::less<void> in its absence.
Definition: STLExtras.h:937
zip_common(Iters &&... ts)
Definition: STLExtras.h:352
enumerator_iter(IterOfRange< R > EndIter)
Definition: STLExtras.h:1002
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:767
filter_iterator & operator++()
Definition: STLExtras.h:266
F(f)
std::tuple< decltype(*declval< Iters >())... > type
Definition: STLExtras.h:310
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:899
typename iterator::pointer pointer
Definition: STLExtras.h:409
int array_pod_sort_comparator(const void *P1, const void *P2)
Adapt std::less<T> for array_pod_sort.
Definition: STLExtras.h:680
Metafunction to determine if T& or T has a member called rbegin().
Definition: STLExtras.h:180
function_ref(Callable &&callable, typename std::enable_if< !std::is_same< typename std::remove_reference< Callable >::type, function_ref >::value >::type *=nullptr)
Definition: STLExtras.h:106
Ty & operator()(Ty &self) const
Definition: STLExtras.h:63
Definition: BitVector.h:920
concat_range(RangeTs &&... Ranges)
Definition: STLExtras.h:577
void operator()(void *v)
Definition: STLExtras.h:924
auto find_if_not(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Definition: STLExtras.h:800
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:781
decltype(iterators) tup_dec(index_sequence< Ns... >) const
Definition: STLExtras.h:347
SmallVector< typename std::remove_const< detail::ValueOfRange< R > >::type, Size > to_vector(R &&Range)
Given a range of type R, iterate the entire range and return a SmallVector with elements of the vecto...
Definition: STLExtras.h:868
Alias for the common case of a sequence of size_ts.
Definition: STLExtras.h:299
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:736
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:186
bool operator()(const Ty *left, const Ty *right) const
Definition: STLExtras.h:72
#define T
enumerator_iter< R > & operator++()
Definition: STLExtras.h:1011
auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl(std::forward< F >(f), std::forward< Tuple >(t), build_index_impl< std::tuple_size< typename std::decay< Tuple >::type >::value >
Given an input tuple (a1, a2, ..., an), pass the arguments of the tuple variadically to f as if by ca...
Definition: STLExtras.h:1085
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:829
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:68
enumerator_iter(std::size_t Index, IterOfRange< R > Iter)
Definition: STLExtras.h:1005
Helper to store a sequence of ranges being concatenated and access them.
Definition: STLExtras.h:559
traits class for checking whether type T is one of any of the given types in the variadic list...
Definition: STLExtras.h:646
ValueOfRange< R > & value()
Definition: STLExtras.h:985
typename iterator::reference reference
Definition: STLExtras.h:410
#define P(N)
ItType< decltype(std::begin(std::declval< Args >()))... > iterator
Definition: STLExtras.h:405
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
Definition: STLExtras.h:713
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
auto operator()(A &lhs, B &rhs) const -> decltype(func(*lhs, *rhs))
Definition: STLExtras.h:959
ZipType & operator--()
Definition: STLExtras.h:365
An iterator adaptor that filters the elements of given inner iterators.
Definition: STLExtras.h:224
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:208
mapped_iterator(ItTy U, FuncTy F)
Definition: STLExtras.h:145
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&... args)
zip iterator for two or more iteratable types.
Definition: STLExtras.h:433
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const result_type & operator*() const
Definition: STLExtras.h:1009
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
Definition: STLExtras.h:159
Helper to determine if type T has a member called rbegin().
Definition: STLExtras.h:164
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:774
static const unsigned End
detail::zippy< detail::zip_first, T, U, Args... > zip_first(T &&t, U &&u, Args &&... args)
zip iterator that, for the sake of efficiency, assumes the first iteratee to be the shortest...
Definition: STLExtras.h:442
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static constexpr size_t size()
Definition: STLExtras.h:623
iterator end() const
Definition: STLExtras.h:426
bool operator()(A &&a, B &&b) const
Definition: STLExtras.h:938
auto apply_tuple_impl(F &&f, Tuple &&t, index_sequence< I... >) -> decltype(std::forward< F >(f)(std::get< I >(std::forward< Tuple >(t))...))
Definition: STLExtras.h:1074
A functor like C++14&#39;s std::equal<void> in its absence.
Definition: STLExtras.h:944
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
value_type deref(index_sequence< Ns... >) const
Definition: STLExtras.h:337
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:788
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:674
Creates a compile-time integer sequence for a parameter pack.
Definition: STLExtras.h:301
typename iterator::difference_type difference_type
Definition: STLExtras.h:408
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2&#39;s erase_if which is equivalent t...
Definition: STLExtras.h:880
A range adaptor for a pair of iterators.
bool operator()(A &&a, B &&b) const
Definition: STLExtras.h:945
auto lower_bound(R &&Range, ForwardIt I) -> decltype(std::begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:859
Represents a compile-time sequence of integers.
Definition: STLExtras.h:620
enumerator_iter< R > & operator=(const enumerator_iter< R > &Other)
Definition: STLExtras.h:1025
concat_iterator & operator++()
Definition: STLExtras.h:540
FuncReturnTy operator*()
Definition: STLExtras.h:150
result_pair< R > & operator=(const result_pair< R > &Other)
Definition: STLExtras.h:977
ValueT & operator*() const
Definition: STLExtras.h:545
auto partition(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:852
bool operator==(const zip_first< Iters... > &other) const
Definition: STLExtras.h:377
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
bool operator==(const concat_iterator &RHS) const
Definition: STLExtras.h:547
typename iterator::iterator_category iterator_category
Definition: STLExtras.h:406
value_type operator*()
Definition: STLExtras.h:354
decltype(std::begin(std::declval< RangeT & >())) IterOfRange
Definition: STLExtras.h:48
const ValueOfRange< R > & value() const
Definition: STLExtras.h:984
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:286
std::tuple< Iters... > iterators
Definition: STLExtras.h:334
OutputIt transform(R &&Range, OutputIt d_first, UnaryPredicate P)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere...
Definition: STLExtras.h:845
const value_type operator*() const
Definition: STLExtras.h:356
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::reverse_iterator< IteratorTy > make_reverse_iterator(IteratorTy It)
Definition: STLExtras.h:194
traits class for checking whether type T is a base class for all the given types in the variadic list...
Definition: STLExtras.h:658
enumerator_iter< R > begin()
Definition: STLExtras.h:1038
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
enumerator_iter< R > end()
Definition: STLExtras.h:1042
iterator begin() const
Definition: STLExtras.h:425
Binary functor that adapts to any other binary functor after dereferencing operands.
Definition: STLExtras.h:952
Iterator wrapper that concatenates sequences together.
Definition: STLExtras.h:459
Utility type to build an inheritance chain that makes it easy to rank overload candidates.
Definition: STLExtras.h:641
zip_shortest(Iters &&... ts)
Definition: STLExtras.h:396
UnaryPredicate for_each(R &&Range, UnaryPredicate P)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:760
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:795
void deleter(T *Ptr)
Definition: STLExtras.h:125
zip_first(Iters &&... ts)
Definition: STLExtras.h:381
std::size_t index() const
Definition: STLExtras.h:983
Function object to check whether the first component of a std::pair compares less than the first comp...
Definition: STLExtras.h:603
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
auto count_if(R &&Range, UnaryPredicate P) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:837
concat_iterator(RangeTs &&... Ranges)
Constructs an iterator from a squence of ranges.
Definition: STLExtras.h:535
bool operator==(const zip_shortest< Iters... > &other) const
Definition: STLExtras.h:398
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
Definition: STLExtras.h:1067
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:821
size_t operator()(const std::pair< First, Second > &P) const
Definition: STLExtras.h:931