/// @{
/// Construct an empty ArrayRef.
- /*implicit*/ ArrayRef() : Data(0), Length(0) {}
+ /*implicit*/ ArrayRef() : Data(nullptr), Length(0) {}
/// Construct an empty ArrayRef from None.
- /*implicit*/ ArrayRef(NoneType) : Data(0), Length(0) {}
+ /*implicit*/ ArrayRef(NoneType) : Data(nullptr), Length(0) {}
/// Construct an ArrayRef from a single element.
/*implicit*/ ArrayRef(const T &OneElt)
/// Construct an ArrayRef from a std::vector.
template<typename A>
/*implicit*/ ArrayRef(const std::vector<T, A> &Vec)
- : Data(Vec.empty() ? (T*)0 : &Vec[0]), Length(Vec.size()) {}
+ : Data(Vec.data()), Length(Vec.size()) {}
/// Construct an ArrayRef from a C array.
template <size_t N>
- /*implicit*/ ArrayRef(const T (&Arr)[N])
+ /*implicit*/ LLVM_CONSTEXPR ArrayRef(const T (&Arr)[N])
: Data(Arr), Length(N) {}
+#if LLVM_HAS_INITIALIZER_LISTS
+ /// Construct an ArrayRef from a std::initializer_list.
+ /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
+ : Data(Vec.begin() == Vec.end() ? (T*)0 : Vec.begin()),
+ Length(Vec.size()) {}
+#endif
+
/// @}
/// @name Simple Operations
/// @{
return Data[Length-1];
}
+ // copy - Allocate copy in Allocator and return ArrayRef<T> to it.
+ template <typename Allocator> ArrayRef<T> copy(Allocator &A) {
+ T *Buff = A.template Allocate<T>(Length);
+ std::copy(begin(), end(), Buff);
+ return ArrayRef<T>(Buff, Length);
+ }
+
/// equals - Check for element-wise equality.
bool equals(ArrayRef RHS) const {
if (Length != RHS.Length)
return false;
- for (size_type i = 0; i != Length; i++)
- if (Data[i] != RHS.Data[i])
- return false;
- return true;
+ return std::equal(begin(), end(), RHS.begin());
}
/// slice(n) - Chop off the first N elements of the array.
public:
typedef T *iterator;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+
/// Construct an empty MutableArrayRef.
/*implicit*/ MutableArrayRef() : ArrayRef<T>() {}
/// Construct an MutableArrayRef from a C array.
template <size_t N>
- /*implicit*/ MutableArrayRef(T (&Arr)[N])
+ /*implicit*/ LLVM_CONSTEXPR MutableArrayRef(T (&Arr)[N])
: ArrayRef<T>(Arr) {}
T *data() const { return const_cast<T*>(ArrayRef<T>::data()); }
iterator begin() const { return data(); }
iterator end() const { return data() + this->size(); }
+ reverse_iterator rbegin() const { return reverse_iterator(end()); }
+ reverse_iterator rend() const { return reverse_iterator(begin()); }
+
/// front - Get the first element.
T &front() const {
assert(!this->empty());