tint: Add utils::UniqueVector::data()
Change-Id: Ibbd4f595c5fdaacf93c13757878ed06675e735c6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91022 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
3607cb8465
commit
d99af03663
|
@ -75,6 +75,9 @@ struct UniqueVector {
|
|||
/// @returns the number of items in the vector
|
||||
size_t size() const { return vector.size(); }
|
||||
|
||||
/// @returns the pointer to the first element in the vector, or nullptr if the vector is empty.
|
||||
const T* data() const { return vector.empty() ? nullptr : vector.data(); }
|
||||
|
||||
/// @returns an iterator to the beginning of the vector
|
||||
ConstIterator begin() const { return vector.begin(); }
|
||||
|
||||
|
|
|
@ -139,5 +139,14 @@ TEST(UniqueVectorTest, PopBack) {
|
|||
EXPECT_EQ(unique_vec.empty(), true);
|
||||
}
|
||||
|
||||
TEST(UniqueVectorTest, Data) {
|
||||
UniqueVector<int> unique_vec;
|
||||
EXPECT_EQ(unique_vec.data(), nullptr);
|
||||
|
||||
unique_vec.add(42);
|
||||
EXPECT_EQ(unique_vec.data(), &unique_vec[0]);
|
||||
EXPECT_EQ(*unique_vec.data(), 42);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::utils
|
||||
|
|
Loading…
Reference in New Issue