Add [c]begin() and [c]end() member functions to rtc::Buffer
I can't believe it's been this long before I found out we didn't have them... BUG=none Review-Url: https://codereview.webrtc.org/2804673002 Cr-Commit-Position: refs/heads/master@{#17544}
This commit is contained in:
parent
dea682d25b
commit
1ba21eb063
@ -179,6 +179,13 @@ class BufferT {
|
||||
return data()[index];
|
||||
}
|
||||
|
||||
T* begin() { return data(); }
|
||||
T* end() { return data() + size(); }
|
||||
const T* begin() const { return data(); }
|
||||
const T* end() const { return data() + size(); }
|
||||
const T* cbegin() const { return data(); }
|
||||
const T* cend() const { return data() + size(); }
|
||||
|
||||
// The SetData functions replace the contents of the buffer. They accept the
|
||||
// same input types as the constructors.
|
||||
template <typename U,
|
||||
|
||||
@ -356,6 +356,24 @@ TEST(BufferTest, TestBracketWrite) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestBeginEnd) {
|
||||
const Buffer cbuf(kTestData);
|
||||
Buffer buf(kTestData);
|
||||
auto b1 = cbuf.begin();
|
||||
for (auto& x : buf) {
|
||||
EXPECT_EQ(*b1, x);
|
||||
++b1;
|
||||
++x;
|
||||
}
|
||||
EXPECT_EQ(cbuf.end(), b1);
|
||||
auto b2 = buf.begin();
|
||||
for (auto& y : cbuf) {
|
||||
EXPECT_EQ(*b2, y + 1);
|
||||
++b2;
|
||||
}
|
||||
EXPECT_EQ(buf.end(), b2);
|
||||
}
|
||||
|
||||
TEST(BufferTest, TestInt16) {
|
||||
static constexpr int16_t test_data[] = {14, 15, 16, 17, 18};
|
||||
BufferT<int16_t> buf(test_data);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user