From 1d5ae1026e831016fc29fd927877c86af904481f Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 23 Oct 2019 17:51:42 +0000 Subject: Vendor import of stripped llvm trunk r375505, the last commit before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/llvm/trunk@375505 --- include/llvm/ADT/STLExtras.h | 168 ++++++++++++------------------------------- 1 file changed, 46 insertions(+), 122 deletions(-) (limited to 'include/llvm/ADT/STLExtras.h') diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 81dce0168c79..274933bc5204 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -95,18 +95,6 @@ template struct identity { } }; -template struct less_ptr { - bool operator()(const Ty* left, const Ty* right) const { - return *left < *right; - } -}; - -template struct greater_ptr { - bool operator()(const Ty* left, const Ty* right) const { - return *right < *left; - } -}; - /// An efficient, type-erasing, non-owning reference to a callable. This is /// intended for use as the type of a function parameter that is not used /// after the function in question returns. @@ -530,10 +518,6 @@ bool all_of(R &&range, UnaryPredicate P); template bool any_of(R &&range, UnaryPredicate P); -template struct index_sequence; - -template struct index_sequence_for; - namespace detail { using std::declval; @@ -568,38 +552,38 @@ struct zip_common : public zip_traits { std::tuple iterators; protected: - template value_type deref(index_sequence) const { + template value_type deref(std::index_sequence) const { return value_type(*std::get(iterators)...); } template - decltype(iterators) tup_inc(index_sequence) const { + decltype(iterators) tup_inc(std::index_sequence) const { return std::tuple(std::next(std::get(iterators))...); } template - decltype(iterators) tup_dec(index_sequence) const { + decltype(iterators) tup_dec(std::index_sequence) const { return std::tuple(std::prev(std::get(iterators))...); } public: zip_common(Iters &&... ts) : iterators(std::forward(ts)...) {} - value_type operator*() { return deref(index_sequence_for{}); } + value_type operator*() { return deref(std::index_sequence_for{}); } const value_type operator*() const { - return deref(index_sequence_for{}); + return deref(std::index_sequence_for{}); } ZipType &operator++() { - iterators = tup_inc(index_sequence_for{}); + iterators = tup_inc(std::index_sequence_for{}); return *reinterpret_cast(this); } ZipType &operator--() { static_assert(Base::IsBidirectional, "All inner iterators must be at least bidirectional."); - iterators = tup_dec(index_sequence_for{}); + iterators = tup_dec(std::index_sequence_for{}); return *reinterpret_cast(this); } }; @@ -618,7 +602,8 @@ struct zip_first : public zip_common, Iters...> { template class zip_shortest : public zip_common, Iters...> { template - bool test(const zip_shortest &other, index_sequence) const { + bool test(const zip_shortest &other, + std::index_sequence) const { return all_of(std::initializer_list{std::get(this->iterators) != std::get(other.iterators)...}, identity{}); @@ -630,7 +615,7 @@ public: zip_shortest(Iters &&... ts) : Base(std::forward(ts)...) {} bool operator==(const zip_shortest &other) const { - return !test(other, index_sequence_for{}); + return !test(other, std::index_sequence_for{}); } }; @@ -646,18 +631,21 @@ public: private: std::tuple ts; - template iterator begin_impl(index_sequence) const { + template + iterator begin_impl(std::index_sequence) const { return iterator(std::begin(std::get(ts))...); } - template iterator end_impl(index_sequence) const { + template iterator end_impl(std::index_sequence) const { return iterator(std::end(std::get(ts))...); } public: zippy(Args &&... ts_) : ts(std::forward(ts_)...) {} - iterator begin() const { return begin_impl(index_sequence_for{}); } - iterator end() const { return end_impl(index_sequence_for{}); } + iterator begin() const { + return begin_impl(std::index_sequence_for{}); + } + iterator end() const { return end_impl(std::index_sequence_for{}); } }; } // end namespace detail @@ -727,20 +715,20 @@ private: template bool test(const zip_longest_iterator &other, - index_sequence) const { + std::index_sequence) const { return llvm::any_of( std::initializer_list{std::get(this->iterators) != std::get(other.iterators)...}, identity{}); } - template value_type deref(index_sequence) const { + template value_type deref(std::index_sequence) const { return value_type( deref_or_none(std::get(iterators), std::get(end_iterators))...); } template - decltype(iterators) tup_inc(index_sequence) const { + decltype(iterators) tup_inc(std::index_sequence) const { return std::tuple( next_or_end(std::get(iterators), std::get(end_iterators))...); } @@ -750,17 +738,19 @@ public: : iterators(std::forward(ts.first)...), end_iterators(std::forward(ts.second)...) {} - value_type operator*() { return deref(index_sequence_for{}); } + value_type operator*() { return deref(std::index_sequence_for{}); } - value_type operator*() const { return deref(index_sequence_for{}); } + value_type operator*() const { + return deref(std::index_sequence_for{}); + } zip_longest_iterator &operator++() { - iterators = tup_inc(index_sequence_for{}); + iterators = tup_inc(std::index_sequence_for{}); return *this; } bool operator==(const zip_longest_iterator &other) const { - return !test(other, index_sequence_for{}); + return !test(other, std::index_sequence_for{}); } }; @@ -777,12 +767,13 @@ public: private: std::tuple ts; - template iterator begin_impl(index_sequence) const { + template + iterator begin_impl(std::index_sequence) const { return iterator(std::make_pair(adl_begin(std::get(ts)), adl_end(std::get(ts)))...); } - template iterator end_impl(index_sequence) const { + template iterator end_impl(std::index_sequence) const { return iterator(std::make_pair(adl_end(std::get(ts)), adl_end(std::get(ts)))...); } @@ -790,8 +781,10 @@ private: public: zip_longest_range(Args &&... ts_) : ts(std::forward(ts_)...) {} - iterator begin() const { return begin_impl(index_sequence_for{}); } - iterator end() const { return end_impl(index_sequence_for{}); } + iterator begin() const { + return begin_impl(std::index_sequence_for{}); + } + iterator end() const { return end_impl(std::index_sequence_for{}); } }; } // namespace detail @@ -847,7 +840,7 @@ class concat_iterator /// Increments the first non-end iterator. /// /// It is an error to call this with all iterators at the end. - template void increment(index_sequence) { + template void increment(std::index_sequence) { // Build a sequence of functions to increment each iterator if possible. bool (concat_iterator::*IncrementHelperFns[])() = { &concat_iterator::incrementHelper...}; @@ -876,7 +869,7 @@ class concat_iterator /// reference. /// /// It is an error to call this with all iterators at the end. - template ValueT &get(index_sequence) const { + template ValueT &get(std::index_sequence) const { // Build a sequence of functions to get from iterator if possible. ValueT *(concat_iterator::*GetHelperFns[])() const = { &concat_iterator::getHelper...}; @@ -901,11 +894,13 @@ public: using BaseT::operator++; concat_iterator &operator++() { - increment(index_sequence_for()); + increment(std::index_sequence_for()); return *this; } - ValueT &operator*() const { return get(index_sequence_for()); } + ValueT &operator*() const { + return get(std::index_sequence_for()); + } bool operator==(const concat_iterator &RHS) const { return Begins == RHS.Begins && Ends == RHS.Ends; @@ -928,10 +923,10 @@ public: private: std::tuple Ranges; - template iterator begin_impl(index_sequence) { + template iterator begin_impl(std::index_sequence) { return iterator(std::get(Ranges)...); } - template iterator end_impl(index_sequence) { + template iterator end_impl(std::index_sequence) { return iterator(make_range(std::end(std::get(Ranges)), std::end(std::get(Ranges)))...); } @@ -940,8 +935,8 @@ public: concat_range(RangeTs &&... Ranges) : Ranges(std::forward(Ranges)...) {} - iterator begin() { return begin_impl(index_sequence_for{}); } - iterator end() { return end_impl(index_sequence_for{}); } + iterator begin() { return begin_impl(std::index_sequence_for{}); } + iterator end() { return end_impl(std::index_sequence_for{}); } }; } // end namespace detail @@ -990,28 +985,6 @@ struct on_first { } }; -// A subset of N3658. More stuff can be added as-needed. - -/// Represents a compile-time sequence of integers. -template struct integer_sequence { - using value_type = T; - - static constexpr size_t size() { return sizeof...(I); } -}; - -/// Alias for the common case of a sequence of size_ts. -template -struct index_sequence : integer_sequence {}; - -template -struct build_index_impl : build_index_impl {}; -template -struct build_index_impl<0, I...> : index_sequence {}; - -/// Creates a compile-time integer sequence for a parameter pack. -template -struct index_sequence_for : build_index_impl {}; - /// Utility type to build an inheritance chain that makes it easy to rank /// overload candidates. template struct rank : rank {}; @@ -1391,41 +1364,6 @@ void replace(Container &Cont, typename Container::iterator ContIt, // Extra additions to //===----------------------------------------------------------------------===// -// Implement make_unique according to N3656. - -/// Constructs a `new T()` with the given args and returns a -/// `unique_ptr` which owns the object. -/// -/// Example: -/// -/// auto p = make_unique(); -/// auto p = make_unique>(0, 1); -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(Args &&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -/// Constructs a `new T[n]` with the given args and returns a -/// `unique_ptr` which owns the object. -/// -/// \param n size of the new array. -/// -/// Example: -/// -/// auto p = make_unique(2); // value-initializes the array with 0's. -template -typename std::enable_if::value && std::extent::value == 0, - std::unique_ptr>::type -make_unique(size_t n) { - return std::unique_ptr(new typename std::remove_extent::type[n]()); -} - -/// This function isn't used and is only here to provide better compile errors. -template -typename std::enable_if::value != 0>::type -make_unique(Args &&...) = delete; - struct FreeDeleter { void operator()(void* v) { ::free(v); @@ -1439,20 +1377,6 @@ struct pair_hash { } }; -/// A functor like C++14's std::less in its absence. -struct less { - template bool operator()(A &&a, B &&b) const { - return std::forward(a) < std::forward(b); - } -}; - -/// A functor like C++14's std::equal in its absence. -struct equal { - template bool operator()(A &&a, B &&b) const { - return std::forward(a) == std::forward(b); - } -}; - /// Binary functor that adapts to any other binary functor after dereferencing /// operands. template struct deref { @@ -1580,7 +1504,7 @@ template detail::enumerator enumerate(R &&TheRange) { namespace detail { template -auto apply_tuple_impl(F &&f, Tuple &&t, index_sequence) +auto apply_tuple_impl(F &&f, Tuple &&t, std::index_sequence) -> decltype(std::forward(f)(std::get(std::forward(t))...)) { return std::forward(f)(std::get(std::forward(t))...); } @@ -1593,9 +1517,9 @@ auto apply_tuple_impl(F &&f, Tuple &&t, index_sequence) template auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl( std::forward(f), std::forward(t), - build_index_impl< + std::make_index_sequence< std::tuple_size::type>::value>{})) { - using Indices = build_index_impl< + using Indices = std::make_index_sequence< std::tuple_size::type>::value>; return detail::apply_tuple_impl(std::forward(f), std::forward(t), -- cgit v1.2.3