OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 T& operator[](size_t idx) const { | 65 T& operator[](size_t idx) const { |
66 RTC_DCHECK_LT(idx, size_); | 66 RTC_DCHECK_LT(idx, size_); |
67 RTC_DCHECK(data_); // Follows from size_ > idx and the class invariant. | 67 RTC_DCHECK(data_); // Follows from size_ > idx and the class invariant. |
68 return data_[idx]; | 68 return data_[idx]; |
69 } | 69 } |
70 T* begin() const { return data_; } | 70 T* begin() const { return data_; } |
71 T* end() const { return data_ + size_; } | 71 T* end() const { return data_ + size_; } |
72 const T* cbegin() const { return data_; } | 72 const T* cbegin() const { return data_; } |
73 const T* cend() const { return data_ + size_; } | 73 const T* cend() const { return data_ + size_; } |
74 | 74 |
| 75 // An ArrayView is false iff it's empty. |
| 76 explicit operator bool() const { return size_ > 0; } |
| 77 |
| 78 // Comparing two ArrayViews compares their (pointer,size) pairs; it does |
| 79 // *not* dereference the pointers. |
| 80 friend bool operator==(const ArrayView& a, const ArrayView& b) { |
| 81 return a.data_ == b.data_ && a.size_ == b.size_; |
| 82 } |
| 83 friend bool operator!=(const ArrayView& a, const ArrayView& b) { |
| 84 return !(a == b); |
| 85 } |
| 86 |
75 private: | 87 private: |
76 // Invariant: !data_ iff size_ == 0. | 88 // Invariant: !data_ iff size_ == 0. |
77 void CheckInvariant() const { RTC_DCHECK_EQ(!data_, size_ == 0); } | 89 void CheckInvariant() const { RTC_DCHECK_EQ(!data_, size_ == 0); } |
78 T* data_; | 90 T* data_; |
79 size_t size_; | 91 size_t size_; |
80 }; | 92 }; |
81 | 93 |
82 } // namespace rtc | 94 } // namespace rtc |
83 | 95 |
84 #endif // WEBRTC_BASE_ARRAY_VIEW_H_ | 96 #endif // WEBRTC_BASE_ARRAY_VIEW_H_ |
OLD | NEW |