[libcxx-commits] [libcxx] [libc++][test] Improve tests for assign in std::vector (PR #119163)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Dec 9 08:35:04 PST 2024
================
@@ -63,6 +62,100 @@ TEST_CONSTEXPR_CXX20 bool test() {
assert(v[2].value == 42);
}
}
+
+ { // Test with new_size < size() for forward_iterator, resulting in destruction at end during assign
+ using T = EmplaceConstructibleMoveableAndAssignable<int>;
+ using It = forward_iterator<int*>;
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ for (std::size_t i = 0; i < v.capacity(); ++i)
+ v.emplace_back(99);
+ v.assign(It(arr1), It(std::end(arr1)));
+ assert(v.size() == 1);
+ assert(v[0].value == 42);
+ }
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ for (std::size_t i = 0; i < v.capacity(); ++i)
+ v.emplace_back(99);
+ v.assign(It(arr2), It(std::end(arr2)));
+ assert(v.size() == 3);
+ assert(v[0].value == 1);
+ assert(v[1].value == 101);
+ assert(v[2].value == 42);
+ }
+ }
+ { // Test with new_size < size() for input_iterator, resulting in destruction at end during assign
+ using T = EmplaceConstructibleMoveableAndAssignable<int>;
+ using It = cpp17_input_iterator<int*>;
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ for (std::size_t i = 0; i < v.capacity(); ++i)
+ v.emplace_back(99);
+ v.assign(It(arr1), It(std::end(arr1)));
+ assert(v.size() == 1);
+ assert(v[0].value == 42);
+ }
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ for (std::size_t i = 0; i < v.capacity(); ++i)
+ v.emplace_back(99);
+ v.assign(It(arr2), It(std::end(arr2)));
+ assert(v.size() == 3);
+ assert(v[0].value == 1);
+ assert(v[1].value == 101);
+ assert(v[2].value == 42);
+ }
+ }
+
+ { // Test with size() < new_size < capacity() for forward_iterator, resulting in construction at end during assign
+ using T = EmplaceConstructibleMoveableAndAssignable<int>;
+ using It = forward_iterator<int*>;
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ v.assign(It(arr1), It(std::end(arr1)));
+ assert(v.size() == 1);
+ assert(v[0].value == 42);
+ }
+ {
+ std::vector<T> v;
+ v.reserve(5);
+ for (std::size_t i = 0; i < 2; ++i)
+ v.emplace_back(99);
+ v.assign(It(arr2), It(std::end(arr2)));
+ assert(v.size() == 3);
+ assert(v[0].value == 1);
+ assert(v[1].value == 101);
+ assert(v[2].value == 42);
+ }
+ }
+ { // Test with size() < new_size < capacity() for inputs_iterator, resulting in construction at end during assign
----------------
ldionne wrote:
```suggestion
{ // Test with size() < new_size < capacity() for input_iterator, resulting in construction at end during assign
```
https://github.com/llvm/llvm-project/pull/119163
More information about the libcxx-commits
mailing list