LLVM: include/llvm/ADT/STLExtras.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef LLVM_ADT_STLEXTRAS_H
18#define LLVM_ADT_STLEXTRAS_H
19
26#include "llvm/Config/abi-breaking.h"
28#include
29#include
30#include
31#include
32#include
33#include
34#include <initializer_list>
35#include
36#include
37#include
38#include
39#include
40#include
41#include <type_traits>
42#include
43
44#ifdef EXPENSIVE_CHECKS
45#include
46#endif
47
48namespace llvm {
49
50
51
52
53
55 using type = std::add_pointer_t<std::add_const_t>;
56};
57
59 using type = std::add_lvalue_reference_t<std::add_const_t>;
60};
61
62
63
64
65
66template <typename T, bool isClass = std::is_class::value>
68
69
70template <typename ClassType, typename ReturnType, typename... Args>
72
74
75
77
78
79 template <size_t Index>
80 using arg_t = std::tuple_element_t<Index, std::tuple<Args...>>;
81};
82
83template <typename ClassType, typename ReturnType, typename... Args>
86
87template <typename ReturnType, typename... Args>
89
91
92
94
95
96 template <size_t i>
97 using arg_t = std::tuple_element_t<i, std::tuple<Args...>>;
98};
99template <typename ReturnType, typename... Args>
102
103template <typename ReturnType, typename... Args>
106
107
108
109template <typename T, typename... Ts>
110using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
111
112
113
114template <typename T, typename... Ts>
115using are_base_of = std::conjunction<std::is_base_of<T, Ts>...>;
116
117
118
119template <typename T = void, typename... Ts>
121template <typename T = void, typename... Ts>
123
124
125
126
127
128
129
130
133template <typename T, typename... Us>
135 : std::conjunction<std::negation<is_one_of<T, Us...>>,
136 TypesAreDistinct<Us...>> {};
137
138
139
140
141
142
143
144
145
146
147
149template <typename T, typename U, typename... Us>
151 : std::integral_constant<size_t, 1 + FirstIndexOfType<T, Us...>::value> {};
152template <typename T, typename... Us>
154
155
156
157
158template <size_t I, typename... Ts>
159using TypeAtIndex = std::tuple_element_t<I, std::tuple<Ts...>>;
160
161
162
163template <typename EnumTy1, typename EnumTy2,
164 typename = std::enable_if_t<std::is_enum_v &&
165 std::is_enum_v>>
169
170
171
172
173
175
176
177
178
179
180
181
182
183
184
185
186template <typename T,
187 bool = std::is_function_v<std::remove_pointer_t<remove_cvref_t>>>
189 using value_type = std::remove_reference_t;
190 using reference = value_type &;
191 using const_reference = value_type const &;
192
193 std::optional<value_type> Obj;
194
195 static_assert(!std::is_pointer_v<value_type>,
196 "Pointers to non-functions are not callable.");
197
198public:
201
204
206 Obj = std::nullopt;
208 Obj.emplace(*Other.Obj);
209 return *this;
210 }
211
213 Obj = std::nullopt;
215 Obj.emplace(std::move(*Other.Obj));
216 return *this;
217 }
218
219 template <typename... Pn,
220 std::enable_if_t<std::is_invocable_v<T, Pn...>, int> = 0>
221 decltype(auto) operator()(Pn &&...Params) {
222 return (*Obj)(std::forward(Params)...);
223 }
224
225 template <typename... Pn,
226 std::enable_if_t<std::is_invocable_v<T const, Pn...>, int> = 0>
227 decltype(auto) operator()(Pn &&...Params) const {
228 return (*Obj)(std::forward(Params)...);
229 }
230
231 bool valid() const { return Obj != std::nullopt; }
232 bool reset() { return Obj = std::nullopt; }
233
234 operator reference() { return *Obj; }
235 operator const_reference() const { return *Obj; }
236};
237
238
239
241 static constexpr bool IsPtr = std::is_pointer_v<remove_cvref_t>;
242
243 using StorageT = std::conditional_t<IsPtr, T, std::remove_reference_t *>;
244 using CastT = std::conditional_t<IsPtr, T, T &>;
245
246private:
247 StorageT Func = nullptr;
248
249private:
250 template static constexpr auto convertIn(In &&I) {
251 if constexpr (IsPtr) {
252
253 return I;
254 } else {
255
256 return &I;
257 }
258 }
259
260public:
262
263
264
265
266
267 template <
268 typename FnPtrOrRef,
269 std::enable_if_t<
270 !std::is_same_v<remove_cvref_t, Callable>, int
271 > = 0
272 >
274
275 template <typename... Pn,
276 std::enable_if_t<std::is_invocable_v<T, Pn...>, int> = 0>
277 decltype(auto) operator()(Pn &&...Params) const {
278 return Func(std::forward(Params)...);
279 }
280
281 bool valid() const { return Func != nullptr; }
282 void reset() { Func = nullptr; }
283
284 operator T const &() const {
285 if constexpr (IsPtr) {
286
287 return Func;
288 } else {
289 static_assert(std::is_reference_v,
290 "Expected a reference to a function.");
291
292 return *Func;
293 }
294 }
295};
296
297}
298
299
303 return B != E && std::next(B) == E;
304}
305
306
307
308template
313
314
315
316template auto drop_begin(T &&RangeOrContainer, size_t N = 1) {
318 adl_end(RangeOrContainer));
319}
320
321
322
323template auto drop_end(T &&RangeOrContainer, size_t N = 1) {
325 std::prev(adl_end(RangeOrContainer), N));
326}
327
328
329
330
331template <typename ItTy, typename FuncTy,
332 typename ReferenceTy =
333 decltype(std::declval()(*std::declval()))>
336 mapped_iterator<ItTy, FuncTy>, ItTy,
337 typename std::iterator_traits::iterator_category,
338 std::remove_reference_t,
339 typename std::iterator_traits::difference_type,
340 std::remove_reference_t *, ReferenceTy> {
341public:
345
347
349
350 ReferenceTy operator*() const { return F(*this->I); }
351
352private:
354};
355
356
357
358template <class ItTy, class FuncTy>
362
363template <class ContainerTy, class FuncTy>
367
368
369
370
371
372
373template <typename DerivedT, typename ItTy, typename ReferenceTy>
376 DerivedT, ItTy,
377 typename std::iterator_traits::iterator_category,
378 std::remove_reference_t,
379 typename std::iterator_traits::difference_type,
380 std::remove_reference_t *, ReferenceTy> {
381public:
383
386
388
390 return static_cast<const DerivedT &>(*this).mapElement(*this->I);
391 }
392};
393
395template
397 decltype(adl_rbegin(std::declval<Range &>()));
398
399template
402}
403
404
405
406template [[nodiscard]] auto reverse(ContainerTy &&C) {
409 else
411 std::make_reverse_iterator(adl_begin(C)));
412}
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430template <typename WrappedIteratorT, typename PredicateT, typename IterTag>
433 filter_iterator_base<WrappedIteratorT, PredicateT, IterTag>,
434 WrappedIteratorT,
435 std::common_type_t<IterTag,
436 typename std::iterator_traits<
437 WrappedIteratorT>::iterator_category>> {
439
440protected:
443
445 while (this->I != End && (*this->I))
446 BaseT::operator++();
447 }
448
450
451
452
453
459
460public:
461 using BaseT::operator++;
462
464 BaseT::operator++();
466 return *this;
467 }
468
469 decltype(auto) operator*() const {
470 assert(BaseT::wrapped() != End && "Cannot dereference end iterator!");
471 return BaseT::operator*();
472 }
473
474 decltype(auto) operator->() const {
475 assert(BaseT::wrapped() != End && "Cannot dereference end iterator!");
476 return BaseT::operator->();
477 }
478};
479
480
482 typename IterTag = std::forward_iterator_tag>
492
493
494template <typename WrappedIteratorT, typename PredicateT>
496 std::bidirectional_iterator_tag>
498 std::bidirectional_iterator_tag> {
500
501 void findPrevValid() {
502 while (!this->Pred(*this->I))
503 BaseT::operator--();
504 }
505
506public:
507 using BaseT::operator--;
508
510
514
516 BaseT::operator--();
517 findPrevValid();
518 return *this;
519 }
520};
521
523
524
525
526template
528 std::is_base_of_v<std::bidirectional_iterator_tag,
529 typename std::iterator_traits::iterator_category>,
530 std::bidirectional_iterator_tag, std::forward_iterator_tag>;
531
532}
533
534
535
536template <typename WrappedIteratorT, typename PredicateT>
540
541
542
543
544
545
546
547
548template <typename RangeT, typename PredicateT>
551 using FilterIteratorT =
555 return make_range(FilterIteratorT(B, E, Pred), FilterIteratorT(E, E, Pred));
556}
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575template
578 WrappedIteratorT, std::input_iterator_tag> {
580
581 using PointerT = typename std::iterator_traits::pointer;
582
583protected:
584#if LLVM_ENABLE_ABI_BREAKING_CHECKS
585 bool IsEarlyIncremented = false;
586#endif
587
588public:
590
591 using BaseT::operator*;
592 decltype(*std::declval()) operator*() {
593#if LLVM_ENABLE_ABI_BREAKING_CHECKS
594 assert(!IsEarlyIncremented && "Cannot dereference twice!");
595 IsEarlyIncremented = true;
596#endif
597 return *(this->I)++;
598 }
599
600 using BaseT::operator++;
602#if LLVM_ENABLE_ABI_BREAKING_CHECKS
603 assert(IsEarlyIncremented && "Cannot increment before dereferencing!");
604 IsEarlyIncremented = false;
605#endif
606 return *this;
607 }
608
611#if LLVM_ENABLE_ABI_BREAKING_CHECKS
612 assert(.IsEarlyIncremented && "Cannot compare after dereferencing!");
613#endif
614 return (const BaseT &)LHS == (const BaseT &)RHS;
615 }
616};
617
618
619
620
621
622
623
624
625
626
627
628
629
630template
633 using EarlyIncIteratorT =
637}
638
639
640template <typename R, typename UnaryPredicate>
641bool all_of(R &&range, UnaryPredicate P);
642
643template <typename R, typename UnaryPredicate>
644bool any_of(R &&range, UnaryPredicate P);
645
646template bool all_equal(std::initializer_list Values);
647
648template constexpr size_t range_size(R &&Range);
649
651
652using std::declval;
653
654
655
657 using type = std::tuple<decltype(*declval())...>;
658};
659
660template <typename ZipType, typename ReferenceTupleType, typename... Iters>
662 ZipType,
663 std::common_type_t<
664 std::bidirectional_iterator_tag,
665 typename std::iterator_traits::iterator_category...>,
666
667 ReferenceTupleType,
668 typename std::iterator_traits<
669 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
670
671
672
673
674 ReferenceTupleType *, ReferenceTupleType>;
675
676template <typename ZipType, typename ReferenceTupleType, typename... Iters>
681
683
684protected:
688
689 template <size_t... Ns> void tup_inc(std::index_sequence<Ns...>) {
690 (++std::get(iterators), ...);
691 }
692
693 template <size_t... Ns> void tup_dec(std::index_sequence<Ns...>) {
694 (--std::get(iterators), ...);
695 }
696
697 template <size_t... Ns>
699 std::index_sequence<Ns...>) const {
700 return ((std::get(this->iterators) == std::get(other.iterators)) &&
701 ...);
702 }
703
704public:
706
708
711 return static_cast<ZipType &>(*this);
712 }
713
716 "All inner iterators must be at least bidirectional.");
718 return static_cast<ZipType &>(*this);
719 }
720
721
725};
726
727template <typename... Iters>
729 typename ZipTupleType<Iters...>::type, Iters...> {
732
736};
737
738template <typename... Iters>
740 : zip_common<zip_shortest<Iters...>, typename ZipTupleType<Iters...>::type,
741 Iters...> {
744
746 return any_iterator_equals(other, std::index_sequence_for<Iters...>{});
747 }
748
749private:
750 template <size_t... Ns>
751 bool any_iterator_equals(const zip_shortest &other,
752 std::index_sequence<Ns...>) const {
753 return ((std::get(this->iterators) == std::get(other.iterators)) ||
754 ...);
755 }
756};
757
758
759template <template <typename...> class ItType, typename TupleStorageType,
760 typename IndexSequence>
762
763
764template <template <typename...> class ItType, typename... Args,
765 std::size_t... Ns>
767 std::index_sequence<Ns...>> {
769 std::get(declval<std::tuple<Args...> &>())))...>;
770};
771
772
773template <template <typename...> class ItType, typename... Args,
774 std::size_t... Ns>
776 std::index_sequence<Ns...>> {
778 std::get(declval<const std::tuple<Args...> &>())))...>;
779};
780
781template <template <typename...> class ItType, typename... Args> class zippy {
782private:
783 std::tuple<Args...> storage;
784 using IndexSequence = std::index_sequence_for<Args...>;
785
786public:
788 IndexSequence>::type;
791 IndexSequence>::type;
793 using value_type = typename iterator::value_type;
795 using pointer = typename iterator::pointer;
796 using reference = typename iterator::reference;
798
800
805
806private:
807 template <size_t... Ns>
808 const_iterator begin_impl(std::index_sequence<Ns...>) const {
810 }
811 template <size_t... Ns> iterator begin_impl(std::index_sequence<Ns...>) {
813 }
814
815 template <size_t... Ns>
816 const_iterator end_impl(std::index_sequence<Ns...>) const {
818 }
819 template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) {
821 }
822};
823
824}
825
826
827
828template <typename T, typename U, typename... Args>
830 Args &&...args) {
832 std::forward(t), std::forward(u), std::forward(args)...);
833}
834
835
836
837
838template <typename T, typename U, typename... Args>
840 Args &&...args) {
842 "Iteratees do not have equal length");
844 std::forward(t), std::forward(u), std::forward(args)...);
845}
846
847
848
849
850
851template <typename T, typename U, typename... Args>
853 Args &&...args) {
855 "First iteratee is not the shortest");
856
858 std::forward(t), std::forward(u), std::forward(args)...);
859}
860
862template
864 if (I == End)
865 return End;
866 return std::next(I);
867}
868
869template
870auto deref_or_none(const Iter &I, const Iter &End) -> std::optional<
871 std::remove_const_t<std::remove_reference_t<decltype(*I)>>> {
872 if (I == End)
873 return std::nullopt;
874 return *I;
875}
876
878 using type = std::optional<std::remove_const_t<
879 std::remove_reference_t<decltype(*std::declval())>>>;
880};
881
883 using type = std::tuple<typename ZipLongestItemType::type...>;
884};
885
886template <typename... Iters>
889 zip_longest_iterator<Iters...>,
890 std::common_type_t<
891 std::forward_iterator_tag,
892 typename std::iterator_traits::iterator_category...>,
893 typename ZipLongestTupleType<Iters...>::type,
894 typename std::iterator_traits<
895 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
896 typename ZipLongestTupleType<Iters...>::type *,
897 typename ZipLongestTupleType<Iters...>::type> {
898public:
900
901private:
902 std::tuple<Iters...> iterators;
903 std::tuple<Iters...> end_iterators;
904
905 template <size_t... Ns>
907 std::index_sequence<Ns...>) const {
908 return ((std::get(this->iterators) != std::get(other.iterators)) ||
909 ...);
910 }
911
912 template <size_t... Ns> value_type deref(std::index_sequence<Ns...>) const {
914 deref_or_none(std::get(iterators), std::get(end_iterators))...);
915 }
916
917 template <size_t... Ns>
918 decltype(iterators) tup_inc(std::index_sequence<Ns...>) const {
919 return std::tuple<Iters...>(
920 next_or_end(std::get(iterators), std::get(end_iterators))...);
921 }
922
923public:
925 : iterators(std::forward(ts.first)...),
926 end_iterators(std::forward(ts.second)...) {}
927
929 return deref(std::index_sequence_for<Iters...>{});
930 }
931
933 iterators = tup_inc(std::index_sequence_for<Iters...>{});
934 return *this;
935 }
936
938 return (other, std::index_sequence_for<Iters...>{});
939 }
940};
941
943public:
951
952private:
953 std::tuple<Args...> ts;
954
955 template <size_t... Ns>
956 iterator begin_impl(std::index_sequence<Ns...>) const {
958 adl_end(std::get(ts)))...);
959 }
960
961 template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) const {
962 return iterator(std::make_pair(adl_end(std::get(ts)),
963 adl_end(std::get(ts)))...);
964 }
965
966public:
968
970 return begin_impl(std::index_sequence_for<Args...>{});
971 }
972 iterator end() const { return end_impl(std::index_sequence_for<Args...>{}); }
973};
974}
975
976
977
978
979template <typename T, typename U, typename... Args>
981 Args &&... args) {
983 std::forward(t), std::forward(u), std::forward(args)...);
984}
985
986
987
988
989
990
991
992
993
994
995
996template <typename ValueT, typename... IterTs>
999 std::forward_iterator_tag, ValueT> {
1000 using BaseT = typename concat_iterator::iterator_facade_base;
1001
1002 static constexpr bool ReturnsByValue =
1003 !(std::is_reference_v<decltype(*std::declval())> && ...);
1004 static constexpr bool ReturnsConvertibleType =
1006 std::remove_cv_t,
1008 (std::is_convertible_v<decltype(*std::declval()), ValueT> && ...);
1009
1010
1011
1012 using reference_type =
1013 std::conditional_t<ReturnsByValue || ReturnsConvertibleType, ValueT,
1014 ValueT &>;
1015
1016
1017
1018
1019
1020
1021
1022 std::tuple<IterTs...> Begins;
1023 std::tuple<IterTs...> Ends;
1024
1025
1026
1027 template <size_t Index, size_t... Others> void incrementImpl() {
1028 auto &Begin = std::get(Begins);
1029 auto &End = std::get(Ends);
1030 if (Begin == End) {
1031 if constexpr (sizeof...(Others) != 0)
1032 return incrementImpl<Others...>();
1033 llvm_unreachable("Attempted to increment an end concat iterator!");
1034 }
1035 ++Begin;
1036 }
1037
1038
1039
1040
1041 template <size_t... Ns> void increment(std::index_sequence<Ns...>) {
1042 incrementImpl<Ns...>();
1043 }
1044
1045
1046
1047 template <size_t Index, size_t... Others> reference_type getImpl() const {
1048 auto &Begin = std::get(Begins);
1049 auto &End = std::get(Ends);
1050 if (Begin == End) {
1051 if constexpr (sizeof...(Others) != 0)
1052 return getImpl<Others...>();
1054 "Attempted to get a pointer from an end concat iterator!");
1055 }
1056 return *Begin;
1057 }
1058
1059
1060
1061
1062
1063 template <size_t... Ns> reference_type get(std::index_sequence<Ns...>) const {
1064 return getImpl<Ns...>();
1065 }
1066
1067public:
1068
1069
1070
1071
1072 template <typename... RangeTs>
1075
1076 using BaseT::operator++;
1077
1079 increment(std::index_sequence_for<IterTs...>());
1080 return *this;
1081 }
1082
1084 return get(std::index_sequence_for<IterTs...>());
1085 }
1086
1088 return Begins == RHS.Begins && Ends == RHS.Ends;
1089 }
1090};
1091
1093
1094
1095
1096
1097
1098
1099template <typename ValueT, typename... RangeTs> class concat_range {
1100public:
1103 decltype(adl_begin(std::declval<RangeTs &>()))...>;
1104
1105private:
1106 std::tuple<RangeTs...> Ranges;
1107
1108 template <size_t... Ns> iterator begin_impl(std::index_sequence<Ns...>) {
1109 return iterator(std::get(Ranges)...);
1110 }
1111 template <size_t... Ns>
1112 iterator begin_impl(std::index_sequence<Ns...>) const {
1113 return iterator(std::get(Ranges)...);
1114 }
1115 template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) {
1117 adl_end(std::get(Ranges)))...);
1118 }
1119 template <size_t... Ns> iterator end_impl(std::index_sequence<Ns...>) const {
1121 adl_end(std::get(Ranges)))...);
1122 }
1123
1124public:
1126 : Ranges(std::forward(Ranges)...) {}
1127
1129 return begin_impl(std::index_sequence_for<RangeTs...>{});
1130 }
1132 return begin_impl(std::index_sequence_for<RangeTs...>{});
1133 }
1135 return end_impl(std::index_sequence_for<RangeTs...>{});
1136 }
1138 return end_impl(std::index_sequence_for<RangeTs...>{});
1139 }
1140};
1141
1142}
1143
1144
1145
1146
1147
1148template <typename ValueT, typename... RangeTs>
1149[[nodiscard]] detail::concat_range<ValueT, RangeTs...>
1151 static_assert(sizeof...(RangeTs) > 1,
1152 "Need more than one range to concatenate!");
1154 std::forward(Ranges)...);
1155}
1156
1157
1158
1159template <typename DerivedT, typename BaseT, typename T,
1160 typename PointerT = T *, typename ReferenceT = T &>
1163 std::random_access_iterator_tag, T,
1164 std::ptrdiff_t, PointerT, ReferenceT> {
1165public:
1178
1180 this->index += offset;
1181 return static_cast<DerivedT &>(*this);
1182 }
1184 this->index -= offset;
1185 return static_cast<DerivedT &>(*this);
1186 }
1187
1188
1190
1191
1193
1194protected:
1199};
1200
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212template <typename DerivedT, typename BaseT, typename T,
1213 typename PointerT = T *, typename ReferenceT = T &>
1215public:
1217
1218
1220 PointerT, ReferenceT> {
1221 public:
1222
1224 return DerivedT::dereference_iterator(this->getBase(), this->getIndex());
1225 }
1226
1227 private:
1230
1231
1233 ReferenceT>;
1234 };
1235
1243
1247 assert(Index < size() && "invalid index for value range");
1248 return DerivedT::dereference_iterator(base, static_cast<ptrdiff_t>(Index));
1249 }
1251 assert(() && "expected non-empty range");
1252 return (*this)[0];
1253 }
1255 assert(() && "expected non-empty range");
1256 return (*this)[size() - 1];
1257 }
1258
1259
1261
1262
1264
1265
1266 DerivedT slice(size_t n, size_t m) const {
1267 assert(n + m <= size() && "invalid size specifiers");
1268 return DerivedT(offset_base(base, n), m);
1269 }
1270
1271
1273 assert(size() >= n && "Dropping more elements than exist");
1275 }
1276
1278 assert(size() >= n && "Dropping more elements than exist");
1279 return DerivedT(base, size() - n);
1280 }
1281
1282
1285 : static_cast<const DerivedT &>(*this);
1286 }
1287
1288
1291 : static_cast<const DerivedT &>(*this);
1292 }
1293
1294
1295 template <typename RangeT, typename = std::enable_if_t<std::is_constructible<
1297 operator RangeT() const {
1299 }
1300
1301
1303
1304private:
1305
1306 static BaseT offset_base(const BaseT &base, size_t n) {
1307 return n == 0 ? base : DerivedT::offset_base(base, n);
1308 }
1309
1310protected:
1315
1316
1318
1320};
1321
1322
1323template <typename OtherT, typename DerivedT, typename BaseT, typename T,
1324 typename PointerT, typename ReferenceT>
1326 ReferenceT> &lhs,
1327 const OtherT &rhs) {
1328 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1329}
1330
1331template <typename OtherT, typename DerivedT, typename BaseT, typename T,
1332 typename PointerT, typename ReferenceT>
1334 ReferenceT> &lhs,
1335 const OtherT &rhs) {
1336 return !(lhs == rhs);
1337}
1338}
1339
1340
1341
1342
1343
1344
1345
1346
1347template <typename DerivedT, typename BaseT, typename T,
1348 typename PointerT = T *, typename ReferenceT = T &>
1351 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT> {
1352public:
1355 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT>(
1358 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT,
1360
1361
1362 const BaseT &getBase() const { return this->base.first; }
1363
1364
1366
1367
1368 static std::pair<BaseT, ptrdiff_t>
1370
1371
1372 return {base.first, base.second + index};
1373 }
1374
1375 static ReferenceT
1378 return DerivedT::dereference(base.first, base.second + index);
1379 }
1380};
1381
1383
1384
1385
1386
1387
1388
1390public:
1391 using type = std::conditional_t<std::is_reference::value, FirstTy,
1392 std::remove_reference_t>;
1393};
1394}
1395
1396
1398 using EltTy = decltype(*adl_begin(c));
1401 EltTy, decltype((elt.first))>::type {
1402 return elt.first;
1403 });
1404}
1405
1406
1408 using EltTy = decltype(*adl_begin(c));
1410 std::forward(c),
1411 [](EltTy elt) ->
1413 decltype((elt.second))>::type {
1414 return elt.second;
1415 });
1416}
1417
1418
1419
1420template
1423 using ReferenceTy = typename std::iterator_traits::reference;
1425 [ShouldReverse](auto I) -> ReferenceTy {
1426 return ShouldReverse ? std::get<0>(I) : std::get<1>(I);
1427 });
1428}
1429
1430
1431
1432
1433
1434
1435
1436
1438 template bool operator()(const T &lhs, const T &rhs) const {
1439 return std::less<>()(std::get<0>(lhs), std::get<0>(rhs));
1440 }
1441};
1442
1443
1444
1445
1447 template bool operator()(const T &lhs, const T &rhs) const {
1448 return std::less<>()(std::get<1>(lhs), std::get<1>(rhs));
1449 }
1450};
1451
1452
1453
1454template
1457
1458 template
1459 decltype(auto) operator()(const T &lhs, const T &rhs) const {
1460 return func(lhs.first, rhs.first);
1461 }
1462};
1463
1464
1465
1466template struct rank : rank<N - 1> {};
1467template <> struct rank<0> {};
1468
1470template <typename... Ts> struct Visitor;
1471
1472template <typename HeadT, typename... TailTs>
1478 using Visitor<TailTs...>::operator();
1479};
1480
1486}
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516template <typename... CallableTs>
1517constexpr decltype(auto) makeVisitor(CallableTs &&...Callables) {
1518 return detail::Visitor<CallableTs...>(std::forward(Callables)...);
1519}
1520
1521
1522
1523
1524
1525
1526
1527template <class Iterator, class RNG>
1528void shuffle(Iterator first, Iterator last, RNG &&g) {
1529
1530
1531 using difference_type =
1532 typename std::iterator_traits::difference_type;
1533 for (auto size = last - first; size > 1; ++first, (void)--size) {
1534 difference_type offset = g() % size;
1535
1536
1537 if (offset != difference_type(0))
1538 std::iter_swap(first, first + offset);
1539 }
1540}
1541
1542
1543template
1545 if (std::less()(*reinterpret_cast<const T*>(P1),
1546 *reinterpret_cast<const T*>(P2)))
1547 return -1;
1548 if (std::less()(*reinterpret_cast<const T*>(P2),
1549 *reinterpret_cast<const T*>(P1)))
1550 return 1;
1551 return 0;
1552}
1553
1554
1555
1556template
1558 (const void*, const void*) {
1560}
1561
1562#ifdef EXPENSIVE_CHECKS
1564
1565inline unsigned presortShuffleEntropy() {
1566 static unsigned Result(std::random_device{}());
1568}
1569
1570template
1571inline void presortShuffle(IteratorTy Start, IteratorTy End) {
1572 std::mt19937 Generator(presortShuffleEntropy());
1574}
1575
1576}
1577#endif
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593template
1595
1596
1597 auto NElts = End - Start;
1598 if (NElts <= 1) return;
1599#ifdef EXPENSIVE_CHECKS
1600 detail::presortShuffle(Start, End);
1601#endif
1603}
1604
1605template
1607 IteratorTy Start, IteratorTy End,
1608 int (*Compare)(
1609 const typename std::iterator_traits::value_type *,
1610 const typename std::iterator_traits::value_type *)) {
1611
1612
1613 auto NElts = End - Start;
1614 if (NElts <= 1) return;
1615#ifdef EXPENSIVE_CHECKS
1616 detail::presortShuffle(Start, End);
1617#endif
1618 qsort(&*Start, NElts, sizeof(*Start),
1619 reinterpret_cast<int (*)(const void *, const void *)>(Compare));
1620}
1621
1623template
1624
1625
1627 std::is_pointer,
1628 std::is_trivially_copyable<typename std::iterator_traits::value_type>>;
1629}
1630
1631
1632
1633template
1634inline void sort(IteratorTy Start, IteratorTy End) {
1636
1637
1639 } else {
1640#ifdef EXPENSIVE_CHECKS
1641 detail::presortShuffle(Start, End);
1642#endif
1643 std::sort(Start, End);
1644 }
1645}
1646
1647template inline void sort(Container &&C) {
1649}
1650
1651template <typename IteratorTy, typename Compare>
1652inline void sort(IteratorTy Start, IteratorTy End, Compare Comp) {
1653#ifdef EXPENSIVE_CHECKS
1654 detail::presortShuffle(Start, End);
1655#endif
1656 std::sort(Start, End, Comp);
1657}
1658
1659template <typename Container, typename Compare>
1660inline void sort(Container &&C, Compare Comp) {
1662}
1663
1664
1665
1666template
1668 std::enable_if_t<
1669 std::is_base_of<std::random_access_iterator_tag,
1670 typename std::iterator_traits<decltype(
1671 Range.begin())>::iterator_category>::value,
1672 void> * = nullptr) {
1673 return std::distance(Range.begin(), Range.end());
1674}
1675
1677template
1679 decltype(adl_size(std::declval<Range &>()));
1680
1681template
1684}
1685
1686
1687
1688
1689
1690
1691
1698
1699
1702 std::forward(Init));
1703}
1704
1705
1706template <typename R, typename E, typename BinaryOp>
1709 std::forward(Init), std::forward(Op));
1710}
1711
1712
1713
1714template <typename R, typename E = detail::ValueOfRange>
1718
1719
1720
1721template <typename R, typename E = detail::ValueOfRange>
1723 return accumulate(std::forward(Range), std::move(Init),
1724 std::multiplies<>{});
1725}
1726
1727
1728
1729template <typename R, typename UnaryFunction>
1733
1734
1735
1736template <typename R, typename UnaryPredicate>
1740
1741
1742
1743template <typename R, typename UnaryPredicate>
1747
1748
1749
1750template <typename R, typename UnaryPredicate>
1754
1755
1756
1760
1761
1762
1763template <typename R, typename T> auto find(R &&Range, const T &Val) {
1765}
1766
1767
1768
1769template <typename R, typename UnaryPredicate>
1773
1774template <typename R, typename UnaryPredicate>
1778
1779
1780
1781template <typename R, typename UnaryPredicate>
1785
1786
1787
1788template <typename R, typename OutputIt, typename UnaryPredicate>
1792
1793
1794
1795
1796
1797
1798template <typename T, typename R, typename Predicate>
1800 T *RC = nullptr;
1802 if (T *PRC = P(A, AllowRepeats)) {
1803 if (RC) {
1804 if (!AllowRepeats || PRC != RC)
1805 return nullptr;
1806 } else {
1807 RC = PRC;
1808 }
1809 }
1810 }
1811 return RC;
1812}
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823template <typename T, typename R, typename Predicate>
1825 bool AllowRepeats = false) {
1826 T *RC = nullptr;
1828 std::pair<T *, bool> PRC = P(A, AllowRepeats);
1829 if (PRC.second) {
1830 assert(PRC.first == nullptr &&
1831 "Inconsistent return values in find_singleton_nested.");
1832 return PRC;
1833 }
1834 if (PRC.first) {
1835 if (RC) {
1836 if (!AllowRepeats || PRC.first != RC)
1837 return {nullptr, true};
1838 } else {
1839 RC = PRC.first;
1840 }
1841 }
1842 }
1843 return {RC, false};
1844}
1845
1846template <typename R, typename OutputIt>
1850
1851
1852
1853template <typename R, typename OutputIt, typename UnaryPredicate, typename T>
1855 const T &NewValue) {
1857 NewValue);
1858}
1859
1860
1861
1862template <typename R, typename OutputIt, typename T>
1864 const T &NewValue) {
1866 NewValue);
1867}
1868
1869
1870
1871template <typename R, typename T>
1875
1876
1877
1878template <typename R, typename OutputIt>
1882
1884template <typename Range, typename Element>
1886 decltype(std::declval<Range &>().contains(std::declval<const Element &>()));
1887
1888template <typename Range, typename Element>
1891
1892template <typename Range, typename Element>
1894 decltype(std::declval<Range &>().find(std::declval<const Element &>()) !=
1895 std::declval<Range &>().end());
1896
1897template <typename Range, typename Element>
1900
1901}
1902
1903
1904
1905
1906
1907
1908template <typename R, typename E>
1911 return Range.contains(Element);
1913 return Range.find(Element) != Range.end();
1914 else
1917}
1918
1919
1920
1921template <typename T, typename E>
1922constexpr bool is_contained(std::initializer_list Set, const E &Element) {
1923
1924 for (const T &V : Set)
1925 if (V == Element)
1926 return true;
1927 return false;
1928}
1929
1930
1931
1935
1936
1937
1941
1942
1943
1944
1945
1946template <typename R1, typename R2> bool includes(R1 &&Range1, R2 &&Range2) {
1947 assert(is_sorted(Range1) && "Range1 must be sorted in non-descending order");
1948 assert(is_sorted(Range2) && "Range2 must be sorted in non-descending order");
1951}
1952
1953
1954
1955
1956template <typename R1, typename R2, typename Compare>
1958 assert(is_sorted(Range1, C) && "Range1 must be sorted with respect to C");
1959 assert(is_sorted(Range2, C) && "Range2 must be sorted with respect to C");
1961 adl_end(Range2), std::forward(C));
1962}
1963
1964
1965
1966template <typename R, typename E> auto count(R &&Range, const E &Element) {
1968}
1969
1970
1971
1972template <typename R, typename UnaryPredicate>
1976
1977
1978
1979template <typename R, typename OutputIt, typename UnaryFunction>
1983
1984
1985
1986template <typename R, typename UnaryPredicate>
1990
1991
1992
1995 std::forward(Value));
1996}
1997
1998template <typename R, typename T, typename Compare>
2002}
2003
2004
2005
2008 std::forward(Value));
2009}
2010
2011template <typename R, typename T, typename Compare>
2015}
2016
2017
2018
2021 std::forward(Value));
2022}
2023
2024template <typename R, typename T, typename Compare>
2028}
2029
2030
2031
2035
2039
2040
2041
2045
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059template <typename R1, typename R2> auto mismatch(R1 &&Range1, R2 &&Range2) {
2062}
2063
2064template <typename R, typename IterTy>
2068
2069template
2073
2074template <typename R, typename Compare>
2078
2079
2080
2081template <typename R, typename Predicate,
2082 typename Val = decltype(*adl_begin(std::declval()))>
2086
2087template<typename Range, typename Predicate>
2091
2092
2093
2097
2098
2099
2100template <typename L, typename R> bool equal(L &&LRange, R &&RRange) {
2103}
2104
2105template <typename L, typename R, typename BinaryPredicate>
2106bool equal(L &&LRange, R &&RRange, BinaryPredicate P) {
2109}
2110
2111
2115 return Begin == End || std::equal(std::next(Begin), End, Begin);
2116}
2117
2118
2119
2120template bool all_equal(std::initializer_list Values) {
2122}
2123
2124
2125
2126
2127
2128
2129
2130
2131template <typename Container, typename UnaryPredicate>
2135
2136
2137
2138
2139template <typename Container, typename ValueType>
2141 C.erase(std::remove(C.begin(), C.end(), V), C.end());
2142}
2143
2144
2145
2146
2147template <typename Container, typename Range>
2151
2152
2153template <typename Container, typename... Args>
2156
2157 ((void)C.insert(C.end(), std::forward(Values)), ...);
2158}
2159
2160
2161
2162template <typename Container, typename RandomAccessIterator>
2163void replace(Container &Cont, typename Container::iterator ContIt,
2164 typename Container::iterator ContEnd, RandomAccessIterator ValIt,
2165 RandomAccessIterator ValEnd) {
2166 while (true) {
2167 if (ValIt == ValEnd) {
2168 Cont.erase(ContIt, ContEnd);
2169 return;
2170 }
2171 if (ContIt == ContEnd) {
2172 Cont.insert(ContIt, ValIt, ValEnd);
2173 return;
2174 }
2175 *ContIt = *ValIt;
2176 ++ContIt;
2177 ++ValIt;
2178 }
2179}
2180
2181
2182
2183template <typename Container, typename Range = std::initializer_list<
2184 typename Container::value_type>>
2185void replace(Container &Cont, typename Container::iterator ContIt,
2186 typename Container::iterator ContEnd, Range &&R) {
2188}
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200template <typename ForwardIterator, typename UnaryFunctor,
2201 typename NullaryFunctor,
2202 typename = std::enable_if_t<
2203 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2204 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2205inline void interleave(ForwardIterator begin, ForwardIterator end,
2206 UnaryFunctor each_fn, NullaryFunctor between_fn) {
2207 if (begin == end)
2208 return;
2209 each_fn(*begin);
2210 ++begin;
2211 for (; begin != end; ++begin) {
2212 between_fn();
2213 each_fn(*begin);
2214 }
2215}
2216
2217template <typename Container, typename UnaryFunctor, typename NullaryFunctor,
2218 typename = std::enable_if_t<
2219 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2220 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2221inline void interleave(const Container &c, UnaryFunctor each_fn,
2222 NullaryFunctor between_fn) {
2224}
2225
2226
2227template <typename Container, typename UnaryFunctor, typename StreamT,
2229inline void interleave(const Container &c, StreamT &os, UnaryFunctor each_fn,
2232}
2233template <typename Container, typename StreamT,
2235inline void interleave(const Container &c, StreamT &os,
2238 c, os, [&](const T &a) { os << a; }, separator);
2239}
2240
2241template <typename Container, typename UnaryFunctor, typename StreamT,
2244 UnaryFunctor each_fn) {
2246}
2247template <typename Container, typename StreamT,
2252
2253
2254
2255
2256
2262
2263template<typename First, typename Second>
2265 size_t operator()(const std::pair<First, Second> &P) const {
2266 return std::hash()(P.first) * 31 + std::hash()(P.second);
2267 }
2268};
2269
2270
2271
2274
2275
2276
2277
2278 template <typename A, typename B> auto operator()(A &lhs, B &rhs) const {
2281 return func(*lhs, *rhs);
2282 }
2283};
2284
2286
2287
2289
2290template <typename... Iters>
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304template <typename... Iters>
2306 EnumeratorTupleType<Iters...>, Iters...> {
2307 static_assert(sizeof...(Iters) >= 2, "Expected at least two iteratees");
2310
2312 return std::get<1>(this->iterators) == std::get<1>(Other.iterators);
2313 }
2314};
2315
2317 static constexpr std::size_t NumRefs = sizeof...(Refs);
2318 static_assert(NumRefs != 0);
2319
2321
2322
2324
2325
2327
2329 : Idx(Index), Storage(std::forward(Rs)...) {}
2330
2331
2332
2333 std::size_t index() const { return Idx; }
2334
2335
2336
2338 if constexpr (NumRefs == 1)
2339 return std::get<0>(Storage);
2340 else
2341 return Storage;
2342 }
2343
2344
2345 template <std::size_t I, typename = std::enable_if_t<I == 0>>
2347 return Result.Idx;
2348 }
2349
2350
2351
2352 template <std::size_t I, typename = std::enable_if_t<I != 0>>
2354
2355
2356
2357 return std::get<I - 1>(Result.Storage);
2358 }
2359
2360 template <typename... Ts>
2362 const std::tuple<std::size_t, Ts...> &Other) {
2363 static_assert(NumRefs == sizeof...(Ts), "Size mismatch");
2364 if (Result.Idx != std::get<0>(Other))
2365 return false;
2366 return Result.is_value_equal(Other, std::make_index_sequence{});
2367 }
2368
2369private:
2370 template <typename Tuple, std::size_t... Idx>
2371 bool is_value_equal(const Tuple &Other, std::index_sequence<Idx...>) const {
2372 return ((std::get(Storage) == std::get<Idx + 1>(Other)) && ...);
2373 }
2374
2375 std::size_t Idx;
2376
2377
2378
2379
2380
2381
2382
2383 mutable range_reference_tuple Storage;
2384};
2385
2388 std::random_access_iterator_tag, std::size_t> {
2390
2392 Index += N;
2393 return *this;
2394 }
2395
2397 Index -= N;
2398 return *this;
2399 }
2400
2402 return Index - R.Index;
2403 }
2404
2405
2406
2407
2408
2409
2411
2413 return Lhs.Index == Rhs.Index;
2414 }
2415
2417 return Lhs.Index < Rhs.Index;
2418 }
2419
2420private:
2421 std::size_t Index;
2422};
2423
2424
2428
2429
2430 return index_iterator{std::numeric_limitsstd::size\_t::max()};
2431 }
2432};
2433
2434}
2435
2436
2438 std::size_t Begin;
2439 std::size_t End;
2440
2441public:
2442 index_range(std::size_t Begin, std::size_t End) : Begin(Begin), End(End) {}
2445};
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483template <typename FirstRange, typename... RestRanges>
2485 if constexpr (sizeof...(Rest) != 0) {
2486#ifndef NDEBUG
2487
2488
2490 assert(all_equal(sizes) && "Ranges have different length");
2491#endif
2492 }
2494 FirstRange, RestRanges...>;
2496 std::forward(Rest)...);
2497}
2498
2500
2501template <typename Predicate, typename... Args>
2504 auto it = z.begin();
2505 auto end = z.end();
2506 while (it != end) {
2507 if (!std::apply([&](auto &&...args) { return P(args...); }, *it))
2508 return false;
2509 ++it;
2510 }
2511 return it.all_equals(end);
2512}
2513
2514
2515
2516template <typename... ArgsThenPredicate, size_t... InputIndexes>
2518 std::tuple<ArgsThenPredicate...> argsThenPredicate,
2519 std::index_sequence<InputIndexes...>) {
2520 auto constexpr OutputIndex =
2521 std::tuple_size<decltype(argsThenPredicate)>::value - 1;
2523 std::get(argsThenPredicate)...);
2524}
2525
2526}
2527
2528
2529
2530
2531template <typename... ArgsAndPredicate>
2532bool all_of_zip(ArgsAndPredicate &&...argsAndPredicate) {
2534 std::forward_as_tuple(argsAndPredicate...),
2535 std::make_index_sequence<sizeof...(argsAndPredicate) - 1>{});
2536}
2537
2538
2539
2540
2541template <typename IterTy,
2542 typename Pred = bool (*)(const decltype(*std::declval()) &)>
2544 IterTy &&Begin, IterTy &&End, unsigned N,
2545 Pred &&ShouldBeCounted =
2546 [](const decltype(*std::declval()) &) { return true; },
2547 std::enable_if_t<
2548 !std::is_base_of<std::random_access_iterator_tag,
2549 typename std::iterator_traits<std::remove_reference_t<
2550 decltype(Begin)>>::iterator_category>::value,
2551 void> * = nullptr) {
2552 for (; N; ++Begin) {
2553 if (Begin == End)
2554 return false;
2555 N -= ShouldBeCounted(*Begin);
2556 }
2557 for (; Begin != End; ++Begin)
2558 if (ShouldBeCounted(*Begin))
2559 return false;
2560 return true;
2561}
2562
2563
2564
2565
2566template <typename IterTy,
2567 typename Pred = bool (*)(const decltype(*std::declval()) &)>
2569 IterTy &&Begin, IterTy &&End, unsigned N,
2570 Pred &&ShouldBeCounted =
2571 [](const decltype(*std::declval()) &) { return true; },
2572 std::enable_if_t<
2573 !std::is_base_of<std::random_access_iterator_tag,
2574 typename std::iterator_traits<std::remove_reference_t<
2575 decltype(Begin)>>::iterator_category>::value,
2576 void> * = nullptr) {
2577 for (; N; ++Begin) {
2578 if (Begin == End)
2579 return false;
2580 N -= ShouldBeCounted(*Begin);
2581 }
2582 return true;
2583}
2584
2585
2586
2587template <typename IterTy,
2588 typename Pred = bool (*)(const decltype(*std::declval()) &)>
2590 IterTy &&Begin, IterTy &&End, unsigned N,
2591 Pred &&ShouldBeCounted = [](const decltype(*std::declval()) &) {
2592 return true;
2593 }) {
2594 assert(N != std::numeric_limits::max());
2595 return (Begin, End, N + 1, ShouldBeCounted);
2596}
2597
2598
2599template bool hasNItems(ContainerTy &&C, unsigned N) {
2601}
2602
2603
2604template
2608
2609
2610template
2614
2615
2617template using has_sizeof = decltype(sizeof(T));
2618}
2619
2620
2621
2622template
2624
2625}
2626
2627namespace std {
2628template <typename... Refs>
2629struct tuple_size<llvm::detail::enumerator_result<Refs...>>
2630 : std::integral_constant<std::size_t, sizeof...(Refs)> {};
2631
2632template <std::size_t I, typename... Refs>
2633struct tuple_element<I, llvm::detail::enumerator_result<Refs...>>
2634 : std::tuple_element<I, std::tuple<Refs...>> {};
2635
2636template <std::size_t I, typename... Refs>
2637struct tuple_element<I, const llvm::detail::enumerator_result<Refs...>>
2638 : std::tuple_element<I, std::tuple<Refs...>> {};
2639
2640}
2641
2642#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file contains library features backported from future STL versions.
INLINE void g(uint32_t *state, size_t a, size_t b, size_t c, size_t d, uint32_t x, uint32_t y)
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
bool valid() const
Definition STLExtras.h:281
decltype(auto) operator()(Pn &&...Params) const
Definition STLExtras.h:277
void reset()
Definition STLExtras.h:282
Callable(FnPtrOrRef &&F)
Definition STLExtras.h:273
Templated storage wrapper for a callable.
Definition STLExtras.h:188
bool reset()
Definition STLExtras.h:232
Callable(T const &O)
Definition STLExtras.h:200
Callable & operator=(Callable &&Other)
Definition STLExtras.h:212
bool valid() const
Definition STLExtras.h:231
Callable(Callable const &Other)=default
Callable & operator=(Callable const &Other)
Definition STLExtras.h:205
Callable(Callable &&Other)=default
Iterator wrapper that concatenates sequences together.
Definition STLExtras.h:999
concat_iterator & operator++()
Definition STLExtras.h:1078
bool operator==(const concat_iterator &RHS) const
Definition STLExtras.h:1087
reference_type operator*() const
Definition STLExtras.h:1083
concat_iterator(RangeTs &&...Ranges)
Constructs an iterator from a sequence of ranges.
Definition STLExtras.h:1073
Helper to store a sequence of ranges being concatenated and access them.
Definition STLExtras.h:1099
concat_range(RangeTs &&... Ranges)
Definition STLExtras.h:1125
concat_iterator< ValueT, decltype(adl_begin(std::declval< RangeTs & >()))... > iterator
Definition STLExtras.h:1101
iterator end()
Definition STLExtras.h:1134
iterator begin()
Definition STLExtras.h:1128
iterator end() const
Definition STLExtras.h:1137
iterator begin() const
Definition STLExtras.h:1131
Return a reference to the first or second member of a reference.
Definition STLExtras.h:1389
std::conditional_t< std::is_reference< EltTy >::value, FirstTy, std::remove_reference_t< FirstTy > > type
Definition STLExtras.h:1391
An iterator element of this range.
Definition STLExtras.h:1220
ReferenceT operator*() const
Definition STLExtras.h:1223
The class represents the base of a range of indexed_accessor_iterators.
Definition STLExtras.h:1214
ReferenceT front() const
Definition STLExtras.h:1250
DerivedT slice(size_t n, size_t m) const
Drop the first N elements, and keep M elements.
Definition STLExtras.h:1266
size_t size() const
Return the size of this range.
Definition STLExtras.h:1260
bool empty() const
Return if the range is empty.
Definition STLExtras.h:1263
indexed_accessor_range_base & operator=(const indexed_accessor_range_base &)=default
DerivedT take_front(size_t n=1) const
Take the first n elements.
Definition STLExtras.h:1283
ReferenceT operator[](size_t Index) const
Definition STLExtras.h:1246
iterator end() const
Definition STLExtras.h:1245
DerivedT drop_back(size_t n=1) const
Drop the last n elements.
Definition STLExtras.h:1277
indexed_accessor_range_base RangeBaseT
Definition STLExtras.h:1216
DerivedT take_back(size_t n=1) const
Take the last n elements.
Definition STLExtras.h:1289
DerivedT drop_front(size_t n=1) const
Drop the first n elements.
Definition STLExtras.h:1272
iterator begin() const
Definition STLExtras.h:1244
indexed_accessor_range_base(const indexed_accessor_range_base &)=default
indexed_accessor_range_base(BaseT base, ptrdiff_t count)
Definition STLExtras.h:1241
indexed_accessor_range_base(indexed_accessor_range_base &&)=default
indexed_accessor_range_base(iterator begin, iterator end)
Definition STLExtras.h:1236
ReferenceT back() const
Definition STLExtras.h:1254
ptrdiff_t count
The size from the owning range.
Definition STLExtras.h:1319
BaseT base
The base that owns the provided range of values.
Definition STLExtras.h:1317
indexed_accessor_range_base(const iterator_range< iterator > &range)
Definition STLExtras.h:1239
const BaseT & getBase() const
Returns the base of this range.
Definition STLExtras.h:1302
Definition STLExtras.h:897
zip_longest_iterator(std::pair< Iters &&, Iters && >... ts)
Definition STLExtras.h:924
value_type operator*() const
Definition STLExtras.h:928
bool operator==(const zip_longest_iterator< Iters... > &other) const
Definition STLExtras.h:937
zip_longest_iterator< Iters... > & operator++()
Definition STLExtras.h:932
typename ZipLongestTupleType< Iters... >::type value_type
Definition STLExtras.h:899
Definition STLExtras.h:942
typename iterator::iterator_category iterator_category
Definition STLExtras.h:946
typename iterator::pointer pointer
Definition STLExtras.h:949
iterator end() const
Definition STLExtras.h:972
typename iterator::difference_type difference_type
Definition STLExtras.h:948
zip_longest_iterator< decltype(adl_begin(std::declval< Args >()))... > iterator
Definition STLExtras.h:944
iterator begin() const
Definition STLExtras.h:969
typename iterator::reference reference
Definition STLExtras.h:950
zip_longest_range(Args &&... ts_)
Definition STLExtras.h:967
typename iterator::value_type value_type
Definition STLExtras.h:947
Definition STLExtras.h:781
typename ZippyIteratorTuple< ItType, decltype(storage), IndexSequence >::type iterator
Definition STLExtras.h:787
iterator end()
Definition STLExtras.h:804
typename iterator::value_type value_type
Definition STLExtras.h:793
typename iterator::difference_type difference_type
Definition STLExtras.h:794
typename iterator::reference reference
Definition STLExtras.h:796
typename iterator::pointer pointer
Definition STLExtras.h:795
typename ZippyIteratorTuple< ItType, const decltype(storage), IndexSequence >::type const_iterator
Definition STLExtras.h:789
zippy(Args &&...args)
Definition STLExtras.h:799
typename const_iterator::reference const_reference
Definition STLExtras.h:797
const_iterator begin() const
Definition STLExtras.h:801
typename iterator::iterator_category iterator_category
Definition STLExtras.h:792
const_iterator end() const
Definition STLExtras.h:803
iterator begin()
Definition STLExtras.h:802
A pseudo-iterator adaptor that is designed to implement "early increment" style loops.
Definition STLExtras.h:578
friend bool operator==(const early_inc_iterator_impl &LHS, const early_inc_iterator_impl &RHS)
Definition STLExtras.h:609
early_inc_iterator_impl(WrappedIteratorT I)
Definition STLExtras.h:589
early_inc_iterator_impl & operator++()
Definition STLExtras.h:601
decltype(*std::declval< WrappedIteratorT >()) operator*()
Definition STLExtras.h:592
An iterator adaptor that filters the elements of given inner iterators.
Definition STLExtras.h:437
PredicateT Pred
Definition STLExtras.h:442
filter_iterator_base & operator++()
Definition STLExtras.h:463
filter_iterator_base()=default
WrappedIteratorT End
Definition STLExtras.h:441
void findNextValid()
Definition STLExtras.h:444
filter_iterator_base(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
Definition STLExtras.h:454
filter_iterator_impl()=default
filter_iterator_impl(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
Definition STLExtras.h:511
filter_iterator_impl & operator--()
Definition STLExtras.h:515
Specialization of filter_iterator_base for forward iteration only.
Definition STLExtras.h:484
filter_iterator_impl(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
Definition STLExtras.h:488
filter_iterator_impl()=default
index_range(std::size_t Begin, std::size_t End)
Definition STLExtras.h:2442
detail::index_iterator begin() const
Definition STLExtras.h:2443
detail::index_iterator end() const
Definition STLExtras.h:2444
A utility class used to implement an iterator that contains some base object and an index.
Definition STLExtras.h:1164
DerivedT & operator+=(ptrdiff_t offset)
Definition STLExtras.h:1179
const BaseT & getBase() const
Returns the current base of the iterator.
Definition STLExtras.h:1192
bool operator==(const indexed_accessor_iterator &rhs) const
Definition STLExtras.h:1170
indexed_accessor_iterator(BaseT base, ptrdiff_t index)
Definition STLExtras.h:1195
ptrdiff_t index
Definition STLExtras.h:1198
DerivedT & operator-=(ptrdiff_t offset)
Definition STLExtras.h:1183
ptrdiff_t operator-(const indexed_accessor_iterator &rhs) const
Definition STLExtras.h:1166
bool operator<(const indexed_accessor_iterator &rhs) const
Definition STLExtras.h:1174
BaseT base
Definition STLExtras.h:1197
ptrdiff_t getIndex() const
Returns the current index of the iterator.
Definition STLExtras.h:1189
indexed_accessor_range(BaseT base, ptrdiff_t startIndex, ptrdiff_t count)
Definition STLExtras.h:1353
const BaseT & getBase() const
Returns the current base of the range.
Definition STLExtras.h:1362
ptrdiff_t getStartIndex() const
Returns the current start index of the range.
Definition STLExtras.h:1365
static ReferenceT dereference_iterator(const std::pair< BaseT, ptrdiff_t > &base, ptrdiff_t index)
See detail::indexed_accessor_range_base for details.
Definition STLExtras.h:1376
static std::pair< BaseT, ptrdiff_t > offset_base(const std::pair< BaseT, ptrdiff_t > &base, ptrdiff_t index)
See detail::indexed_accessor_range_base for details.
Definition STLExtras.h:1369
iterator_adaptor_base()=default
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
std::common_type_t< std::forward_iterator_tag, std::iterator_traits< Iters >::iterator_category... > iterator_category
std::iterator_traits< std::tuple_element_t< 0, std::tuple< Iters... > > >::difference_type difference_type
ZipLongestTupleType< Iters... >::type reference
ZipLongestTupleType< Iters... >::type * pointer
A range adaptor for a pair of iterators.
ItTy getCurrent()
Definition STLExtras.h:387
mapped_iterator_base BaseT
Definition STLExtras.h:382
mapped_iterator_base(ItTy U)
Definition STLExtras.h:384
ReferenceTy operator*() const
Definition STLExtras.h:389
Definition STLExtras.h:340
mapped_iterator()=default
const FuncTy & getFunction() const
Definition STLExtras.h:348
mapped_iterator(ItTy U, FuncTy F)
Definition STLExtras.h:343
ItTy getCurrent()
Definition STLExtras.h:346
ReferenceTy operator*() const
Definition STLExtras.h:350
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
@ C
The default llvm calling convention, compatible with C.
Definition STLExtras.h:174
decltype(adl_rbegin(std::declval< Range & >())) check_has_free_function_rbegin
Definition STLExtras.h:396
auto deref_or_none(const Iter &I, const Iter &End) -> std::optional< std::remove_const_t< std::remove_reference_t< decltype(*I)> > >
Definition STLExtras.h:870
enumerator_result< decltype(*declval< Iters >())... > EnumeratorTupleType
Definition STLExtras.h:2291
bool all_of_zip_predicate_first(Predicate &&P, Args &&...args)
Definition STLExtras.h:2502
const char unit< Period >::value[]
static constexpr bool HasMemberFind
Definition STLExtras.h:1898
static constexpr bool HasFreeFunctionRBegin
Definition STLExtras.h:400
decltype(adl_size(std::declval< Range & >())) check_has_free_function_size
Definition STLExtras.h:1678
bool operator!=(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)
Inequality comparison for DenseSet.
static constexpr bool HasMemberContains
Definition STLExtras.h:1889
std::conditional_t< std::is_base_of_v< std::bidirectional_iterator_tag, typename std::iterator_traits< IterT >::iterator_category >, std::bidirectional_iterator_tag, std::forward_iterator_tag > fwd_or_bidi_tag
A type alias which is std::bidirectional_iterator_tag if the category of IterT derives from it,...
Definition STLExtras.h:527
bool all_of_zip_predicate_last(std::tuple< ArgsThenPredicate... > argsThenPredicate, std::index_sequence< InputIndexes... >)
Definition STLExtras.h:2517
decltype(std::declval< Range & >().contains(std::declval< const Element & >())) check_has_member_contains_t
Definition STLExtras.h:1885
decltype(adl_begin(std::declval< RangeT & >())) IterOfRange
decltype(sizeof(T)) has_sizeof
Definition STLExtras.h:2617
decltype(std::declval< Range & >().find(std::declval< const Element & >()) != std::declval< Range & >().end()) check_has_member_find_t
Definition STLExtras.h:1893
Iter next_or_end(const Iter &I, const Iter &End)
Definition STLExtras.h:863
iterator_facade_base< ZipType, std::common_type_t< std::bidirectional_iterator_tag, typename std::iterator_traits< Iters >::iterator_category... >, ReferenceTupleType, typename std::iterator_traits< std::tuple_element_t< 0, std::tuple< Iters... > > >::difference_type, ReferenceTupleType *, ReferenceTupleType > zip_traits
Definition STLExtras.h:661
static constexpr bool HasFreeFunctionSize
Definition STLExtras.h:1682
bool operator==(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)
Equality comparison for DenseSet.
std::remove_reference_t< decltype(*adl_begin(std::declval< RangeT & >()))> ValueOfRange
std::conjunction< std::is_pointer< T >, std::is_trivially_copyable< typename std::iterator_traits< T >::value_type > > sort_trivially_copyable
Definition STLExtras.h:1626
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
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:829
void stable_sort(R &&Range)
Definition STLExtras.h:2070
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1763
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1757
bool includes(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::includes which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1946
auto min_element(R &&Range)
Provide wrappers to std::min_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2032
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1730
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:1737
detail::zip_longest_range< T, U, Args... > zip_longest(T &&t, U &&u, Args &&... args)
Iterate over two or more iterators at the same time.
Definition STLExtras.h:980
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition STLExtras.h:1667
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:1557
constexpr bool is_incomplete_v
Detects when type T is incomplete.
Definition STLExtras.h:2623
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
Definition STLExtras.h:839
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2484
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
Definition STLExtras.h:2205
constexpr bool all_types_equal_v
Definition STLExtras.h:122
auto accumulate(R &&Range, E &&Init)
Wrapper for std::accumulate.
Definition STLExtras.h:1700
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
Definition STLExtras.h:2083
int array_pod_sort_comparator(const void *P1, const void *P2)
Adapt std::less for array_pod_sort.
Definition STLExtras.h:1544
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
Definition STLExtras.h:359
decltype(auto) getSingleElement(ContainerTy &&C)
Asserts that the given container has a single element and returns that element.
Definition STLExtras.h:309
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition STLExtras.h:2148
bool hasNItemsOrLess(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;})
Returns true if the sequence [Begin, End) has N or less items.
Definition STLExtras.h:2589
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
Definition STLExtras.h:2243
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:632
void shuffle(Iterator first, Iterator last, RNG &&g)
Definition STLExtras.h:1528
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
auto uninitialized_copy(R &&Src, IterTy Dst)
Definition STLExtras.h:2065
auto unique(Range &&R, Predicate P)
Definition STLExtras.h:2088
auto binary_search(R &&Range, T &&Value)
Provide wrappers to std::binary_search which take ranges instead of having to pass begin/end explicit...
Definition STLExtras.h:1993
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2019
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:1789
auto map_range(ContainerTy &&C, FuncTy F)
Definition STLExtras.h:364
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
Definition STLExtras.h:1150
constexpr auto adl_rbegin(RangeT &&range) -> decltype(adl_detail::rbegin_impl(std::forward< RangeT >(range)))
Returns the reverse-begin iterator to range using std::rbegin and function found through Argument-Dep...
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
Definition STLExtras.h:2568
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
Definition STLExtras.h:2140
OutputIt transform(R &&Range, OutputIt d_first, UnaryFunction F)
Wrapper function around std::transform to apply a function to a range and store the result elsewhere.
Definition STLExtras.h:1980
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:1744
auto mismatch(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::mismatch which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:2059
auto reverse(ContainerTy &&C)
Definition STLExtras.h:406
constexpr size_t range_size(R &&Range)
Returns the size of the Range, i.e., the number of elements.
Definition STLExtras.h:1692
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:852
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1634
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
Definition STLExtras.h:2543
auto find_if_not(R &&Range, UnaryPredicate P)
Definition STLExtras.h:1775
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:1751
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
Definition STLExtras.h:1397
constexpr auto adl_size(RangeT &&range) -> decltype(adl_detail::size_impl(std::forward< RangeT >(range)))
Returns the size of range using std::size and functions found through Argument-Dependent Lookup (ADL)...
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
Definition STLExtras.h:1932
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition STLExtras.h:300
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:550
std::pair< T *, bool > find_singleton_nested(R &&Range, Predicate P, bool AllowRepeats=false)
Return a pair consisting of the single value in Range that satisfies P( ,...
Definition STLExtras.h:1824
std::conjunction< std::is_same< T, Ts >... > all_types_equal
traits class for checking whether type T is same as all other types in Ts.
Definition STLExtras.h:120
T * find_singleton(R &&Range, Predicate P, bool AllowRepeats=false)
Return the single value in Range that satisfies P( *, AllowRepeats)->T * returning n...
Definition STLExtras.h:1799
auto reverse_conditionally(ContainerTy &&C, bool ShouldReverse)
Return a range that conditionally reverses C.
Definition STLExtras.h:1421
iterator_range(Container &&) -> iterator_range< llvm::detail::IterOfRange< Container > >
auto drop_end(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the last N elements excluded.
Definition STLExtras.h:323
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1782
std::disjunction< std::is_same< T, Ts >... > is_one_of
traits class for checking whether type T is one of any of the given types in the variadic list.
Definition STLExtras.h:110
constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS)
Helper which adds two underlying types of enumeration type.
Definition STLExtras.h:166
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2006
void replace(R &&Range, const T &OldValue, const T &NewValue)
Provide wrappers to std::replace which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1872
auto product_of(R &&Range, E Init=E{1})
Returns the product of all values in Range with Init initial value.
Definition STLExtras.h:1722
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition STLExtras.h:1966
DWARFExpression::Operation Op
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2042
OutputIt replace_copy_if(R &&Range, OutputIt Out, UnaryPredicate P, const T &NewValue)
Provide wrappers to std::replace_copy_if which take ranges instead of having to pass begin/end explic...
Definition STLExtras.h:1854
OutputIt copy(R &&Range, OutputIt Out)
Definition STLExtras.h:1847
auto partition(R &&Range, UnaryPredicate P)
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1987
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
Definition STLExtras.h:1407
auto sum_of(R &&Range, E Init=E{0})
Returns the sum of all values in Range with Init initial value.
Definition STLExtras.h:1715
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1879
OutputIt replace_copy(R &&Range, OutputIt Out, const T &OldValue, const T &NewValue)
Provide wrappers to std::replace_copy which take ranges instead of having to pass begin/end explicitl...
Definition STLExtras.h:1863
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:1973
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
Definition STLExtras.h:159
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1770
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2132
constexpr auto adl_rend(RangeT &&range) -> decltype(adl_detail::rend_impl(std::forward< RangeT >(range)))
Returns the reverse-end iterator to range using std::rend and functions found through Argument-Depend...
void append_values(Container &C, Args &&...Values)
Appends all Values to container C.
Definition STLExtras.h:2154
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1909
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
bool all_equal(std::initializer_list< T > Values)
Returns true if all Values in the initializer lists are equal or the list.
Definition STLExtras.h:2120
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:1594
constexpr decltype(auto) makeVisitor(CallableTs &&...Callables)
Returns an opaquely-typed Callable object whose operator() overload set is the sum of the operator() ...
Definition STLExtras.h:1517
filter_iterator_impl< WrappedIteratorT, PredicateT, detail::fwd_or_bidi_tag< WrappedIteratorT > > filter_iterator
Defines filter_iterator to a suitable specialization of filter_iterator_impl, based on the underlying...
Definition STLExtras.h:537
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
Definition STLExtras.h:2100
std::conjunction< std::is_base_of< T, Ts >... > are_base_of
traits class for checking whether type T is a base class for all the given types in the variadic list...
Definition STLExtras.h:115
bool all_of_zip(ArgsAndPredicate &&...argsAndPredicate)
Compare two zipped ranges using the provided predicate (as last argument).
Definition STLExtras.h:2532
Implement std::hash so that hash_code can be used in STL containers.
Find the first index where a type appears in a list of types.
Definition STLExtras.h:148
Definition STLExtras.h:2257
void operator()(void *v)
Definition STLExtras.h:2258
Determine if all types in Ts are distinct.
Definition STLExtras.h:131
Binary functor that adapts to any other binary functor after dereferencing operands.
Definition STLExtras.h:2272
auto operator()(A &lhs, B &rhs) const
Definition STLExtras.h:2278
T func
Definition STLExtras.h:2273
constexpr Visitor(HeadT &&Head, TailTs &&...Tail)
Definition STLExtras.h:1474
constexpr Visitor(HeadT &&Head)
Definition STLExtras.h:1482
Definition STLExtras.h:1470
Definition STLExtras.h:877
std::optional< std::remove_const_t< std::remove_reference_t< decltype(*std::declval< Iter >())> > > type
Definition STLExtras.h:878
Definition STLExtras.h:882
std::tuple< typename ZipLongestItemType< Iters >::type... > type
Definition STLExtras.h:883
Definition STLExtras.h:656
std::tuple< decltype(*declval< Iters >())... > type
Definition STLExtras.h:657
ItType< decltype(adl_begin( std::get< Ns >(declval< const std::tuple< Args... > & >())))... > type
Definition STLExtras.h:777
ItType< decltype(adl_begin( std::get< Ns >(declval< std::tuple< Args... > & >())))... > type
Definition STLExtras.h:768
Helper to obtain the iterator types for the tuple storage within zippy.
Definition STLExtras.h:761
std::tuple< Refs... > range_reference_tuple
Definition STLExtras.h:2323
decltype(auto) value() const
Returns the value(s) for the current iterator.
Definition STLExtras.h:2337
static constexpr std::size_t NumValues
Definition STLExtras.h:2320
friend decltype(auto) get(const enumerator_result &Result)
Returns the value at index I.
Definition STLExtras.h:2353
static constexpr std::size_t NumRefs
Definition STLExtras.h:2317
std::tuple< std::size_t, Refs... > value_reference_tuple
Definition STLExtras.h:2326
friend bool operator==(const enumerator_result &Result, const std::tuple< std::size_t, Ts... > &Other)
Definition STLExtras.h:2361
std::size_t index() const
Returns the 0-based index of the current position within the original input range(s).
Definition STLExtras.h:2333
friend std::size_t get(const enumerator_result &Result)
Returns the value at index I. This case covers the index.
Definition STLExtras.h:2346
enumerator_result(std::size_t Index, Refs &&...Rs)
Definition STLExtras.h:2328
Tuple-like type for zip_enumerator dereference.
Definition STLExtras.h:2288
Definition STLExtras.h:2388
friend bool operator==(const index_iterator &Lhs, const index_iterator &Rhs)
Definition STLExtras.h:2412
std::ptrdiff_t operator-(const index_iterator &R) const
Definition STLExtras.h:2401
std::size_t operator*() const
Definition STLExtras.h:2410
friend bool operator<(const index_iterator &Lhs, const index_iterator &Rhs)
Definition STLExtras.h:2416
index_iterator & operator-=(std::ptrdiff_t N)
Definition STLExtras.h:2396
index_iterator & operator+=(std::ptrdiff_t N)
Definition STLExtras.h:2391
index_iterator(std::size_t Index)
Definition STLExtras.h:2389
Infinite stream of increasing 0-based size_t indices.
Definition STLExtras.h:2425
index_iterator begin() const
Definition STLExtras.h:2426
index_iterator end() const
Definition STLExtras.h:2427
zip_traits< ZipType, ReferenceTupleType, Iters... > Base
Definition STLExtras.h:678
std::index_sequence_for< Iters... > IndexSequence
Definition STLExtras.h:679
void tup_inc(std::index_sequence< Ns... >)
Definition STLExtras.h:689
zip_common(Iters &&... ts)
Definition STLExtras.h:705
bool test_all_equals(const zip_common &other, std::index_sequence< Ns... >) const
Definition STLExtras.h:698
std::tuple< Iters... > iterators
Definition STLExtras.h:682
ZipType & operator++()
Definition STLExtras.h:709
value_type operator*() const
Definition STLExtras.h:707
typename Base::value_type value_type
Definition STLExtras.h:680
bool all_equals(zip_common &other)
Return true if all the iterator are matching other's iterators.
Definition STLExtras.h:722
ZipType & operator--()
Definition STLExtras.h:714
void tup_dec(std::index_sequence< Ns... >)
Definition STLExtras.h:693
value_type deref(std::index_sequence< Ns... >) const
Definition STLExtras.h:685
Zippy iterator that uses the second iterator for comparisons.
Definition STLExtras.h:2306
bool operator==(const zip_enumerator &Other) const
Definition STLExtras.h:2311
Definition STLExtras.h:729
bool operator==(const zip_first &other) const
Definition STLExtras.h:733
Definition STLExtras.h:741
bool operator==(const zip_shortest &other) const
Definition STLExtras.h:745
std::tuple_element_t< Index, std::tuple< Args... > > arg_t
The type of an argument to this function.
Definition STLExtras.h:80
ReturnType result_t
The result type of this function.
Definition STLExtras.h:76
@ num_args
Definition STLExtras.h:73
std::tuple_element_t< i, std::tuple< Args... > > arg_t
The type of an argument to this function.
Definition STLExtras.h:97
@ num_args
Definition STLExtras.h:90
ReturnType result_t
The result type of this function.
Definition STLExtras.h:93
This class provides various trait information about a callable object.
Definition STLExtras.h:67
Function object to check whether the first component of a container supported by std::get (like std::...
Definition STLExtras.h:1437
bool operator()(const T &lhs, const T &rhs) const
Definition STLExtras.h:1438
Function object to check whether the second component of a container supported by std::get (like std:...
Definition STLExtras.h:1446
bool operator()(const T &lhs, const T &rhs) const
Definition STLExtras.h:1447
Definition STLExtras.h:54
std::add_pointer_t< std::add_const_t< T > > type
Definition STLExtras.h:55
Definition STLExtras.h:58
std::add_lvalue_reference_t< std::add_const_t< T > > type
Definition STLExtras.h:59
Function object to apply a binary function to the first component of a std::pair.
Definition STLExtras.h:1455
FuncTy func
Definition STLExtras.h:1456
Definition STLExtras.h:2264
size_t operator()(const std::pair< First, Second > &P) const
Definition STLExtras.h:2265
Utility type to build an inheritance chain that makes it easy to rank overload candidates.
Definition STLExtras.h:1466