17#ifndef LLVM_ADT_STLEXTRAS_H
18#define LLVM_ADT_STLEXTRAS_H
25#include "llvm/Config/abi-breaking.h"
33#include <initializer_list>
43#ifdef EXPENSIVE_CHECKS
54 using type = std::add_pointer_t<std::add_const_t<T>>;
58 using type = std::add_lvalue_reference_t<std::add_const_t<T>>;
65template <typename T, bool isClass = std::is_class<T>::value>
69template <
typename ClassType,
typename ReturnType,
typename... Args>
78 template <
size_t Index>
79 using arg_t = std::tuple_element_t<Index, std::tuple<Args...>>;
82template <
typename ClassType,
typename ReturnType,
typename... Args>
86template <
typename ReturnType,
typename... Args>
96 using arg_t = std::tuple_element_t<i, std::tuple<Args...>>;
98template <
typename ReturnType,
typename... Args>
102template <
typename ReturnType,
typename... Args>
108template <
typename T,
typename... Ts>
109using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
113template <
typename T,
typename... Ts>
118template <
typename T = void,
typename... Ts>
120template <
typename T = void,
typename... Ts>
132template <
typename T,
typename... Us>
134 : std::conjunction<std::negation<is_one_of<T, Us...>>,
135 TypesAreDistinct<Us...>> {};
148template <
typename T,
typename U,
typename... Us>
150 : std::integral_constant<size_t, 1 + FirstIndexOfType<T, Us...>::value> {};
151template <
typename T,
typename... Us>
157template <
size_t I,
typename... Ts>
162template <
typename EnumTy1,
typename EnumTy2,
163 typename = std::enable_if_t<std::is_enum_v<EnumTy1> &&
164 std::is_enum_v<EnumTy2>>>
186 bool = std::is_function_v<std::remove_pointer_t<remove_cvref_t<T>>>>
188 using value_type = std::remove_reference_t<T>;
189 using reference = value_type &;
190 using const_reference = value_type
const &;
192 std::optional<value_type> Obj;
194 static_assert(!std::is_pointer_v<value_type>,
195 "Pointers to non-functions are not callable.");
207 Obj.emplace(*
Other.Obj);
214 Obj.emplace(std::move(*
Other.Obj));
218 template <
typename... Pn,
219 std::enable_if_t<std::is_invocable_v<
T, Pn...>,
int> = 0>
220 decltype(
auto)
operator()(Pn &&...Params) {
221 return std::invoke(*Obj, std::forward<Pn>(Params)...);
224 template <
typename... Pn,
225 std::enable_if_t<std::is_invocable_v<
T const, Pn...>,
int> = 0>
226 decltype(
auto)
operator()(Pn &&...Params)
const {
227 return std::invoke(*Obj, std::forward<Pn>(Params)...);
230 bool valid()
const {
return Obj != std::nullopt; }
231 bool reset() {
return Obj = std::nullopt; }
233 operator reference() {
return *Obj; }
234 operator const_reference()
const {
return *Obj; }
240 static constexpr bool IsPtr = std::is_pointer_v<remove_cvref_t<T>>;
242 using StorageT = std::conditional_t<IsPtr, T, std::remove_reference_t<T> *>;
243 using CastT = std::conditional_t<IsPtr, T, T &>;
246 StorageT Func =
nullptr;
249 template <
typename In>
static constexpr auto convertIn(In &&
I) {
250 if constexpr (IsPtr) {
269 !std::is_same_v<remove_cvref_t<FnPtrOrRef>,
Callable>,
int
274 template <
typename... Pn,
275 std::enable_if_t<std::is_invocable_v<
T, Pn...>,
int> = 0>
277 return Func(std::forward<Pn>(Params)...);
280 bool valid()
const {
return Func !=
nullptr; }
283 operator T const &()
const {
284 if constexpr (IsPtr) {
288 static_assert(std::is_reference_v<T>,
289 "Expected a reference to a function.");
302 return B !=
E && std::next(
B) ==
E;
307template <
typename ContainerTy>
315template <
typename T>
auto drop_begin(
T &&RangeOrContainer,
size_t N = 1) {
322template <
typename T>
auto drop_end(
T &&RangeOrContainer,
size_t N = 1) {
324 std::prev(
adl_end(RangeOrContainer),
N));
330template <
typename ItTy,
typename FuncTy,
331 typename ReferenceTy =
332 std::invoke_result_t<FuncTy, decltype(*std::declval<ItTy>())>>
337 std::remove_reference_t<ReferenceTy>,
339 std::remove_reference_t<ReferenceTy> *, ReferenceTy> {
357template <
class ItTy,
class FuncTy>
364template <
class ContainerTy,
class FuncTy>
374template <
typename DerivedT,
typename ItTy,
typename ReferenceTy>
378 typename std::iterator_traits<ItTy>::iterator_category,
379 std::remove_reference_t<ReferenceTy>,
380 typename std::iterator_traits<ItTy>::difference_type,
381 std::remove_reference_t<ReferenceTy> *, ReferenceTy> {
391 return static_cast<const DerivedT &
>(*this).mapElement(*this->I);
396template <
typename Range>
398 decltype(
adl_rbegin(std::declval<Range &>()));
400template <
typename Range>
407template <
typename ContainerTy> [[nodiscard]]
auto reverse(ContainerTy &&
C) {
431template <
typename WrappedIteratorT,
typename PredicateT,
typename IterTag>
434 filter_iterator_base<WrappedIteratorT, PredicateT, IterTag>,
436 std::common_type_t<IterTag,
437 typename std::iterator_traits<
438 WrappedIteratorT>::iterator_category>> {
446 while (this->I !=
End && !
Pred(*this->I))
462 using BaseT::operator++;
470 decltype(
auto)
operator*()
const {
471 assert(BaseT::wrapped() !=
End &&
"Cannot dereference end iterator!");
472 return BaseT::operator*();
475 decltype(
auto) operator->()
const {
476 assert(BaseT::wrapped() !=
End &&
"Cannot dereference end iterator!");
477 return BaseT::operator->();
483 typename IterTag = std::forward_iterator_tag>
495template <
typename WrappedIteratorT,
typename PredicateT>
497 std::bidirectional_iterator_tag>
499 std::bidirectional_iterator_tag> {
502 void findPrevValid() {
503 while (!this->
Pred(*this->I))
508 using BaseT::operator--;
527template <
typename IterT>
529 std::is_base_of_v<std::bidirectional_iterator_tag,
530 typename std::iterator_traits<IterT>::iterator_category>,
531 std::bidirectional_iterator_tag, std::forward_iterator_tag>;
537template <
typename WrappedIteratorT,
typename PredicateT>
549template <
typename RangeT,
typename PredicateT>
552 using FilterIteratorT =
556 return make_range(FilterIteratorT(
B,
E, Pred), FilterIteratorT(
E,
E, Pred));
576template <
typename WrappedIteratorT>
579 WrappedIteratorT, std::input_iterator_tag> {
582 using PointerT =
typename std::iterator_traits<WrappedIteratorT>::pointer;
585#if LLVM_ENABLE_ABI_BREAKING_CHECKS
586 bool IsEarlyIncremented =
false;
592 using BaseT::operator*;
593 decltype(*std::declval<WrappedIteratorT>())
operator*() {
594#if LLVM_ENABLE_ABI_BREAKING_CHECKS
595 assert(!IsEarlyIncremented &&
"Cannot dereference twice!");
596 IsEarlyIncremented =
true;
601 using BaseT::operator++;
603#if LLVM_ENABLE_ABI_BREAKING_CHECKS
604 assert(IsEarlyIncremented &&
"Cannot increment before dereferencing!");
605 IsEarlyIncremented =
false;
612#if LLVM_ENABLE_ABI_BREAKING_CHECKS
613 assert(!
LHS.IsEarlyIncremented &&
"Cannot compare after dereferencing!");
615 return (
const BaseT &)
LHS == (
const BaseT &)
RHS;
631template <
typename RangeT>
634 using EarlyIncIteratorT =
641template <
typename R,
typename UnaryPredicate>
642bool all_of(R &&range, UnaryPredicate
P);
644template <
typename R,
typename UnaryPredicate>
645bool any_of(R &&range, UnaryPredicate
P);
647template <
typename T>
bool all_equal(std::initializer_list<T> Values);
658 using type = std::tuple<decltype(*declval<Iters>())...>;
661template <
typename ZipType,
typename ReferenceTupleType,
typename... Iters>
665 std::bidirectional_iterator_tag,
666 typename std::iterator_traits<Iters>::iterator_category...>,
669 typename std::iterator_traits<
670 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
675 ReferenceTupleType *, ReferenceTupleType>;
677template <
typename ZipType,
typename ReferenceTupleType,
typename... Iters>
690 template <
size_t... Ns>
void tup_inc(std::index_sequence<Ns...>) {
694 template <
size_t... Ns>
void tup_dec(std::index_sequence<Ns...>) {
698 template <
size_t... Ns>
700 std::index_sequence<Ns...>)
const {
712 return static_cast<ZipType &
>(*this);
717 "All inner iterators must be at least bidirectional.");
719 return static_cast<ZipType &
>(*this);
728template <
typename... Iters>
730 typename ZipTupleType<Iters...>::type, Iters...> {
739template <
typename... Iters>
741 :
zip_common<zip_shortest<Iters...>, typename ZipTupleType<Iters...>::type,
747 return any_iterator_equals(other, std::index_sequence_for<Iters...>{});
751 template <
size_t... Ns>
753 std::index_sequence<Ns...>)
const {
760template <
template <
typename...>
class ItType,
typename TupleStorageType,
761 typename IndexSequence>
765template <
template <
typename...>
class ItType,
typename... Args,
768 std::index_sequence<Ns...>> {
770 std::get<Ns>(declval<std::tuple<Args...> &>())))...>;
774template <
template <
typename...>
class ItType,
typename... Args,
777 std::index_sequence<Ns...>> {
779 std::get<Ns>(declval<
const std::tuple<Args...> &>())))...>;
782template <
template <
typename...>
class ItType,
typename... Args>
class zippy {
784 std::tuple<Args...> storage;
785 using IndexSequence = std::index_sequence_for<Args...>;
789 IndexSequence>::type;
792 IndexSequence>::type;
808 template <
size_t... Ns>
812 template <
size_t... Ns>
iterator begin_impl(std::index_sequence<Ns...>) {
816 template <
size_t... Ns>
820 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>) {
829template <
typename T,
typename U,
typename...
Args>
833 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
839template <
typename T,
typename U,
typename... Args>
843 "Iteratees do not have equal length");
845 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
852template <
typename T,
typename U,
typename... Args>
856 "First iteratee is not the shortest");
859 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
863template <
typename Iter>
870template <
typename Iter>
872 std::remove_const_t<std::remove_reference_t<
decltype(*I)>>> {
879 using type = std::optional<std::remove_const_t<
880 std::remove_reference_t<decltype(*std::declval<Iter>())>>>;
884 using type = std::tuple<typename ZipLongestItemType<Iters>::type...>;
887template <
typename... Iters>
890 zip_longest_iterator<Iters...>,
892 std::forward_iterator_tag,
893 typename std::iterator_traits<Iters>::iterator_category...>,
894 typename ZipLongestTupleType<Iters...>::type,
895 typename std::iterator_traits<
896 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
897 typename ZipLongestTupleType<Iters...>::type *,
898 typename ZipLongestTupleType<Iters...>::type> {
903 std::tuple<Iters...> iterators;
904 std::tuple<Iters...> end_iterators;
906 template <
size_t... Ns>
908 std::index_sequence<Ns...>)
const {
909 return ((std::get<Ns>(this->iterators) != std::get<Ns>(other.iterators)) ||
913 template <
size_t... Ns> value_type
deref(std::index_sequence<Ns...>)
const {
915 deref_or_none(std::get<Ns>(iterators), std::get<Ns>(end_iterators))...);
918 template <
size_t... Ns>
919 decltype(iterators) tup_inc(std::index_sequence<Ns...>)
const {
920 return std::tuple<Iters...>(
921 next_or_end(std::get<Ns>(iterators), std::get<Ns>(end_iterators))...);
926 : iterators(
std::forward<Iters>(ts.first)...),
927 end_iterators(
std::forward<Iters>(ts.second)...) {}
930 return deref(std::index_sequence_for<Iters...>{});
934 iterators = tup_inc(std::index_sequence_for<Iters...>{});
939 return !
test(other, std::index_sequence_for<Iters...>{});
954 std::tuple<Args...> ts;
956 template <
size_t... Ns>
957 iterator begin_impl(std::index_sequence<Ns...>)
const {
959 adl_end(std::get<Ns>(ts)))...);
962 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>)
const {
964 adl_end(std::get<Ns>(ts)))...);
971 return begin_impl(std::index_sequence_for<Args...>{});
973 iterator end()
const {
return end_impl(std::index_sequence_for<Args...>{}); }
980template <
typename T,
typename U,
typename... Args>
984 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
997template <
typename ValueT,
typename... IterTs>
1000 std::forward_iterator_tag, ValueT> {
1001 using BaseT =
typename concat_iterator::iterator_facade_base;
1003 static constexpr bool ReturnsByValue =
1004 !(std::is_reference_v<decltype(*std::declval<IterTs>())> && ...);
1005 static constexpr bool ReturnsConvertibleType =
1007 std::remove_cv_t<ValueT>,
1009 (std::is_convertible_v<
decltype(*std::declval<IterTs>()), ValueT> && ...);
1013 using reference_type =
1014 std::conditional_t<ReturnsByValue || ReturnsConvertibleType, ValueT,
1023 std::tuple<IterTs...> Begins;
1024 std::tuple<IterTs...> Ends;
1028 template <
size_t Index,
size_t... Others>
void incrementImpl() {
1029 auto &Begin = std::get<Index>(Begins);
1030 auto &End = std::get<Index>(Ends);
1032 if constexpr (
sizeof...(Others) != 0)
1033 return incrementImpl<Others...>();
1042 template <
size_t... Ns>
void increment(std::index_sequence<Ns...>) {
1043 incrementImpl<Ns...>();
1048 template <
size_t Index,
size_t... Others> reference_type getImpl()
const {
1049 auto &Begin = std::get<Index>(Begins);
1050 auto &End = std::get<Index>(Ends);
1052 if constexpr (
sizeof...(Others) != 0)
1053 return getImpl<Others...>();
1055 "Attempted to get a pointer from an end concat iterator!");
1064 template <
size_t... Ns> reference_type get(std::index_sequence<Ns...>)
const {
1065 return getImpl<Ns...>();
1073 template <
typename... RangeTs>
1077 using BaseT::operator++;
1080 increment(std::index_sequence_for<IterTs...>());
1085 return get(std::index_sequence_for<IterTs...>());
1089 return Begins ==
RHS.Begins && Ends ==
RHS.Ends;
1104 decltype(
adl_begin(std::declval<RangeTs &>()))...>;
1107 std::tuple<RangeTs...> Ranges;
1109 template <
size_t... Ns>
iterator begin_impl(std::index_sequence<Ns...>) {
1110 return iterator(std::get<Ns>(Ranges)...);
1112 template <
size_t... Ns>
1113 iterator begin_impl(std::index_sequence<Ns...>)
const {
1114 return iterator(std::get<Ns>(Ranges)...);
1116 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>) {
1118 adl_end(std::get<Ns>(Ranges)))...);
1120 template <
size_t... Ns> iterator end_impl(std::index_sequence<Ns...>)
const {
1122 adl_end(std::get<Ns>(Ranges)))...);
1127 : Ranges(
std::forward<RangeTs>(Ranges)...) {}
1130 return begin_impl(std::index_sequence_for<RangeTs...>{});
1133 return begin_impl(std::index_sequence_for<RangeTs...>{});
1136 return end_impl(std::index_sequence_for<RangeTs...>{});
1139 return end_impl(std::index_sequence_for<RangeTs...>{});
1149template <
typename ValueT,
typename... RangeTs>
1150[[nodiscard]] detail::concat_range<ValueT, RangeTs...>
1152 static_assert(
sizeof...(RangeTs) > 1,
1153 "Need more than one range to concatenate!");
1155 std::forward<RangeTs>(Ranges)...);
1160template <
typename DerivedT,
typename BaseT,
typename T,
1161 typename PointerT =
T *,
typename ReferenceT =
T &>
1164 std::random_access_iterator_tag, T,
1165 std::ptrdiff_t, PointerT, ReferenceT> {
1181 this->
index += offset;
1182 return static_cast<DerivedT &
>(*this);
1185 this->
index -= offset;
1186 return static_cast<DerivedT &
>(*this);
1213template <
typename DerivedT,
typename BaseT,
typename T,
1214 typename PointerT =
T *,
typename ReferenceT =
T &>
1221 PointerT, ReferenceT> {
1225 return DerivedT::dereference_iterator(this->
getBase(), this->
getIndex());
1248 assert(Index <
size() &&
"invalid index for value range");
1249 return DerivedT::dereference_iterator(
base,
static_cast<ptrdiff_t>(Index));
1257 return (*
this)[
size() - 1];
1267 DerivedT
slice(
size_t n,
size_t m)
const {
1268 assert(n + m <=
size() &&
"invalid size specifiers");
1269 return DerivedT(offset_base(
base, n), m);
1274 assert(
size() >= n &&
"Dropping more elements than exist");
1279 assert(
size() >= n &&
"Dropping more elements than exist");
1286 :
static_cast<const DerivedT &
>(*this);
1292 :
static_cast<const DerivedT &
>(*this);
1296 template <
typename RangeT,
typename = std::enable_if_t<std::is_constructible<
1298 operator RangeT()
const {
1307 static BaseT offset_base(
const BaseT &
base,
size_t n) {
1308 return n == 0 ?
base : DerivedT::offset_base(
base, n);
1324template <
typename OtherT,
typename DerivedT,
typename BaseT,
typename T,
1325 typename PointerT,
typename ReferenceT>
1328 const OtherT &rhs) {
1329 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1332template <
typename OtherT,
typename DerivedT,
typename BaseT,
typename T,
1333 typename PointerT,
typename ReferenceT>
1336 const OtherT &rhs) {
1337 return !(lhs == rhs);
1348template <
typename DerivedT,
typename BaseT,
typename T,
1349 typename PointerT =
T *,
typename ReferenceT =
T &>
1352 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT> {
1356 DerivedT,
std::pair<BaseT,
ptrdiff_t>,
T, PointerT, ReferenceT>(
1359 DerivedT, std::pair<BaseT, ptrdiff_t>,
T, PointerT,
1369 static std::pair<BaseT, ptrdiff_t>
1373 return {
base.first,
base.second + index};
1379 return DerivedT::dereference(
base.first,
base.second + index);
1392 using type = std::conditional_t<std::is_reference<EltTy>::value, FirstTy,
1393 std::remove_reference_t<FirstTy>>;
1402 EltTy,
decltype((elt.first))>::type {
1411 std::forward<ContainerTy>(c),
1414 decltype((elt.second))>::type {
1421template <
typename ContainerTy>
1424 using ReferenceTy =
typename std::iterator_traits<IterTy>::reference;
1426 [ShouldReverse](
auto I) -> ReferenceTy {
1427 return ShouldReverse ? std::get<0>(
I) : std::get<1>(
I);
1440 return std::less<>()(std::get<0>(lhs), std::get<0>(rhs));
1449 return std::less<>()(std::get<1>(lhs), std::get<1>(rhs));
1455template<
typename FuncTy>
1459 template <
typename T>
1460 decltype(
auto)
operator()(
const T &lhs,
const T &rhs)
const {
1461 return func(lhs.first, rhs.first);
1473template <
typename HeadT,
typename... TailTs>
1479 using Visitor<TailTs...>::operator();
1517template <
typename... CallableTs>
1519 return detail::Visitor<CallableTs...>(std::forward<CallableTs>(Callables)...);
1528template <
class Iterator,
class RNG>
1532 using difference_type =
1533 typename std::iterator_traits<Iterator>::difference_type;
1534 for (
auto size = last - first;
size > 1; ++first, (void)--
size) {
1535 difference_type offset =
g() %
size;
1538 if (offset != difference_type(0))
1539 std::iter_swap(first, first + offset);
1546 if (std::less<T>()(*
reinterpret_cast<const T*
>(P1),
1547 *
reinterpret_cast<const T*
>(P2)))
1549 if (std::less<T>()(*
reinterpret_cast<const T*
>(P2),
1550 *
reinterpret_cast<const T*
>(P1)))
1559 (
const void*,
const void*) {
1563#ifdef EXPENSIVE_CHECKS
1566inline unsigned presortShuffleEntropy() {
1567 static unsigned Result(std::random_device{}());
1571template <
class IteratorTy>
1572inline void presortShuffle(IteratorTy Start, IteratorTy End) {
1573 std::mt19937 Generator(presortShuffleEntropy());
1594template<
class IteratorTy>
1598 auto NElts = End - Start;
1599 if (NElts <= 1)
return;
1600#ifdef EXPENSIVE_CHECKS
1601 detail::presortShuffle<IteratorTy>(Start, End);
1606template <
class IteratorTy>
1608 IteratorTy Start, IteratorTy End,
1610 const typename std::iterator_traits<IteratorTy>::value_type *,
1611 const typename std::iterator_traits<IteratorTy>::value_type *)) {
1614 auto NElts = End - Start;
1615 if (NElts <= 1)
return;
1616#ifdef EXPENSIVE_CHECKS
1617 detail::presortShuffle<IteratorTy>(Start, End);
1619 qsort(&*Start, NElts,
sizeof(*Start),
1620 reinterpret_cast<int (*)(
const void *,
const void *)
>(Compare));
1624template <
typename T>
1629 std::is_trivially_copyable<typename std::iterator_traits<T>::value_type>>;
1634template <
typename IteratorTy>
1635inline void sort(IteratorTy Start, IteratorTy End) {
1641#ifdef EXPENSIVE_CHECKS
1642 detail::presortShuffle<IteratorTy>(Start, End);
1644 std::sort(Start, End);
1648template <
typename Container>
inline void sort(Container &&
C) {
1652template <
typename IteratorTy,
typename Compare>
1653inline void sort(IteratorTy Start, IteratorTy End, Compare Comp) {
1654#ifdef EXPENSIVE_CHECKS
1655 detail::presortShuffle<IteratorTy>(Start, End);
1657 std::sort(Start, End, Comp);
1660template <
typename Container,
typename Compare>
1661inline void sort(Container &&
C, Compare Comp) {
1667template <
typename R>
1670 std::is_base_of<std::random_access_iterator_tag,
1671 typename std::iterator_traits<
decltype(
1672 Range.begin())>::iterator_category>::value,
1673 void> * =
nullptr) {
1674 return std::distance(
Range.begin(),
Range.end());
1678template <
typename Range>
1680 decltype(
adl_size(std::declval<Range &>()));
1682template <
typename Range>
1703 std::forward<E>(
Init));
1707template <
typename R,
typename E,
typename BinaryOp>
1710 std::forward<E>(
Init), std::forward<BinaryOp>(
Op));
1715template <
typename R,
typename E = detail::ValueOfRange<R>>
1722template <
typename R,
typename E = detail::ValueOfRange<R>>
1725 std::multiplies<>{});
1730template <
typename R,
typename UnaryFunction>
1737template <
typename R,
typename UnaryPredicate>
1744template <
typename R,
typename UnaryPredicate>
1751template <
typename R,
typename UnaryPredicate>
1764template <
typename R,
typename T>
auto find(R &&
Range,
const T &Val) {
1770template <
typename R,
typename UnaryPredicate>
1775template <
typename R,
typename UnaryPredicate>
1782template <
typename R,
typename UnaryPredicate>
1789template <
typename R,
typename OutputIt,
typename UnaryPredicate>
1798template <
typename R1,
typename R2>
auto search(R1 &&Range1,
R2 &&Range2) {
1807template <
typename R1,
typename R2,
typename BinaryPredicate>
1825template <
typename R,
typename BinaryPredicate>
1835template <
typename T,
typename R,
typename Predicate>
1839 if (
T *PRC =
P(
A, AllowRepeats)) {
1841 if (!AllowRepeats || PRC != RC)
1860template <
typename T,
typename R,
typename Predicate>
1862 bool AllowRepeats =
false) {
1865 std::pair<T *, bool> PRC =
P(
A, AllowRepeats);
1867 assert(PRC.first ==
nullptr &&
1868 "Inconsistent return values in find_singleton_nested.");
1873 if (!AllowRepeats || PRC.first != RC)
1874 return {
nullptr,
true};
1883template <
typename R,
typename OutputIt>
1890template <
typename R,
typename OutputIt,
typename UnaryPredicate,
typename T>
1892 const T &NewValue) {
1899template <
typename R,
typename OutputIt,
typename T>
1901 const T &NewValue) {
1908template <
typename R,
typename T>
1915template <
typename R,
typename OutputIt>
1921template <
typename Range,
typename Element>
1923 decltype(std::declval<Range &>().contains(std::declval<const Element &>()));
1925template <
typename Range,
typename Element>
1929template <
typename Range,
typename Element>
1931 decltype(std::declval<Range &>().find(std::declval<const Element &>()) !=
1932 std::declval<Range &>().end());
1934template <
typename Range,
typename Element>
1945template <
typename R,
typename E>
1948 return Range.contains(Element);
1958template <
typename T,
typename E>
1961 for (
const T &V : Set)
1982template <
typename R,
typename Cmp = std::less<>>
1991template <
typename R1,
typename R2>
bool includes(R1 &&Range1,
R2 &&Range2) {
1992 assert(
is_sorted(Range1) &&
"Range1 must be sorted in non-descending order");
1993 assert(
is_sorted(Range2) &&
"Range2 must be sorted in non-descending order");
2001template <
typename R1,
typename R2,
typename Compare>
2006 adl_end(Range2), std::forward<Compare>(
C));
2011template <
typename R,
typename E>
auto count(R &&
Range,
const E &Element) {
2017template <
typename R,
typename UnaryPredicate>
2024template <
typename R,
typename OutputIt,
typename UnaryFunction>
2031template <
typename R,
typename UnaryPredicate>
2040 std::forward<T>(
Value));
2043template <
typename R,
typename T,
typename Compare>
2046 std::forward<T>(
Value),
C);
2053 std::forward<T>(
Value));
2056template <
typename R,
typename T,
typename Compare>
2059 std::forward<T>(
Value),
C);
2066 std::forward<T>(
Value));
2069template <
typename R,
typename T,
typename Compare>
2072 std::forward<T>(
Value),
C);
2104template <
typename R1,
typename R2>
auto mismatch(R1 &&Range1,
R2 &&Range2) {
2109template <
typename R,
typename IterTy>
2114template <
typename R>
2119template <
typename R,
typename Compare>
2126template <
typename R,
typename Predicate,
2127 typename Val =
decltype(*
adl_begin(std::declval<R>()))>
2132template<
typename Range,
typename Predicate>
2145template <
typename L,
typename R>
bool equal(L &&LRange, R &&RRange) {
2150template <
typename L,
typename R,
typename BinaryPredicate>
2151bool equal(L &&LRange, R &&RRange, BinaryPredicate
P) {
2160 return Begin == End || std::equal(std::next(Begin), End, Begin);
2165template <
typename T>
bool all_equal(std::initializer_list<T> Values) {
2190template <
typename Container,
typename UnaryPredicate>
2198template <
typename Container,
typename ValueType>
2200 C.erase(std::remove(
C.begin(),
C.end(), V),
C.end());
2206template <
typename Container,
typename Range>
2212template <
typename Container,
typename... Args>
2214 if (
size_t InitialSize =
range_size(
C); InitialSize == 0) {
2223 C.reserve(InitialSize +
sizeof...(Args));
2226 ((void)
C.insert(
C.end(), std::forward<Args>(Values)), ...);
2231template <
typename Container,
typename RandomAccessIterator>
2232void replace(Container &Cont,
typename Container::iterator ContIt,
2233 typename Container::iterator ContEnd, RandomAccessIterator ValIt,
2234 RandomAccessIterator ValEnd) {
2236 if (ValIt == ValEnd) {
2237 Cont.erase(ContIt, ContEnd);
2240 if (ContIt == ContEnd) {
2241 Cont.insert(ContIt, ValIt, ValEnd);
2252template <
typename Container,
typename Range = std::initializer_list<
2253 typename Container::value_type>>
2254void replace(Container &Cont,
typename Container::iterator ContIt,
2255 typename Container::iterator ContEnd,
Range &&R) {
2269template <
typename ForwardIterator,
typename UnaryFunctor,
2270 typename NullaryFunctor,
2271 typename = std::enable_if_t<
2272 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2273 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2274inline void interleave(ForwardIterator begin, ForwardIterator end,
2275 UnaryFunctor each_fn, NullaryFunctor between_fn) {
2280 for (; begin != end; ++begin) {
2286template <
typename Container,
typename UnaryFunctor,
typename NullaryFunctor,
2287 typename = std::enable_if_t<
2288 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2289 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2291 NullaryFunctor between_fn) {
2296template <
typename Container,
typename UnaryFunctor,
typename StreamT,
2298inline void interleave(
const Container &c, StreamT &os, UnaryFunctor each_fn,
2302template <
typename Container,
typename StreamT,
2307 c, os, [&](
const T &a) { os << a; }, separator);
2310template <
typename Container,
typename UnaryFunctor,
typename StreamT,
2313 UnaryFunctor each_fn) {
2316template <
typename Container,
typename StreamT,
2332template<
typename First,
typename Second>
2335 return std::hash<First>()(
P.first) * 31 + std::hash<Second>()(
P.second);
2350 return func(*lhs, *rhs);
2359template <
typename... Iters>
2373template <
typename... Iters>
2375 EnumeratorTupleType<Iters...>, Iters...> {
2376 static_assert(
sizeof...(Iters) >= 2,
"Expected at least two iteratees");
2381 return std::get<1>(this->
iterators) == std::get<1>(
Other.iterators);
2386 static constexpr std::size_t
NumRefs =
sizeof...(Refs);
2398 : Idx(Index), Storage(
std::forward<Refs>(Rs)...) {}
2402 std::size_t
index()
const {
return Idx; }
2408 return std::get<0>(Storage);
2414 template <std::
size_t I,
typename = std::enable_if_t<I == 0>>
2421 template <std::
size_t I,
typename = std::enable_if_t<I != 0>>
2426 return std::get<
I - 1>(Result.Storage);
2429 template <
typename... Ts>
2431 const std::tuple<std::size_t, Ts...> &
Other) {
2432 static_assert(
NumRefs ==
sizeof...(Ts),
"Size mismatch");
2433 if (Result.Idx != std::get<0>(
Other))
2435 return Result.is_value_equal(
Other, std::make_index_sequence<NumRefs>{});
2439 template <
typename Tuple, std::size_t... Idx>
2440 bool is_value_equal(
const Tuple &
Other, std::index_sequence<Idx...>)
const {
2441 return ((std::get<Idx>(Storage) == std::get<Idx + 1>(
Other)) && ...);
2452 mutable range_reference_tuple Storage;
2457 std::random_access_iterator_tag, std::size_t> {
2471 return Index - R.Index;
2482 return Lhs.Index == Rhs.Index;
2486 return Lhs.Index < Rhs.Index;
2511 index_range(std::size_t Begin, std::size_t End) : Begin(Begin), End(End) {}
2552template <
typename FirstRange,
typename... RestRanges>
2554 if constexpr (
sizeof...(Rest) != 0) {
2563 FirstRange, RestRanges...>;
2565 std::forward<RestRanges>(Rest)...);
2570template <
typename Predicate,
typename... Args>
2573 auto it = z.begin();
2576 if (!std::apply([&](
auto &&...
args) {
return P(
args...); }, *it))
2580 return it.all_equals(end);
2585template <
typename... ArgsThenPredicate,
size_t... InputIndexes>
2587 std::tuple<ArgsThenPredicate...> argsThenPredicate,
2588 std::index_sequence<InputIndexes...>) {
2589 auto constexpr OutputIndex =
2590 std::tuple_size<
decltype(argsThenPredicate)>
::value - 1;
2592 std::get<InputIndexes>(argsThenPredicate)...);
2600template <
typename... ArgsAndPredicate>
2603 std::forward_as_tuple(argsAndPredicate...),
2604 std::make_index_sequence<
sizeof...(argsAndPredicate) - 1>{});
2610template <
typename IterTy,
2611 typename Pred =
bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2613 IterTy &&Begin, IterTy &&End,
unsigned N,
2614 Pred &&ShouldBeCounted =
2615 [](
const decltype(*std::declval<IterTy>()) &) {
return true; },
2617 !std::is_base_of<std::random_access_iterator_tag,
2618 typename std::iterator_traits<std::remove_reference_t<
2619 decltype(Begin)>>::iterator_category>::value,
2620 void> * =
nullptr) {
2621 for (;
N; ++Begin) {
2624 N -= ShouldBeCounted(*Begin);
2626 for (; Begin != End; ++Begin)
2627 if (ShouldBeCounted(*Begin))
2635template <
typename IterTy,
2636 typename Pred = bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2638 IterTy &&Begin, IterTy &&End,
unsigned N,
2639 Pred &&ShouldBeCounted =
2640 [](
const decltype(*std::declval<IterTy>()) &) {
return true; },
2642 !std::is_base_of<std::random_access_iterator_tag,
2643 typename std::iterator_traits<std::remove_reference_t<
2644 decltype(Begin)>>::iterator_category>::value,
2645 void> * =
nullptr) {
2646 for (;
N; ++Begin) {
2649 N -= ShouldBeCounted(*Begin);
2656template <
typename IterTy,
2657 typename Pred = bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2659 IterTy &&Begin, IterTy &&End,
unsigned N,
2660 Pred &&ShouldBeCounted = [](
const decltype(*std::declval<IterTy>()) &) {
2663 assert(
N != std::numeric_limits<unsigned>::max());
2668template <
typename ContainerTy>
bool hasNItems(ContainerTy &&
C,
unsigned N) {
2673template <
typename ContainerTy>
2679template <
typename ContainerTy>
2691template <
typename T>
2696template <
typename T,
typename U>
2698 decltype(std::declval<const T &>() == std::declval<const U &>());
2702template <
typename T,
typename U = T>
2708template <
typename... Refs>
2709struct tuple_size<
llvm::detail::enumerator_result<Refs...>>
2710 : std::integral_constant<std::size_t, sizeof...(Refs)> {};
2712template <std::size_t
I,
typename... Refs>
2713struct tuple_element<
I,
llvm::detail::enumerator_result<Refs...>>
2714 : std::tuple_element<I, std::tuple<Refs...>> {};
2716template <std::size_t
I,
typename... Refs>
2717struct tuple_element<
I,
const llvm::detail::enumerator_result<Refs...>>
2718 : std::tuple_element<I, std::tuple<Refs...>> {};
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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)
Represent a constant reference to a string, i.e.
LLVM Value Representation.
decltype(auto) operator()(Pn &&...Params) const
Templated storage wrapper for a callable.
Callable & operator=(Callable &&Other)
Callable(Callable const &Other)=default
Callable & operator=(Callable const &Other)
Callable(Callable &&Other)=default
Iterator wrapper that concatenates sequences together.
concat_iterator & operator++()
bool operator==(const concat_iterator &RHS) const
reference_type operator*() const
concat_iterator(RangeTs &&...Ranges)
Constructs an iterator from a sequence of ranges.
Helper to store a sequence of ranges being concatenated and access them.
concat_range(RangeTs &&... Ranges)
concat_iterator< ValueT, decltype(adl_begin(std::declval< RangeTs & >()))... > iterator
Return a reference to the first or second member of a reference.
std::conditional_t< std::is_reference< EltTy >::value, FirstTy, std::remove_reference_t< FirstTy > > type
An iterator element of this range.
ReferenceT operator*() const
The class represents the base of a range of indexed_accessor_iterators.
DerivedT slice(size_t n, size_t m) const
Drop the first N elements, and keep M elements.
size_t size() const
Return the size of this range.
bool empty() const
Return if the range is empty.
indexed_accessor_range_base & operator=(const indexed_accessor_range_base &)=default
DerivedT take_front(size_t n=1) const
Take the first n elements.
ReferenceT operator[](size_t Index) const
DerivedT drop_back(size_t n=1) const
Drop the last n elements.
indexed_accessor_range_base RangeBaseT
DerivedT take_back(size_t n=1) const
Take the last n elements.
DerivedT drop_front(size_t n=1) const
Drop the first n elements.
indexed_accessor_range_base(const indexed_accessor_range_base &)=default
indexed_accessor_range_base(BaseT base, ptrdiff_t count)
indexed_accessor_range_base(indexed_accessor_range_base &&)=default
indexed_accessor_range_base(iterator begin, iterator end)
ptrdiff_t count
The size from the owning range.
BaseT base
The base that owns the provided range of values.
indexed_accessor_range_base(const iterator_range< iterator > &range)
const BaseT & getBase() const
Returns the base of this range.
zip_longest_iterator(std::pair< Iters &&, Iters && >... ts)
value_type operator*() const
bool operator==(const zip_longest_iterator< Iters... > &other) const
zip_longest_iterator< Iters... > & operator++()
typename ZipLongestTupleType< Iters... >::type value_type
typename iterator::iterator_category iterator_category
typename iterator::pointer pointer
typename iterator::difference_type difference_type
zip_longest_iterator< decltype(adl_begin(std::declval< Args >()))... > iterator
typename iterator::reference reference
zip_longest_range(Args &&... ts_)
typename iterator::value_type value_type
typename ZippyIteratorTuple< ItType, decltype(storage), IndexSequence >::type iterator
typename iterator::value_type value_type
typename iterator::difference_type difference_type
typename iterator::reference reference
typename iterator::pointer pointer
typename ZippyIteratorTuple< ItType, const decltype(storage), IndexSequence >::type const_iterator
typename const_iterator::reference const_reference
const_iterator begin() const
typename iterator::iterator_category iterator_category
const_iterator end() const
A pseudo-iterator adaptor that is designed to implement "early increment" style loops.
friend bool operator==(const early_inc_iterator_impl &LHS, const early_inc_iterator_impl &RHS)
early_inc_iterator_impl(WrappedIteratorT I)
early_inc_iterator_impl & operator++()
decltype(*std::declval< WrappedIteratorT >()) operator*()
An iterator adaptor that filters the elements of given inner iterators.
filter_iterator_base & operator++()
filter_iterator_base()=default
filter_iterator_base(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
filter_iterator_impl()=default
filter_iterator_impl(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
filter_iterator_impl & operator--()
Specialization of filter_iterator_base for forward iteration only.
filter_iterator_impl(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred)
filter_iterator_impl()=default
index_range(std::size_t Begin, std::size_t End)
detail::index_iterator begin() const
detail::index_iterator end() const
A utility class used to implement an iterator that contains some base object and an index.
DerivedT & operator+=(ptrdiff_t offset)
const BaseT & getBase() const
Returns the current base of the iterator.
bool operator==(const indexed_accessor_iterator &rhs) const
indexed_accessor_iterator(BaseT base, ptrdiff_t index)
DerivedT & operator-=(ptrdiff_t offset)
ptrdiff_t operator-(const indexed_accessor_iterator &rhs) const
bool operator<(const indexed_accessor_iterator &rhs) const
ptrdiff_t getIndex() const
Returns the current index of the iterator.
indexed_accessor_range(BaseT base, ptrdiff_t startIndex, ptrdiff_t count)
const BaseT & getBase() const
Returns the current base of the range.
ptrdiff_t getStartIndex() const
Returns the current start index of the range.
static ReferenceT dereference_iterator(const std::pair< BaseT, ptrdiff_t > &base, ptrdiff_t index)
See detail::indexed_accessor_range_base for details.
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.
iterator_adaptor_base()=default
DifferenceTypeT difference_type
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
IteratorCategoryT 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.
mapped_iterator_base BaseT
mapped_iterator_base(ItTy U)
ReferenceTy operator*() const
mapped_iterator()=default
const FuncTy & getFunction() const
mapped_iterator(ItTy U, FuncTy F)
ReferenceTy operator*() const
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.
decltype(adl_rbegin(std::declval< Range & >())) check_has_free_function_rbegin
auto deref_or_none(const Iter &I, const Iter &End) -> std::optional< std::remove_const_t< std::remove_reference_t< decltype(*I)> > >
enumerator_result< decltype(*declval< Iters >())... > EnumeratorTupleType
decltype(std::declval< const T & >()==std::declval< const U & >()) has_equality_comparison
bool all_of_zip_predicate_first(Predicate &&P, Args &&...args)
const char unit< Period >::value[]
static constexpr bool HasMemberFind
static constexpr bool HasFreeFunctionRBegin
decltype(adl_size(std::declval< Range & >())) check_has_free_function_size
bool operator!=(const DenseSetImpl< ValueT, MapTy, ValueInfoT > &LHS, const DenseSetImpl< ValueT, MapTy, ValueInfoT > &RHS)
Inequality comparison for DenseSet.
static constexpr bool HasMemberContains
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,...
bool all_of_zip_predicate_last(std::tuple< ArgsThenPredicate... > argsThenPredicate, std::index_sequence< InputIndexes... >)
decltype(std::declval< Range & >().contains(std::declval< const Element & >())) check_has_member_contains_t
decltype(adl_begin(std::declval< RangeT & >())) IterOfRange
decltype(sizeof(T)) has_sizeof
decltype(std::declval< Range & >().find(std::declval< const Element & >()) != std::declval< Range & >().end()) check_has_member_find_t
Iter next_or_end(const Iter &I, const Iter &End)
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
static constexpr bool HasFreeFunctionSize
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
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.
detail::zippy< detail::zip_shortest, T, U, Args... > zip(T &&t, U &&u, Args &&...args)
zip iterator for two or more iteratable types.
constexpr auto not_equal_to(T &&Arg)
Functor variant of std::not_equal_to that can be used as a UnaryPredicate in functional algorithms li...
void stable_sort(R &&Range)
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
bool includes(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::includes which take ranges instead of having to pass begin/end explicitly.
auto min_element(R &&Range)
Provide wrappers to std::min_element which take ranges instead of having to pass begin/end explicitly...
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
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.
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.
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...
constexpr bool is_incomplete_v
Detects when type T is incomplete.
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.
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,...
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...
constexpr bool all_types_equal_v
auto accumulate(R &&Range, E &&Init)
Wrapper for std::accumulate.
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
int array_pod_sort_comparator(const void *P1, const void *P2)
Adapt std::less<T> for array_pod_sort.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto adjacent_find(R &&Range)
Provide wrappers to std::adjacent_find which finds the first pair of adjacent elements that are equal...
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
decltype(auto) getSingleElement(ContainerTy &&C)
Asserts that the given container has a single element and returns that element.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
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.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
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...
void shuffle(Iterator first, Iterator last, RNG &&g)
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)
auto unique(Range &&R, Predicate P)
auto binary_search(R &&Range, T &&Value)
Provide wrappers to std::binary_search which take ranges instead of having to pass begin/end explicit...
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
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.
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&...Ranges)
Returns a concatenated range across two or more ranges.
constexpr auto bind_front(FnT &&Fn, BindArgsT &&...BindArgs)
C++20 bind_front.
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.
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
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.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto mismatch(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::mismatch which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
constexpr size_t range_size(R &&Range)
Returns the size of the Range, i.e., the number of elements.
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.
void sort(IteratorTy Start, IteratorTy End)
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.
auto find_if_not(R &&Range, UnaryPredicate P)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
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.
constexpr bool is_sorted_constexpr(R &&Range, Cmp C=Cmp{})
Check if elements in a range R are sorted with respect to a comparator C.
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...
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
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...
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(<member of Range> ,...
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.
T * find_singleton(R &&Range, Predicate P, bool AllowRepeats=false)
Return the single value in Range that satisfies P(<member of Range> *, AllowRepeats)->T * returning n...
auto search(R1 &&Range1, R2 &&Range2)
Provide wrappers to std::search which searches for the first occurrence of Range2 within Range1.
auto reverse_conditionally(ContainerTy &&C, bool ShouldReverse)
Return a range that conditionally reverses C.
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.
@ 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.
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.
constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS)
Helper which adds two underlying types of enumeration type.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
constexpr bool has_equality_comparison_v
Detects when type const T can be compared for equality with const U.
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.
auto product_of(R &&Range, E Init=E{1})
Returns the product of all values in Range with Init initial value.
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...
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...
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...
OutputIt copy(R &&Range, OutputIt Out)
auto partition(R &&Range, UnaryPredicate P)
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly.
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
auto sum_of(R &&Range, E Init=E{0})
Returns the sum of all values in Range with Init initial value.
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.
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...
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...
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
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.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.
void array_pod_sort(IteratorTy Start, IteratorTy End)
array_pod_sort - This sorts an array with the specified start and end extent.
constexpr decltype(auto) makeVisitor(CallableTs &&...Callables)
Returns an opaquely-typed Callable object whose operator() overload set is the sum of the operator() ...
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...
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
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...
bool all_of_zip(ArgsAndPredicate &&...argsAndPredicate)
Compare two zipped ranges using the provided predicate (as last argument).
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.
Determine if all types in Ts are distinct.
Binary functor that adapts to any other binary functor after dereferencing operands.
auto operator()(A &lhs, B &rhs) const
constexpr Visitor(HeadT &&Head, TailTs &&...Tail)
constexpr Visitor(HeadT &&Head)
std::optional< std::remove_const_t< std::remove_reference_t< decltype(*std::declval< Iter >())> > > type
std::tuple< typename ZipLongestItemType< Iters >::type... > type
std::tuple< decltype(*declval< Iters >())... > type
ItType< decltype(adl_begin( std::get< Ns >(declval< const std::tuple< Args... > & >())))... > type
ItType< decltype(adl_begin( std::get< Ns >(declval< std::tuple< Args... > & >())))... > type
Helper to obtain the iterator types for the tuple storage within zippy.
std::tuple< Refs... > range_reference_tuple
decltype(auto) value() const
Returns the value(s) for the current iterator.
static constexpr std::size_t NumValues
friend decltype(auto) get(const enumerator_result &Result)
Returns the value at index I.
static constexpr std::size_t NumRefs
std::tuple< std::size_t, Refs... > value_reference_tuple
friend bool operator==(const enumerator_result &Result, const std::tuple< std::size_t, Ts... > &Other)
std::size_t index() const
Returns the 0-based index of the current position within the original input range(s).
friend std::size_t get(const enumerator_result &Result)
Returns the value at index I. This case covers the index.
enumerator_result(std::size_t Index, Refs &&...Rs)
Tuple-like type for zip_enumerator dereference.
friend bool operator==(const index_iterator &Lhs, const index_iterator &Rhs)
std::ptrdiff_t operator-(const index_iterator &R) const
std::size_t operator*() const
friend bool operator<(const index_iterator &Lhs, const index_iterator &Rhs)
index_iterator & operator-=(std::ptrdiff_t N)
index_iterator & operator+=(std::ptrdiff_t N)
index_iterator(std::size_t Index)
Infinite stream of increasing 0-based size_t indices.
index_iterator begin() const
index_iterator end() const
zip_traits< ZipType, ReferenceTupleType, Iters... > Base
std::index_sequence_for< Iters... > IndexSequence
void tup_inc(std::index_sequence< Ns... >)
zip_common(Iters &&... ts)
bool test_all_equals(const zip_common &other, std::index_sequence< Ns... >) const
std::tuple< Iters... > iterators
value_type operator*() const
typename Base::value_type value_type
bool all_equals(zip_common &other)
Return true if all the iterator are matching other's iterators.
void tup_dec(std::index_sequence< Ns... >)
value_type deref(std::index_sequence< Ns... >) const
Zippy iterator that uses the second iterator for comparisons.
bool operator==(const zip_enumerator &Other) const
bool operator==(const zip_first &other) const
bool operator==(const zip_shortest &other) const
std::tuple_element_t< Index, std::tuple< Args... > > arg_t
The type of an argument to this function.
ReturnType result_t
The result type of this function.
std::tuple_element_t< i, std::tuple< Args... > > arg_t
The type of an argument to this function.
ReturnType result_t
The result type of this function.
This class provides various trait information about a callable object.
Function object to check whether the first component of a container supported by std::get (like std::...
bool operator()(const T &lhs, const T &rhs) const
Function object to check whether the second component of a container supported by std::get (like std:...
bool operator()(const T &lhs, const T &rhs) const
std::add_pointer_t< std::add_const_t< T > > type
std::add_lvalue_reference_t< std::add_const_t< T > > type
Function object to apply a binary function to the first component of a std::pair.
size_t operator()(const std::pair< First, Second > &P) const
Utility type to build an inheritance chain that makes it easy to rank overload candidates.