[PATCH] D54992: Implement P0966 - string::reserve Should Not Shrink
Marshall Clow via Phabricator
reviews at reviews.llvm.org
Tue Nov 27 22:30:33 PST 2018
mclow.lists created this revision.
mclow.lists added reviewers: EricWF, ldionne.
We already did most of this, so this is a small change.
https://reviews.llvm.org/D54992
Files:
include/string
test/std/strings/basic.string/string.capacity/reserve.pass.cpp
Index: test/std/strings/basic.string/string.capacity/reserve.pass.cpp
===================================================================
--- test/std/strings/basic.string/string.capacity/reserve.pass.cpp
+++ test/std/strings/basic.string/string.capacity/reserve.pass.cpp
@@ -9,7 +9,9 @@
// <string>
-// void reserve(size_type res_arg=0);
+// Split into two calls for C++20
+// void reserve();
+// void reserve(size_type res_arg);
#include <string>
#include <stdexcept>
@@ -44,6 +46,9 @@
assert(s == s0);
assert(s.capacity() >= res_arg);
assert(s.capacity() >= s.size());
+#if TEST_STD_VER > 17
+ assert(s.capacity() >= old_cap); // resize never shrinks as of P0966
+#endif
}
#ifndef TEST_HAS_NO_EXCEPTIONS
else
@@ -90,6 +95,7 @@
test(s, 10);
test(s, 50);
test(s, 100);
+ test(s, 1000);
test(s, S::npos);
}
}
@@ -121,6 +127,7 @@
test(s, 10);
test(s, 50);
test(s, 100);
+ test(s, 1000);
test(s, S::npos);
}
}
Index: include/string
===================================================================
--- include/string
+++ include/string
@@ -956,8 +956,10 @@
void resize(size_type __n, value_type __c);
_LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
- void reserve(size_type __res_arg = 0);
+ void reserve(size_type __res_arg);
_LIBCPP_INLINE_VISIBILITY
+ void reserve() _NOEXCEPT {reserve(0);}
+ _LIBCPP_INLINE_VISIBILITY
void shrink_to_fit() _NOEXCEPT {reserve();}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54992.175629.patch
Type: text/x-patch
Size: 1614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181128/6159cafd/attachment.bin>
More information about the libcxx-commits
mailing list