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>
diff --git a/src/tint/utils/unique_vector.h b/src/tint/utils/unique_vector.h
index 96d9cbf..0f3f18d 100644
--- a/src/tint/utils/unique_vector.h
+++ b/src/tint/utils/unique_vector.h
@@ -75,6 +75,9 @@
     /// @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(); }
 
diff --git a/src/tint/utils/unique_vector_test.cc b/src/tint/utils/unique_vector_test.cc
index 7d586e9..035ebf8 100644
--- a/src/tint/utils/unique_vector_test.cc
+++ b/src/tint/utils/unique_vector_test.cc
@@ -139,5 +139,14 @@
     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