-
Notifications
You must be signed in to change notification settings - Fork 15k
[ADT] Add SmallVector::assign overload for ArrayRef
#164680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
We already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well.
|
@llvm/pr-subscribers-llvm-adt Author: Jakub Kuderski (kuhar) ChangesWe already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well. Full diff: https://github.com/llvm/llvm-project/pull/164680.diff 2 Files Affected:
diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h
index efae6f339f9de..ca0b918f56c46 100644
--- a/llvm/include/llvm/ADT/SmallVector.h
+++ b/llvm/include/llvm/ADT/SmallVector.h
@@ -734,6 +734,12 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
void assign(const SmallVectorImpl &RHS) { assign(RHS.begin(), RHS.end()); }
+ template <typename U,
+ typename = std::enable_if_t<std::is_convertible_v<U, T>>>
+ void assign(ArrayRef<U> AR) {
+ assign(AR.begin(), AR.end());
+ }
+
iterator erase(const_iterator CI) {
// Just cast away constness because this is a non-const member function.
iterator I = const_cast<iterator>(CI);
@@ -1228,7 +1234,7 @@ class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
}
template <typename U,
- typename = std::enable_if_t<std::is_convertible<U, T>::value>>
+ typename = std::enable_if_t<std::is_convertible_v<U, T>>>
explicit SmallVector(ArrayRef<U> A) : SmallVectorImpl<T>(N) {
this->append(A.begin(), A.end());
}
diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp
index e2e778f44b5e9..b216359ffd31c 100644
--- a/llvm/unittests/ADT/SmallVectorTest.cpp
+++ b/llvm/unittests/ADT/SmallVectorTest.cpp
@@ -599,6 +599,15 @@ TYPED_TEST(SmallVectorTest, AssignSmallVector) {
assertValuesInOrder(V, 2u, 7, 7);
}
+TYPED_TEST(SmallVectorTest, AssignArrayRef) {
+ SCOPED_TRACE("AssignArrayRef");
+ auto &V = this->theVector;
+ Constructable Other[] = {7, 8, 9};
+ V.push_back(Constructable(1));
+ V.assign(ArrayRef(Other));
+ assertValuesInOrder(V, 3u, 7, 8, 9);
+}
+
// Move-assign test
TYPED_TEST(SmallVectorTest, MoveAssignTest) {
SCOPED_TRACE("MoveAssignTest");
|
72f0eed to
d3ec7c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/17911 Here is the relevant piece of the build log for the reference |
We already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well.
We already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well.
We already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well.
We already have a matching constructor from ArrayRef, so add support for assigning from ArrayRef as well.