diff options
author | Abseil Team <absl-team@google.com> | 2018-09-11T18·22-0700 |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-09-11T18·28-0400 |
commit | 02451914b9ad5320f81f56a89f3eef1f8683227c (patch) | |
tree | 99b17555d1d04114190048a9fca05841ac39287e /absl/types/span.h | |
parent | 921fd5cf02ec0d665439a790148d59faa7d4a72c (diff) |
Export of internal Abseil changes.
-- 74c1330e29f1501f2738258faf9ec4564395c90a by Gennadiy Civil <misterg@google.com>: Merging https://github.com/abseil/abseil-cpp/pull/166 PiperOrigin-RevId: 212487256 -- 4ac236574ff8fb3cc1125505292b0bd8c8192da9 by Abseil Team <absl-team@google.com>: Allow c_move to take rvalue containers. PiperOrigin-RevId: 212458618 -- ce94e23984870db666d4c91623ae45b3c60b5b61 by Matt Armstrong <marmstrong@google.com>: Internal change. PiperOrigin-RevId: 212153041 -- 7d88d286821c5839934756dd63a704ed162c49cb by Chris Kennelly <ckennelly@google.com>: Internal change PiperOrigin-RevId: 211982309 -- ddae814b3f609948c20551ea3d80bf51b973f480 by Abseil Team <absl-team@google.com>: Remove unused argument from InlinedVector's AllocatorAndTag This is not part of InlinedVector's public interface. PiperOrigin-RevId: 211973017 -- 051fbfd81648a8da66c62c6603af63038d709c15 by Abseil Team <absl-team@google.com>: Minor performance fix PiperOrigin-RevId: 211820453 -- c205cb2add7400bc8caf2131cb700eea560b7dbf by Laramie Leavitt <lar@google.com>: Make absl::Span a tiny bit more consistent. Add constexper to equivalent absl::Span members as described by http://open-std.org/JTC1/SC22/WG21/docs/papers/2018/p0122r7.pdf * Span constructor use consistently delegate to Span(ptr, length) * Mark more member methods as constexpr. * Use data() and size() consistently in member methods. PiperOrigin-RevId: 211707244 -- 55500c9e941f2f58f4a95c121f32772408866eee by Derek Mauro <dmauro@google.com>: Stop catching polymorphic exception types by value. GCC 8 emits a warning for this. PiperOrigin-RevId: 211684466 GitOrigin-RevId: 74c1330e29f1501f2738258faf9ec4564395c90a Change-Id: Iceab4a5b30ee35d82ef494830262ad29c028cb0a
Diffstat (limited to 'absl/types/span.h')
-rw-r--r-- | absl/types/span.h | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/absl/types/span.h b/absl/types/span.h index 5387e8e027df..3359ce5093c5 100644 --- a/absl/types/span.h +++ b/absl/types/span.h @@ -379,64 +379,70 @@ class Span { // // Returns a reference to the i'th element of this span. constexpr reference at(size_type i) const { - return ABSL_PREDICT_TRUE(i < size()) - ? ptr_[i] + return ABSL_PREDICT_TRUE(i < size()) // + ? *(data() + i) : (base_internal::ThrowStdOutOfRange( "Span::at failed bounds check"), - ptr_[i]); + *(data() + i)); } // Span::front() // // Returns a reference to the first element of this span. - reference front() const noexcept { return ABSL_ASSERT(size() > 0), ptr_[0]; } + constexpr reference front() const noexcept { + return ABSL_ASSERT(size() > 0), *data(); + } // Span::back() // // Returns a reference to the last element of this span. - reference back() const noexcept { - return ABSL_ASSERT(size() > 0), ptr_[size() - 1]; + constexpr reference back() const noexcept { + return ABSL_ASSERT(size() > 0), *(data() + size() - 1); } // Span::begin() // // Returns an iterator to the first element of this span. - constexpr iterator begin() const noexcept { return ptr_; } + constexpr iterator begin() const noexcept { return data(); } // Span::cbegin() // // Returns a const iterator to the first element of this span. - constexpr const_iterator cbegin() const noexcept { return ptr_; } + constexpr const_iterator cbegin() const noexcept { return begin(); } // Span::end() // // Returns an iterator to the last element of this span. - iterator end() const noexcept { return ptr_ + len_; } + constexpr iterator end() const noexcept { return data() + size(); } // Span::cend() // // Returns a const iterator to the last element of this span. - const_iterator cend() const noexcept { return end(); } + constexpr const_iterator cend() const noexcept { return end(); } // Span::rbegin() // // Returns a reverse iterator starting at the last element of this span. - reverse_iterator rbegin() const noexcept { return reverse_iterator(end()); } + constexpr reverse_iterator rbegin() const noexcept { + return reverse_iterator(end()); + } // Span::crbegin() // // Returns a reverse const iterator starting at the last element of this span. - const_reverse_iterator crbegin() const noexcept { return rbegin(); } + constexpr const_reverse_iterator crbegin() const noexcept { return rbegin(); } // Span::rend() // // Returns a reverse iterator starting at the first element of this span. - reverse_iterator rend() const noexcept { return reverse_iterator(begin()); } + constexpr reverse_iterator rend() const noexcept { + return reverse_iterator(begin()); + } // Span::crend() // // Returns a reverse iterator starting at the first element of this span. - const_reverse_iterator crend() const noexcept { return rend(); } + constexpr const_reverse_iterator crend() const noexcept { return rend(); } // Span mutations @@ -444,7 +450,7 @@ class Span { // // Removes the first `n` elements from the span. void remove_prefix(size_type n) noexcept { - assert(len_ >= n); + assert(size() >= n); ptr_ += n; len_ -= n; } @@ -453,7 +459,7 @@ class Span { // // Removes the last `n` elements from the span. void remove_suffix(size_type n) noexcept { - assert(len_ >= n); + assert(size() >= n); len_ -= n; } @@ -474,8 +480,8 @@ class Span { // absl::MakeSpan(vec).subspan(4); // {} // absl::MakeSpan(vec).subspan(5); // throws std::out_of_range constexpr Span subspan(size_type pos = 0, size_type len = npos) const { - return (pos <= len_) - ? Span(ptr_ + pos, span_internal::Min(len_ - pos, len)) + return (pos <= size()) + ? Span(data() + pos, span_internal::Min(size() - pos, len)) : (base_internal::ThrowStdOutOfRange("pos > size()"), Span()); } |