17#ifndef LLVM_ADT_STLEXTRAS_H
18#define LLVM_ADT_STLEXTRAS_H
26#include "llvm/Config/abi-breaking.h"
34#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>>;
62template <
class,
template <
class...>
class Op,
class... Args>
struct detector {
65template <
template <
class...>
class Op,
class... Args>
78template <
template <
class...>
class Op,
class... Args>
85template <typename T, bool isClass = std::is_class<T>::value>
89template <
typename ClassType,
typename ReturnType,
typename... Args>
92 enum { num_args =
sizeof...(Args) };
98 template <
size_t Index>
99 using arg_t = std::tuple_element_t<
Index, std::tuple<Args...>>;
102template <
typename ClassType,
typename ReturnType,
typename... Args>
106template <
typename ReturnType,
typename... Args>
109 enum { num_args =
sizeof...(Args) };
116 using arg_t = std::tuple_element_t<i, std::tuple<Args...>>;
118template <
typename ReturnType,
typename... Args>
122template <
typename ReturnType,
typename... Args>
128template <
typename T,
typename... Ts>
129using is_one_of = std::disjunction<std::is_same<T, Ts>...>;
133template <
typename T,
typename... Ts>
138template <
typename T,
typename... Us>
140 : std::integral_constant<bool, !is_one_of<T, Us...>::value &&
141 TypesAreDistinct<Us...>::value> {};
154template <
typename... Ts>
156 : std::integral_constant<bool, detail::TypesAreDistinct<Ts...>::value> {};
169template <
typename T,
typename U,
typename... Us>
171 : std::integral_constant<size_t, 1 + FirstIndexOfType<T, Us...>::value> {};
172template <
typename T,
typename... Us>
178template <
size_t I,
typename... Ts>
183template <
typename EnumTy1,
typename EnumTy2,
184 typename UT1 = std::enable_if_t<std::is_enum<EnumTy1>::value,
185 std::underlying_type_t<EnumTy1>>,
186 typename UT2 = std::enable_if_t<std::is_enum<EnumTy2>::value,
187 std::underlying_type_t<EnumTy2>>>
189 return static_cast<UT1
>(
LHS) +
static_cast<UT2
>(
RHS);
196namespace callable_detail {
209 bool = std::is_function_v<std::remove_pointer_t<remove_cvref_t<T>>>>
211 using value_type = std::remove_reference_t<T>;
212 using reference = value_type &;
213 using const_reference = value_type
const &;
215 std::optional<value_type> Obj;
217 static_assert(!std::is_pointer_v<value_type>,
218 "Pointers to non-functions are not callable.");
230 Obj.emplace(*
Other.Obj);
237 Obj.emplace(std::move(*
Other.Obj));
241 template <
typename... Pn,
242 std::enable_if_t<std::is_invocable_v<
T, Pn...>,
int> = 0>
243 decltype(
auto)
operator()(Pn &&...Params) {
244 return (*Obj)(std::forward<Pn>(Params)...);
247 template <
typename... Pn,
248 std::enable_if_t<std::is_invocable_v<
T const, Pn...>,
int> = 0>
249 decltype(
auto)
operator()(Pn &&...Params)
const {
250 return (*Obj)(std::forward<Pn>(Params)...);
253 bool valid()
const {
return Obj != std::nullopt; }
254 bool reset() {
return Obj = std::nullopt; }
256 operator reference() {
return *Obj; }
257 operator const_reference()
const {
return *Obj; }
263 static constexpr bool IsPtr = std::is_pointer_v<remove_cvref_t<T>>;
265 using StorageT = std::conditional_t<IsPtr, T, std::remove_reference_t<T> *>;
266 using CastT = std::conditional_t<IsPtr, T, T &>;
269 StorageT Func =
nullptr;
272 template <
typename In>
static constexpr auto convertIn(In &&
I) {
273 if constexpr (IsPtr) {
292 !std::is_same_v<remove_cvref_t<FnPtrOrRef>,
Callable>,
int
297 template <
typename... Pn,
298 std::enable_if_t<std::is_invocable_v<
T, Pn...>,
int> = 0>
299 decltype(
auto)
operator()(Pn &&...Params)
const {
300 return Func(std::forward<Pn>(Params)...);
303 bool valid()
const {
return Func !=
nullptr; }
306 operator T const &()
const {
307 if constexpr (IsPtr) {
311 static_assert(std::is_reference_v<T>,
312 "Expected a reference to a function.");
323 auto B = std::begin(
C),
E = std::end(
C);
324 return B !=
E && std::next(
B) ==
E;
329template <
typename T>
auto drop_begin(
T &&RangeOrContainer,
size_t N = 1) {
336template <
typename T>
auto drop_end(
T &&RangeOrContainer,
size_t N = 1) {
338 std::prev(
adl_end(RangeOrContainer),
N));
344template <
typename ItTy,
typename FuncTy,
345 typename ReferenceTy =
346 decltype(std::declval<FuncTy>()(*std::declval<ItTy>()))>
349 mapped_iterator<ItTy, FuncTy>, ItTy,
350 typename std::iterator_traits<ItTy>::iterator_category,
351 std::remove_reference_t<ReferenceTy>,
352 typename std::iterator_traits<ItTy>::difference_type,
353 std::remove_reference_t<ReferenceTy> *, ReferenceTy> {
371template <
class ItTy,
class FuncTy>
376template <
class ContainerTy,
class FuncTy>
387template <
typename DerivedT,
typename ItTy,
typename ReferenceTy>
391 typename std::iterator_traits<ItTy>::iterator_category,
392 std::remove_reference_t<ReferenceTy>,
393 typename std::iterator_traits<ItTy>::difference_type,
394 std::remove_reference_t<ReferenceTy> *, ReferenceTy> {
404 return static_cast<const DerivedT &
>(*this).mapElement(*this->I);
413 template <
typename Inner>
414 static yes&
test(Inner *
I,
decltype(
I->rbegin()) * =
nullptr);
417 static no&
test(...);
420 static const bool value =
sizeof(test<Ty>(
nullptr)) ==
sizeof(yes);
424template <
typename Ty>
428template <
typename ContainerTy>
auto reverse(ContainerTy &&
C) {
432 return make_range(std::make_reverse_iterator(std::end(
C)),
433 std::make_reverse_iterator(std::begin(
C)));
452template <
typename WrappedIteratorT,
typename PredicateT,
typename IterTag>
455 filter_iterator_base<WrappedIteratorT, PredicateT, IterTag>,
457 std::common_type_t<IterTag,
458 typename std::iterator_traits<
459 WrappedIteratorT>::iterator_category>> {
467 while (this->I !=
End && !
Pred(*this->I))
483 using BaseT::operator++;
491 decltype(
auto)
operator*()
const {
492 assert(BaseT::wrapped() !=
End &&
"Cannot dereference end iterator!");
493 return BaseT::operator*();
496 decltype(
auto) operator->()
const {
497 assert(BaseT::wrapped() !=
End &&
"Cannot dereference end iterator!");
498 return BaseT::operator->();
504 typename IterTag = std::forward_iterator_tag>
516template <
typename WrappedIteratorT,
typename PredicateT>
518 std::bidirectional_iterator_tag>
520 std::bidirectional_iterator_tag> {
523 void findPrevValid() {
524 while (!this->
Pred(*this->I))
529 using BaseT::operator--;
547 using type = std::forward_iterator_tag;
551 using type = std::bidirectional_iterator_tag;
559 std::bidirectional_iterator_tag,
560 typename std::iterator_traits<IterT>::iterator_category>
::value>
::type;
567template <
typename WrappedIteratorT,
typename PredicateT>
579template <
typename RangeT,
typename PredicateT>
582 using FilterIteratorT =
585 FilterIteratorT(std::begin(std::forward<RangeT>(Range)),
586 std::end(std::forward<RangeT>(Range)), Pred),
587 FilterIteratorT(std::end(std::forward<RangeT>(Range)),
588 std::end(std::forward<RangeT>(Range)), Pred));
608template <
typename WrappedIteratorT>
611 WrappedIteratorT, std::input_iterator_tag> {
614 using PointerT =
typename std::iterator_traits<WrappedIteratorT>::pointer;
617#if LLVM_ENABLE_ABI_BREAKING_CHECKS
618 bool IsEarlyIncremented =
false;
624 using BaseT::operator*;
625 decltype(*std::declval<WrappedIteratorT>())
operator*() {
626#if LLVM_ENABLE_ABI_BREAKING_CHECKS
627 assert(!IsEarlyIncremented &&
"Cannot dereference twice!");
628 IsEarlyIncremented =
true;
633 using BaseT::operator++;
635#if LLVM_ENABLE_ABI_BREAKING_CHECKS
636 assert(IsEarlyIncremented &&
"Cannot increment before dereferencing!");
637 IsEarlyIncremented =
false;
644#if LLVM_ENABLE_ABI_BREAKING_CHECKS
645 assert(!
LHS.IsEarlyIncremented &&
"Cannot compare after dereferencing!");
647 return (
const BaseT &)
LHS == (
const BaseT &)
RHS;
663template <
typename RangeT>
664iterator_range<early_inc_iterator_impl<detail::IterOfRange<RangeT>>>
666 using EarlyIncIteratorT =
668 return make_range(EarlyIncIteratorT(std::begin(std::forward<RangeT>(Range))),
669 EarlyIncIteratorT(std::end(std::forward<RangeT>(Range))));
673template <
typename R,
typename UnaryPredicate>
674bool all_of(R &&range, UnaryPredicate
P);
676template <
typename R,
typename UnaryPredicate>
677bool any_of(R &&range, UnaryPredicate
P);
679template <
typename T>
bool all_equal(std::initializer_list<T> Values);
681template <
typename R>
constexpr size_t range_size(R &&Range);
690 using type = std::tuple<decltype(*declval<Iters>())...>;
693template <
typename ZipType,
typename ReferenceTupleType,
typename... Iters>
697 std::bidirectional_iterator_tag,
698 typename std::iterator_traits<Iters>::iterator_category...>,
701 typename std::iterator_traits<
702 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
707 ReferenceTupleType *, ReferenceTupleType>;
709template <
typename ZipType,
typename ReferenceTupleType,
typename... Iters>
722 template <
size_t... Ns>
void tup_inc(std::index_sequence<Ns...>) {
726 template <
size_t... Ns>
void tup_dec(std::index_sequence<Ns...>) {
730 template <
size_t... Ns>
732 std::index_sequence<Ns...>)
const {
744 return static_cast<ZipType &
>(*this);
749 "All inner iterators must be at least bidirectional.");
751 return static_cast<ZipType &
>(*this);
760template <
typename... Iters>
762 typename ZipTupleType<Iters...>::type, Iters...> {
764 Iters...>::zip_common;
771template <
typename... Iters>
773 :
zip_common<zip_shortest<Iters...>, typename ZipTupleType<Iters...>::type,
776 Iters...>::zip_common;
779 return any_iterator_equals(other, std::index_sequence_for<Iters...>{});
783 template <
size_t... Ns>
785 std::index_sequence<Ns...>)
const {
792template <
template <
typename...>
class ItType,
typename TupleStorageType,
793 typename IndexSequence>
797template <
template <
typename...>
class ItType,
typename... Args,
800 std::index_sequence<Ns...>> {
802 std::get<Ns>(declval<std::tuple<Args...> &>())))...>;
806template <
template <
typename...>
class ItType,
typename... Args,
809 std::index_sequence<Ns...>> {
811 std::get<Ns>(declval<
const std::tuple<Args...> &>())))...>;
814template <
template <
typename...>
class ItType,
typename... Args>
class zippy {
816 std::tuple<Args...> storage;
817 using IndexSequence = std::index_sequence_for<Args...>;
821 IndexSequence>::type;
824 IndexSequence>::type;
840 template <
size_t... Ns>
844 template <
size_t... Ns>
iterator begin_impl(std::index_sequence<Ns...>) {
848 template <
size_t... Ns>
852 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>) {
861template <
typename T,
typename U,
typename...
Args>
865 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
871template <
typename T,
typename U,
typename... Args>
875 "Iteratees do not have equal length");
877 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
884template <
typename T,
typename U,
typename... Args>
888 "First iteratee is not the shortest");
891 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
895template <
typename Iter>
902template <
typename Iter>
904 std::remove_const_t<std::remove_reference_t<
decltype(*I)>>> {
911 using type = std::optional<std::remove_const_t<
912 std::remove_reference_t<decltype(*std::declval<Iter>())>>>;
916 using type = std::tuple<typename ZipLongestItemType<Iters>::type...>;
919template <
typename... Iters>
922 zip_longest_iterator<Iters...>,
924 std::forward_iterator_tag,
925 typename std::iterator_traits<Iters>::iterator_category...>,
926 typename ZipLongestTupleType<Iters...>::type,
927 typename std::iterator_traits<
928 std::tuple_element_t<0, std::tuple<Iters...>>>::difference_type,
929 typename ZipLongestTupleType<Iters...>::type *,
930 typename ZipLongestTupleType<Iters...>::type> {
935 std::tuple<Iters...> iterators;
936 std::tuple<Iters...> end_iterators;
938 template <
size_t... Ns>
940 std::index_sequence<Ns...>)
const {
941 return ((std::get<Ns>(this->iterators) != std::get<Ns>(other.iterators)) ||
945 template <
size_t... Ns>
value_type deref(std::index_sequence<Ns...>)
const {
947 deref_or_none(std::get<Ns>(iterators), std::get<Ns>(end_iterators))...);
950 template <
size_t... Ns>
951 decltype(iterators) tup_inc(std::index_sequence<Ns...>)
const {
952 return std::tuple<Iters...>(
953 next_or_end(std::get<Ns>(iterators), std::get<Ns>(end_iterators))...);
958 : iterators(
std::forward<Iters>(ts.first)...),
959 end_iterators(
std::forward<Iters>(ts.second)...) {}
962 return deref(std::index_sequence_for<Iters...>{});
966 iterators = tup_inc(std::index_sequence_for<Iters...>{});
971 return !
test(other, std::index_sequence_for<Iters...>{});
986 std::tuple<Args...> ts;
988 template <
size_t... Ns>
989 iterator begin_impl(std::index_sequence<Ns...>)
const {
991 adl_end(std::get<Ns>(ts)))...);
994 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>)
const {
996 adl_end(std::get<Ns>(ts)))...);
1003 return begin_impl(std::index_sequence_for<Args...>{});
1005 iterator end()
const {
return end_impl(std::index_sequence_for<Args...>{}); }
1012template <
typename T,
typename U,
typename... Args>
1016 std::forward<T>(t), std::forward<U>(u), std::forward<Args>(
args)...);
1029template <
typename ValueT,
typename... IterTs>
1032 std::forward_iterator_tag, ValueT> {
1033 using BaseT =
typename concat_iterator::iterator_facade_base;
1041 std::tuple<IterTs...> Begins;
1042 std::tuple<IterTs...> Ends;
1048 template <
size_t Index>
bool incrementHelper() {
1049 auto &Begin = std::get<Index>(Begins);
1050 auto &
End = std::get<Index>(Ends);
1061 template <
size_t... Ns>
void increment(std::index_sequence<Ns...>) {
1064 &concat_iterator::incrementHelper<Ns>...};
1067 for (
auto &IncrementHelperFn : IncrementHelperFns)
1068 if ((this->*IncrementHelperFn)())
1077 template <
size_t Index>
ValueT *getHelper()
const {
1078 auto &Begin = std::get<Index>(Begins);
1079 auto &
End = std::get<Index>(Ends);
1090 template <
size_t... Ns>
ValueT &get(std::index_sequence<Ns...>)
const {
1093 &concat_iterator::getHelper<Ns>...};
1096 for (
auto &GetHelperFn : GetHelperFns)
1097 if (
ValueT *
P = (this->*GetHelperFn)())
1100 llvm_unreachable(
"Attempted to get a pointer from an end concat iterator!");
1108 template <
typename... RangeTs>
1110 : Begins(
std::begin(Ranges)...), Ends(
std::end(Ranges)...) {}
1112 using BaseT::operator++;
1115 increment(std::index_sequence_for<IterTs...>());
1120 return get(std::index_sequence_for<IterTs...>());
1124 return Begins ==
RHS.Begins && Ends ==
RHS.Ends;
1139 decltype(std::begin(std::declval<RangeTs &>()))...>;
1142 std::tuple<RangeTs...> Ranges;
1144 template <
size_t... Ns>
1145 iterator begin_impl(std::index_sequence<Ns...>) {
1146 return iterator(std::get<Ns>(Ranges)...);
1148 template <
size_t... Ns>
1149 iterator begin_impl(std::index_sequence<Ns...>)
const {
1150 return iterator(std::get<Ns>(Ranges)...);
1152 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>) {
1154 std::end(std::get<Ns>(Ranges)))...);
1156 template <
size_t... Ns>
iterator end_impl(std::index_sequence<Ns...>)
const {
1158 std::end(std::get<Ns>(Ranges)))...);
1163 : Ranges(
std::forward<RangeTs>(Ranges)...) {}
1166 return begin_impl(std::index_sequence_for<RangeTs...>{});
1169 return begin_impl(std::index_sequence_for<RangeTs...>{});
1172 return end_impl(std::index_sequence_for<RangeTs...>{});
1175 return end_impl(std::index_sequence_for<RangeTs...>{});
1184template <
typename ValueT,
typename... RangeTs>
1186 static_assert(
sizeof...(RangeTs) > 1,
1187 "Need more than one range to concatenate!");
1189 std::forward<RangeTs>(Ranges)...);
1194template <
typename DerivedT,
typename BaseT,
typename T,
1195 typename PointerT =
T *,
typename ReferenceT =
T &>
1198 std::random_access_iterator_tag, T,
1199 std::ptrdiff_t, PointerT, ReferenceT> {
1214 this->
index += offset;
1215 return static_cast<DerivedT &
>(*this);
1218 this->
index -= offset;
1219 return static_cast<DerivedT &
>(*this);
1246template <
typename DerivedT,
typename BaseT,
typename T,
1247 typename PointerT =
T *,
typename ReferenceT =
T &>
1254 PointerT, ReferenceT> {
1258 return DerivedT::dereference_iterator(this->
getBase(), this->
getIndex());
1290 return (*
this)[
size() - 1];
1294 template <
typename OtherT>
1296 const OtherT &rhs) {
1297 return std::equal(lhs.
begin(), lhs.
end(), rhs.begin(), rhs.end());
1299 template <
typename OtherT>
1301 const OtherT &rhs) {
1302 return !(lhs == rhs);
1312 DerivedT
slice(
size_t n,
size_t m)
const {
1313 assert(n + m <=
size() &&
"invalid size specifiers");
1314 return DerivedT(offset_base(
base, n), m);
1319 assert(
size() >= n &&
"Dropping more elements than exist");
1324 assert(
size() >= n &&
"Dropping more elements than exist");
1331 :
static_cast<const DerivedT &
>(*this);
1337 :
static_cast<const DerivedT &
>(*this);
1341 template <
typename RangeT,
typename = std::enable_if_t<std::is_constructible<
1343 operator RangeT()
const {
1352 static BaseT offset_base(
const BaseT &
base,
size_t n) {
1353 return n == 0 ?
base : DerivedT::offset_base(
base, n);
1376template <
typename DerivedT,
typename BaseT,
typename T,
1377 typename PointerT =
T *,
typename ReferenceT =
T &>
1380 DerivedT, std::pair<BaseT, ptrdiff_t>, T, PointerT, ReferenceT> {
1384 DerivedT,
std::pair<BaseT,
ptrdiff_t>,
T, PointerT, ReferenceT>(
1387 DerivedT, std::pair<BaseT, ptrdiff_t>,
T, PointerT,
1397 static std::pair<BaseT, ptrdiff_t>
1401 return std::make_pair(
base.first,
base.second + index);
1407 return DerivedT::dereference(
base.first,
base.second + index);
1420 using type = std::conditional_t<std::is_reference<EltTy>::value, FirstTy,
1421 std::remove_reference_t<FirstTy>>;
1427 using EltTy =
decltype((*std::begin(c)));
1430 EltTy,
decltype((elt.first))>::type {
1437 using EltTy =
decltype((*std::begin(c)));
1439 std::forward<ContainerTy>(c),
1442 decltype((elt.second))>::type {
1456 return std::less<>()(std::get<0>(lhs), std::get<0>(rhs));
1465 return std::less<>()(std::get<1>(lhs), std::get<1>(rhs));
1471template<
typename FuncTy>
1475 template <
typename T>
1476 decltype(
auto)
operator()(
const T &lhs,
const T &rhs)
const {
1477 return func(lhs.first, rhs.first);
1489template <
typename HeadT,
typename... TailTs>
1495 using Visitor<TailTs...>::operator();
1533template <
typename... CallableTs>
1535 return detail::Visitor<CallableTs...>(std::forward<CallableTs>(Callables)...);
1544template <
class Iterator,
class RNG>
1549 typename std::iterator_traits<Iterator>::difference_type difference_type;
1550 for (
auto size = last - first;
size > 1; ++first, (void)--
size) {
1551 difference_type offset =
g() %
size;
1554 if (offset != difference_type(0))
1555 std::iter_swap(first, first + offset);
1562 if (std::less<T>()(*
reinterpret_cast<const T*
>(P1),
1563 *
reinterpret_cast<const T*
>(P2)))
1565 if (std::less<T>()(*
reinterpret_cast<const T*
>(P2),
1566 *
reinterpret_cast<const T*
>(P1)))
1575 (
const void*,
const void*) {
1576 return array_pod_sort_comparator<T>;
1579#ifdef EXPENSIVE_CHECKS
1582inline unsigned presortShuffleEntropy() {
1583 static unsigned Result(std::random_device{}());
1587template <
class IteratorTy>
1588inline void presortShuffle(IteratorTy Start, IteratorTy
End) {
1589 std::mt19937 Generator(presortShuffleEntropy());
1610template<
class IteratorTy>
1614 auto NElts =
End - Start;
1615 if (NElts <= 1)
return;
1616#ifdef EXPENSIVE_CHECKS
1617 detail::presortShuffle<IteratorTy>(Start,
End);
1622template <
class IteratorTy>
1624 IteratorTy Start, IteratorTy
End,
1626 const typename std::iterator_traits<IteratorTy>::value_type *,
1627 const typename std::iterator_traits<IteratorTy>::value_type *)) {
1630 auto NElts =
End - Start;
1631 if (NElts <= 1)
return;
1632#ifdef EXPENSIVE_CHECKS
1633 detail::presortShuffle<IteratorTy>(Start,
End);
1635 qsort(&*Start, NElts,
sizeof(*Start),
1636 reinterpret_cast<int (*)(
const void *,
const void *)
>(Compare));
1640template <
typename T>
1645 std::is_trivially_copyable<typename std::iterator_traits<T>::value_type>>;
1650template <
typename IteratorTy>
1651inline void sort(IteratorTy Start, IteratorTy
End) {
1657#ifdef EXPENSIVE_CHECKS
1658 detail::presortShuffle<IteratorTy>(Start,
End);
1660 std::sort(Start,
End);
1664template <
typename Container>
inline void sort(Container &&
C) {
1668template <
typename IteratorTy,
typename Compare>
1669inline void sort(IteratorTy Start, IteratorTy
End, Compare Comp) {
1670#ifdef EXPENSIVE_CHECKS
1671 detail::presortShuffle<IteratorTy>(Start,
End);
1673 std::sort(Start,
End, Comp);
1676template <
typename Container,
typename Compare>
1677inline void sort(Container &&
C, Compare Comp) {
1683template <
typename R>
1686 std::is_base_of<std::random_access_iterator_tag,
1687 typename std::iterator_traits<
decltype(
1688 Range.begin())>::iterator_category>
::value,
1689 void> * =
nullptr) {
1690 return std::distance(Range.begin(), Range.end());
1694template <
typename Range>
1696 decltype(
adl_size(std::declval<Range &>()));
1698template <
typename Range>
1710 if constexpr (detail::HasFreeFunctionSize<R>)
1713 return static_cast<size_t>(std::distance(
adl_begin(Range),
adl_end(Range)));
1718template <
typename R,
typename UnaryFunction>
1725template <
typename R,
typename UnaryPredicate>
1732template <
typename R,
typename UnaryPredicate>
1739template <
typename R,
typename UnaryPredicate>
1746template <
typename R,
typename T>
auto find(R &&Range,
const T &Val) {
1752template <
typename R,
typename UnaryPredicate>
1757template <
typename R,
typename UnaryPredicate>
1764template <
typename R,
typename UnaryPredicate>
1771template <
typename R,
typename OutputIt,
typename UnaryPredicate>
1772OutputIt
copy_if(R &&Range, OutputIt Out, UnaryPredicate
P) {
1781template <
typename T,
typename R,
typename Predicate>
1784 for (
auto &&
A : Range) {
1785 if (
T *PRC =
P(
A, AllowRepeats)) {
1787 if (!AllowRepeats || PRC != RC)
1805template <
typename T,
typename R,
typename Predicate>
1807 bool AllowRepeats =
false) {
1809 for (
auto *
A : Range) {
1810 std::pair<T *, bool> PRC =
P(
A, AllowRepeats);
1812 assert(PRC.first ==
nullptr &&
1813 "Inconsistent return values in find_singleton_nested.");
1818 if (!AllowRepeats || PRC.first != RC)
1819 return {
nullptr,
true};
1827template <
typename R,
typename OutputIt>
1828OutputIt
copy(R &&Range, OutputIt Out) {
1834template <
typename R,
typename OutputIt,
typename UnaryPredicate,
typename T>
1836 const T &NewValue) {
1843template <
typename R,
typename OutputIt,
typename T>
1845 const T &NewValue) {
1852template <
typename R,
typename OutputIt>
1853OutputIt
move(R &&Range, OutputIt Out) {
1858template <
typename Range,
typename Element>
1860 decltype(std::declval<Range &>().contains(std::declval<const Element &>()));
1862template <
typename Range,
typename Element>
1866template <
typename Range,
typename Element>
1868 decltype(std::declval<Range &>().find(std::declval<const Element &>()) !=
1869 std::declval<Range &>().end());
1871template <
typename Range,
typename Element>
1882template <
typename R,
typename E>
1884 if constexpr (detail::HasMemberContains<R, E>)
1885 return Range.contains(Element);
1886 else if constexpr (detail::HasMemberFind<R, E>)
1887 return Range.find(Element) != Range.end();
1895template <
typename T,
typename E>
1898 for (
const T &V : Set)
1906template <
typename R,
typename Compare>
bool is_sorted(R &&Range, Compare
C) {
1918template <
typename R,
typename E>
auto count(R &&Range,
const E &Element) {
1924template <
typename R,
typename UnaryPredicate>
1931template <
typename R,
typename OutputIt,
typename UnaryFunction>
1932OutputIt
transform(R &&Range, OutputIt d_first, UnaryFunction
F) {
1938template <
typename R,
typename UnaryPredicate>
1947 std::forward<T>(
Value));
1950template <
typename R,
typename T,
typename Compare>
1953 std::forward<T>(
Value),
C);
1960 std::forward<T>(
Value));
1963template <
typename R,
typename T,
typename Compare>
1966 std::forward<T>(
Value),
C);
1969template <
typename R>
1974template <
typename R,
typename Compare>
1981template <
typename R,
typename Predicate,
1982 typename Val =
decltype(*
adl_begin(std::declval<R>()))>
1987template<
typename Range,
typename Predicate>
1994template <
typename L,
typename R>
bool equal(L &&LRange, R &&RRange) {
2003 return Begin ==
End || std::equal(Begin + 1,
End, Begin);
2008template <
typename T>
bool all_equal(std::initializer_list<T> Values) {
2009 return all_equal<std::initializer_list<T>>(std::move(Values));
2019template <
typename Container,
typename UnaryPredicate>
2027template <
typename Container,
typename ValueType>
2029 C.erase(std::remove(
C.begin(),
C.end(), V),
C.end());
2032template <
typename Container,
typename ValueType>
2041template <
typename Container,
typename Range>
2047template <
typename Container,
typename... Args>
2051 ((void)
C.insert(
C.end(), std::forward<Args>(Values)), ...);
2056template<
typename Container,
typename RandomAccessIterator>
2057void replace(Container &Cont,
typename Container::iterator ContIt,
2058 typename Container::iterator ContEnd, RandomAccessIterator ValIt,
2059 RandomAccessIterator ValEnd) {
2061 if (ValIt == ValEnd) {
2062 Cont.erase(ContIt, ContEnd);
2064 }
else if (ContIt == ContEnd) {
2065 Cont.insert(ContIt, ValIt, ValEnd);
2068 *ContIt++ = *ValIt++;
2074template<
typename Container,
typename Range = std::initializer_list<
2075 typename Container::value_type>>
2076void replace(Container &Cont,
typename Container::iterator ContIt,
2077 typename Container::iterator ContEnd, Range R) {
2078 replace(Cont, ContIt, ContEnd, R.begin(), R.end());
2091template <
typename ForwardIterator,
typename UnaryFunctor,
2092 typename NullaryFunctor,
2093 typename = std::enable_if_t<
2094 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2095 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2096inline void interleave(ForwardIterator begin, ForwardIterator end,
2097 UnaryFunctor each_fn, NullaryFunctor between_fn) {
2102 for (; begin != end; ++begin) {
2108template <
typename Container,
typename UnaryFunctor,
typename NullaryFunctor,
2109 typename = std::enable_if_t<
2110 !std::is_constructible<StringRef, UnaryFunctor>::value &&
2111 !std::is_constructible<StringRef, NullaryFunctor>::value>>
2113 NullaryFunctor between_fn) {
2114 interleave(c.begin(), c.end(), each_fn, between_fn);
2118template <
typename Container,
typename UnaryFunctor,
typename StreamT,
2119 typename T = detail::ValueOfRange<Container>>
2120inline void interleave(
const Container &c, StreamT &os, UnaryFunctor each_fn,
2122 interleave(c.begin(), c.end(), each_fn, [&] { os << separator; });
2124template <
typename Container,
typename StreamT,
2125 typename T = detail::ValueOfRange<Container>>
2129 c, os, [&](
const T &a) { os << a; }, separator);
2132template <
typename Container,
typename UnaryFunctor,
typename StreamT,
2133 typename T = detail::ValueOfRange<Container>>
2135 UnaryFunctor each_fn) {
2138template <
typename Container,
typename StreamT,
2139 typename T = detail::ValueOfRange<Container>>
2154template<
typename First,
typename Second>
2157 return std::hash<First>()(
P.first) * 31 + std::hash<Second>()(
P.second);
2172 return func(*lhs, *rhs);
2181template <
typename... Iters>
2195template <
typename... Iters>
2197 EnumeratorTupleType<Iters...>, Iters...> {
2198 static_assert(
sizeof...(Iters) >= 2,
"Expected at least two iteratees");
2200 Iters...>::zip_common;
2203 return std::get<1>(this->
iterators) == std::get<1>(
Other.iterators);
2208 static constexpr std::size_t NumRefs =
sizeof...(Refs);
2209 static_assert(NumRefs != 0);
2211 static constexpr std::size_t NumValues = NumRefs + 1;
2220 :
Idx(
Index), Storage(
std::forward<Refs>(Rs)...) {}
2229 if constexpr (NumRefs == 1)
2230 return std::get<0>(Storage);
2236 template <std::
size_t I,
typename = std::enable_if_t<I == 0>>
2243 template <std::
size_t I,
typename = std::enable_if_t<I != 0>>
2248 return std::get<
I - 1>(Result.Storage);
2251 template <
typename... Ts>
2253 const std::tuple<std::size_t, Ts...> &
Other) {
2254 static_assert(NumRefs ==
sizeof...(Ts),
"Size mismatch");
2255 if (Result.Idx != std::get<0>(
Other))
2257 return Result.is_value_equal(
Other, std::make_index_sequence<NumRefs>{});
2261 template <
typename Tuple, std::size_t...
Idx>
2262 bool is_value_equal(
const Tuple &
Other, std::index_sequence<Idx...>)
const {
2263 return ((std::get<Idx>(Storage) == std::get<Idx + 1>(
Other)) && ...);
2274 mutable range_reference_tuple Storage;
2279 std::random_access_iterator_tag, std::size_t> {
2293 return Index - R.Index;
2304 return Lhs.Index == Rhs.Index;
2308 return Lhs.Index < Rhs.Index;
2374template <
typename FirstRange,
typename... RestRanges>
2376 if constexpr (
sizeof...(Rest) != 0) {
2385 FirstRange, RestRanges...>;
2387 std::forward<RestRanges>(Rest)...);
2392template <
typename Predicate,
typename... Args>
2395 auto it = z.begin();
2398 if (!std::apply([&](
auto &&...
args) {
return P(
args...); }, *it))
2402 return it.all_equals(end);
2407template <
typename... ArgsThenPredicate,
size_t... InputIndexes>
2409 std::tuple<ArgsThenPredicate...> argsThenPredicate,
2410 std::index_sequence<InputIndexes...>) {
2411 auto constexpr OutputIndex =
2412 std::tuple_size<
decltype(argsThenPredicate)>
::value - 1;
2414 std::get<InputIndexes>(argsThenPredicate)...);
2422template <
typename... ArgsAndPredicate>
2425 std::forward_as_tuple(argsAndPredicate...),
2426 std::make_index_sequence<
sizeof...(argsAndPredicate) - 1>{});
2432template <
typename IterTy,
2433 typename Pred =
bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2435 IterTy &&Begin, IterTy &&
End,
unsigned N,
2436 Pred &&ShouldBeCounted =
2437 [](
const decltype(*std::declval<IterTy>()) &) {
return true; },
2439 !std::is_base_of<std::random_access_iterator_tag,
2440 typename std::iterator_traits<std::remove_reference_t<
2441 decltype(Begin)>>::iterator_category>
::value,
2442 void> * =
nullptr) {
2443 for (;
N; ++Begin) {
2446 N -= ShouldBeCounted(*Begin);
2448 for (; Begin !=
End; ++Begin)
2449 if (ShouldBeCounted(*Begin))
2457template <
typename IterTy,
2458 typename Pred =
bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2460 IterTy &&Begin, IterTy &&
End,
unsigned N,
2461 Pred &&ShouldBeCounted =
2462 [](
const decltype(*std::declval<IterTy>()) &) {
return true; },
2464 !std::is_base_of<std::random_access_iterator_tag,
2465 typename std::iterator_traits<std::remove_reference_t<
2466 decltype(Begin)>>::iterator_category>
::value,
2467 void> * =
nullptr) {
2468 for (;
N; ++Begin) {
2471 N -= ShouldBeCounted(*Begin);
2478template <
typename IterTy,
2479 typename Pred =
bool (*)(
const decltype(*std::declval<IterTy>()) &)>
2481 IterTy &&Begin, IterTy &&
End,
unsigned N,
2482 Pred &&ShouldBeCounted = [](
const decltype(*std::declval<IterTy>()) &) {
2485 assert(
N != std::numeric_limits<unsigned>::max());
2490template <
typename ContainerTy>
bool hasNItems(ContainerTy &&
C,
unsigned N) {
2495template <
typename ContainerTy>
2501template <
typename ContainerTy>
2523template <
typename T>
2529template <
typename... Refs>
2530struct tuple_size<
llvm::detail::enumerator_result<Refs...>>
2531 : std::integral_constant<std::size_t, sizeof...(Refs)> {};
2533template <std::size_t
I,
typename... Refs>
2534struct tuple_element<
I,
llvm::detail::enumerator_result<Refs...>>
2535 : std::tuple_element<I, std::tuple<Refs...>> {};
2537template <std::size_t
I,
typename... Refs>
2538struct tuple_element<
I,
const llvm::detail::enumerator_result<Refs...>>
2539 : std::tuple_element<I, std::tuple<Refs...>> {};
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DEPRECATED(MSG, FIX)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live value
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
This class represents an Operation in the Expression.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
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
ValueT & 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(std::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.
friend bool operator==(const indexed_accessor_range_base &lhs, const OtherT &rhs)
Compare this range with another.
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
friend bool operator!=(const indexed_accessor_range_base &lhs, const OtherT &rhs)
DerivedT drop_back(size_t n=1) const
Drop the last n elements.
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
zip_longest_iterator< decltype(adl_begin(std::declval< Args >()))... > iterator
typename iterator::difference_type difference_type
typename iterator::reference reference
zip_longest_range(Args &&... ts_)
typename iterator::value_type value_type
typename iterator::value_type value_type
typename iterator::difference_type difference_type
typename iterator::reference reference
typename iterator::pointer pointer
typename const_iterator::reference const_reference
typename ZippyIteratorTuple< ItType, decltype(storage), IndexSequence >::type iterator
typename ZippyIteratorTuple< ItType, const decltype(storage), IndexSequence >::type const_iterator
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++()
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
Helper to determine if type T has a member called rbegin().
Increasing range of size_t indices.
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.
This class provides an implementation of a range of indexed_accessor_iterators where the base is not ...
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.
CRTP base class for adapting an iterator to a different type.
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.
A base type of mapped iterator, that is useful for building derived iterators that do not need/want t...
mapped_iterator_base(ItTy U)
ReferenceTy operator*() const
mapped_iterator()=default
const FuncTy & getFunction() const
mapped_iterator(ItTy U, FuncTy F)
ReferenceTy operator*() const
friend const_iterator end(StringRef path)
Get end iterator over path.
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.
auto deref_or_none(const Iter &I, const Iter &End) -> std::optional< std::remove_const_t< std::remove_reference_t< decltype(*I)> > >
decltype(std::declval< Range & >().contains(std::declval< const Element & >())) check_has_member_contains_t
decltype(std::declval< Range & >().find(std::declval< const Element & >()) !=std::declval< Range & >().end()) check_has_member_find_t
bool all_of_zip_predicate_first(Predicate &&P, Args &&...args)
static constexpr bool HasMemberFind
std::conjunction< std::is_pointer< T >, std::is_trivially_copyable< typename std::iterator_traits< T >::value_type > > sort_trivially_copyable
static constexpr bool HasMemberContains
decltype(sizeof(T)) has_sizeof
bool all_of_zip_predicate_last(std::tuple< ArgsThenPredicate... > argsThenPredicate, std::index_sequence< InputIndexes... >)
Iter next_or_end(const Iter &I, const Iter &End)
static constexpr bool HasFreeFunctionSize
decltype(adl_size(std::declval< Range & >())) check_has_free_function_size
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.
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.
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...
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 are tuples (A,...
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...
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.
mapped_iterator< ItTy, FuncTy > map_iterator(ItTy I, FuncTy F)
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 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.
auto map_range(ContainerTy &&C, FuncTy F)
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
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 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)...
detail::concat_range< ValueT, RangeTs... > concat(RangeTs &&... Ranges)
Concatenated range across two or more ranges.
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> *,...
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 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.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
void erase_value(Container &C, ValueType V)
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
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...
auto to_address(const Ptr &P)
Returns a raw pointer that represents the same address as the argument.
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.
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.
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
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...
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
std::tuple_element_t< I, std::tuple< Ts... > > TypeAtIndex
Find the type at a given index in a list of types.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
void replace(Container &Cont, typename Container::iterator ContIt, typename Container::iterator ContEnd, RandomAccessIterator ValIt, RandomAccessIterator ValEnd)
Given a sequence container Cont, replace the range [ContIt, ContEnd) with the range [ValIt,...
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.
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() ...
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
bool all_of_zip(ArgsAndPredicate &&...argsAndPredicate)
Compare two zipped ranges using the provided predicate (as last argument).
constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS)
Helper which adds two underlying types of enumeration type.
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.
friend decltype(auto) get(const enumerator_result &Result)
Returns the value at index I.
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.
std::bidirectional_iterator_tag type
std::forward_iterator_tag type
Helper which sets its type member to forward_iterator_tag if the category of IterT does not derive fr...
typename fwd_or_bidi_tag_impl< std::is_base_of< std::bidirectional_iterator_tag, typename std::iterator_traits< IterT >::iterator_category >::value >::type type
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
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.
Metafunction to determine if T& or T has a member called rbegin().
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.