Lines Matching refs:Array
25 // Represents a moveable array with contents of type |T|. The array can be null,
28 class Array {
38 // Constructs an empty array.
39 Array() : is_null_(false) {}
40 // Constructs a null array.
41 Array(std::nullptr_t null_pointer) : is_null_(true) {}
43 // Constructs a new non-null array of the specified size. The elements will
46 explicit Array(size_t size) : vec_(size), is_null_(false) {}
47 ~Array() {}
49 // Copies the contents of |other| into this array.
50 Array(const std::vector<T>& other) : vec_(other), is_null_(false) {}
52 // Moves the contents of |other| into this array.
53 Array(std::vector<T>&& other) : vec_(std::move(other)), is_null_(false) {}
54 Array(Array&& other) : is_null_(true) { Take(&other); }
56 Array& operator=(std::vector<T>&& other) {
61 Array& operator=(Array&& other) {
66 Array& operator=(std::nullptr_t null_pointer) {
72 // Creates a non-null array of the specified size. The elements will be
75 static Array New(size_t size) { return Array(size); }
77 // Creates a new array with a copy of the contents of |other|.
79 static Array From(const U& other) {
80 return TypeConverter<Array, U>::Convert(other);
83 // Copies the contents of this array to a new object of type |U|.
86 return TypeConverter<U, Array>::Convert(*this);
89 // Indicates whether the array is null (which is distinct from empty).
92 // Indicates whether the array is empty (which is distinct from null).
95 // Returns a reference to the first element of the array. Calling this on a
96 // null or empty array causes undefined behavior.
105 // Returns the size of the array, which will be zero if the array is null.
109 // an array with size less than |offset|+1 causes undefined behavior.
115 // Pushes |value| onto the back of the array. If this array was null, it will
126 // Resizes the array to |size| and makes it non-null. Otherwise, works just
133 // Sets the array to empty (even if previously it was null.)
137 // the array is null, this will be an empty vector.
140 // Passes the underlying storage and resets this array to null.
148 void Swap(Array* other) {
153 // Swaps the contents of this array with the specified vector, making this
154 // array non-null. Since the vector cannot represent null, it will just be
155 // made empty if this array is null.
161 // Returns a copy of the array where each value of the new array has been
162 // "cloned" from the corresponding value of this array. If the element type
169 Array Clone() const {
170 Array result;
176 // Indicates whether the contents of this array are equal to |other|. A null
177 // array is only equal to another null array. If the element type defines an
179 bool Equals(const Array& other) const {
186 typedef std::vector<T> Array::*Testable;
189 operator Testable() const { return is_null_ ? 0 : &Array::vec_; }
192 // Forbid the == and != operators explicitly, otherwise Array will be
195 bool operator==(const Array<U>& other) const = delete;
197 bool operator!=(const Array<U>& other) const = delete;
199 void Take(Array* other) {
207 DISALLOW_COPY_AND_ASSIGN(Array);
210 // A |TypeConverter| that will create an |Array<T>| containing a copy of the
212 // element. The returned array will always be non-null.
214 struct TypeConverter<Array<T>, std::vector<E>> {
215 static Array<T> Convert(const std::vector<E>& input) {
216 Array<T> result(input.size());
224 // the contents of an |Array<T>|, using |TypeConverter<E, T>| to copy each
225 // element. If the input array is null, the output vector will be empty.
227 struct TypeConverter<std::vector<E>, Array<T>> {
228 static std::vector<E> Convert(const Array<T>& input) {
239 // A |TypeConverter| that will create an |Array<T>| containing a copy of the
241 // element. The returned array will always be non-null.
243 struct TypeConverter<Array<T>, std::set<E>> {
244 static Array<T> Convert(const std::set<E>& input) {
245 Array<T> result;
253 // the contents of an |Array<T>|, using |TypeConverter<E, T>| to copy each
254 // element. If the input array is null, the output set will be empty.
256 struct TypeConverter<std::set<E>, Array<T>> {
257 static std::set<E> Convert(const Array<T>& input) {
269 inline bool operator<(const Array<T>& a, const Array<T>& b) {