9 #ifndef LLVM_ADT_ARRAYREF_H 10 #define LLVM_ADT_ARRAYREF_H 21 #include <initializer_list> 24 #include <type_traits> 50 const T *
Data =
nullptr;
67 : Data(&OneElt), Length(1) {}
71 : Data(data), Length(length) {}
75 : Data(begin), Length(end - begin) {}
82 : Data(Vec.data()), Length(Vec.
size()) {
88 : Data(Vec.data()), Length(Vec.
size()) {}
92 constexpr
ArrayRef(
const std::array<T, N> &Arr)
93 : Data(Arr.data()), Length(
N) {}
97 constexpr
ArrayRef(
const T (&Arr)[
N]) : Data(Arr), Length(N) {}
100 #if LLVM_GNUC_PREREQ(9, 0, 0) 104 #pragma GCC diagnostic push 105 #pragma GCC diagnostic ignored "-Winit-list-lifetime" 109 Length(Vec.
size()) {}
110 #if LLVM_GNUC_PREREQ(9, 0, 0) 111 #pragma GCC diagnostic pop 116 template <
typename U>
119 typename std::enable_if<
120 std::is_convertible<U *const *, T const *>::value>::
type * =
nullptr)
121 : Data(A.data()), Length(A.
size()) {}
126 template<
typename U,
typename DummyT>
129 typename std::enable_if<
130 std::is_convertible<U *const *, T const *>::value>::
type * =
nullptr)
131 : Data(Vec.data()), Length(Vec.
size()) {
136 template<
typename U,
typename A>
138 typename std::enable_if<
139 std::is_convertible<U *const *, T const *>::value>::
type* = 0)
140 : Data(Vec.data()), Length(Vec.
size()) {}
153 bool empty()
const {
return Length == 0; }
158 size_t size()
const {
return Length; }
169 return Data[Length-1];
174 T *Buff = A.template Allocate<T>(Length);
175 std::uninitialized_copy(
begin(),
end(), Buff);
181 if (Length != RHS.Length)
198 assert(
size() >=
N &&
"Dropping more elements than exist");
199 return slice(
N,
size() -
N);
204 assert(
size() >=
N &&
"Dropping more elements than exist");
205 return slice(0,
size() -
N);
224 return drop_back(
size() -
N);
231 return drop_front(
size() -
N);
250 assert(Index < Length &&
"Invalid index!");
258 template <
typename U>
260 operator=(U &&Temporary) =
delete;
266 template <
typename U>
268 operator=(std::initializer_list<U>) =
delete;
273 std::vector<T>
vec()
const {
274 return std::vector<T>(
Data, Data+Length);
280 operator std::vector<T>()
const {
281 return std::vector<T>(
Data, Data+Length);
355 return data()[this->
size()-1];
361 assert(N + M <= this->
size() &&
"Invalid specifier");
367 return slice(N, this->
size() - N);
372 assert(this->
size() >=
N &&
"Dropping more elements than exist");
373 return slice(
N, this->
size() -
N);
377 assert(this->
size() >=
N &&
"Dropping more elements than exist");
378 return slice(0, this->
size() -
N);
383 template <
class PredicateT>
390 template <
class PredicateT>
397 if (
N >= this->
size())
399 return drop_back(this->
size() -
N);
404 if (
N >= this->
size())
406 return drop_front(this->
size() -
N);
411 template <
class PredicateT>
418 template <
class PredicateT>
427 assert(Index < this->
size() &&
"Invalid index!");
428 return data()[
Index];
446 delete[] this->data();
477 template <
typename T>
483 template <
typename T,
unsigned N>
495 template <
typename T, std::
size_t N>
511 template<
typename T,
size_t N>
539 return !(LHS == RHS);
550 #endif // LLVM_ADT_ARRAYREF_H reverse_iterator rbegin() const
const T & operator[](size_t Index) const
const T & front() const
front - Get the first element.
MutableArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
ArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
const_iterator end(StringRef path)
Get end iterator over path.
ArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate. ...
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
const T & back() const
back - Get the last element.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
MutableArrayRef< T > makeMutableArrayRef(T &OneElt)
Construct a MutableArrayRef from a single element.
This class represents lattice values for constants.
NoneType
A simple null object to allow implicit construction of Optional<T> and similar types without having t...
constexpr MutableArrayRef(T(&Arr)[N])
Construct an MutableArrayRef from a C array.
reverse_iterator rbegin() const
ArrayRef(NoneType)
Construct an empty ArrayRef from None.
T & front() const
front - Get the first element.
ArrayRef(const std::vector< U *, A > &Vec, typename std::enable_if< std::is_convertible< U *const *, T const *>::value >::type *=0)
Construct an ArrayRef<const T*> from std::vector<T*>.
std::reverse_iterator< iterator > reverse_iterator
MutableArrayRef(std::vector< T > &Vec)
Construct a MutableArrayRef from a std::vector.
ArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
ArrayRef(const std::vector< T, A > &Vec)
Construct an ArrayRef from a std::vector.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
ArrayRef(const std::initializer_list< T > &Vec)
Construct an ArrayRef from a std::initializer_list.
T & operator[](size_t Index) const
ArrayRef< T > copy(Allocator &A)
MutableArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
OwningArrayRef & operator=(OwningArrayRef &&Other)
MutableArrayRef< T > take_until(PredicateT Pred) const
Return the first N elements of this Array that don't satisfy the given predicate. ...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
ArrayRef(const SmallVectorTemplateCommon< T, U > &Vec)
Construct an ArrayRef from a SmallVector.
MutableArrayRef(T *begin, T *end)
Construct an MutableArrayRef from a range.
size_t size() const
size - Get the array size.
std::enable_if< std::is_same< U, T >::value, ArrayRef< T > >::type & operator=(U &&Temporary)=delete
Disallow accidental assignment from a temporary.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
auto find_if_not(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
MutableArrayRef< T > drop_back(size_t N=1) const
OwningArrayRef(OwningArrayRef &&Other)
This is a MutableArrayRef that owns its array.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
ArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
reverse_iterator rend() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
MutableArrayRef(T *data, size_t length)
Construct an MutableArrayRef from a pointer and length.
constexpr ArrayRef(const std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
MutableArrayRef< T > drop_while(PredicateT Pred) const
Return a copy of *this with the first N elements satisfying the given predicate removed.
MutableArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
MutableArrayRef< T > take_while(PredicateT Pred) const
Return the first N elements of this Array that satisfy the given predicate.
ArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed...
std::vector< T > vec() const
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
MutableArrayRef(T &OneElt)
Construct an MutableArrayRef from a single element.
An opaque object representing a hash code.
ArrayRef(const T *data, size_t length)
Construct an ArrayRef from a pointer and length.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
ArrayRef(const ArrayRef< U *> &A, typename std::enable_if< std::is_convertible< U *const *, T const *>::value >::type *=nullptr)
Construct an ArrayRef<const T*> from ArrayRef<T*>.
ArrayRef(const SmallVectorTemplateCommon< U *, DummyT > &Vec, typename std::enable_if< std::is_convertible< U *const *, T const *>::value >::type *=nullptr)
Construct an ArrayRef<const T*> from a SmallVector<T*>.
MutableArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
bool operator!=(uint64_t V1, const APInt &V2)
reverse_iterator rend() const
This is the part of SmallVectorTemplateBase which does not depend on whether the type T is a POD...
ArrayRef< T > take_back(size_t N=1) const
Return a copy of *this with only the last N elements.
constexpr ArrayRef(const T(&Arr)[N])
Construct an ArrayRef from a C array.
MutableArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
OwningArrayRef(ArrayRef< T > Data)
bool equals(ArrayRef RHS) const
equals - Check for element-wise equality.
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
OwningArrayRef(size_t Size)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is equivalent to an IR comdat.
constexpr MutableArrayRef(std::array< T, N > &Arr)
Construct an ArrayRef from a std::array.
ArrayRef(const T *begin, const T *end)
Construct an ArrayRef from a range.
MutableArrayRef< T > drop_until(PredicateT Pred) const
Return a copy of *this with the first N elements not satisfying the given predicate removed...
ArrayRef< T > slice(size_t N) const
slice(n) - Chop off the first N elements of the array.
T & back() const
back - Get the last element.
bool operator==(uint64_t V1, const APInt &V2)
MutableArrayRef(NoneType)
Construct an empty MutableArrayRef from None.
OutputIt copy(R &&Range, OutputIt Out)
MutableArrayRef(SmallVectorImpl< T > &Vec)
Construct an MutableArrayRef from a SmallVector.
bool empty() const
empty - Check if the array is empty.