mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-24 20:29:39 +08:00
Implement P0966 - string::reserve should not shrink
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@347789 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -956,9 +956,11 @@ public:
|
|||||||
void resize(size_type __n, value_type __c);
|
void resize(size_type __n, value_type __c);
|
||||||
_LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
|
_LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
|
||||||
|
|
||||||
|
void reserve(size_type __res_arg);
|
||||||
_LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
|
_LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
|
||||||
|
|
||||||
void reserve(size_type __res_arg = 0);
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
void reserve() _NOEXCEPT {reserve(0);}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
void shrink_to_fit() _NOEXCEPT {reserve();}
|
void shrink_to_fit() _NOEXCEPT {reserve();}
|
||||||
_LIBCPP_INLINE_VISIBILITY
|
_LIBCPP_INLINE_VISIBILITY
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
// <string>
|
// <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 <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -44,6 +46,9 @@ test(S s, typename S::size_type res_arg)
|
|||||||
assert(s == s0);
|
assert(s == s0);
|
||||||
assert(s.capacity() >= res_arg);
|
assert(s.capacity() >= res_arg);
|
||||||
assert(s.capacity() >= s.size());
|
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
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
||||||
else
|
else
|
||||||
@@ -90,6 +95,7 @@ int main()
|
|||||||
test(s, 10);
|
test(s, 10);
|
||||||
test(s, 50);
|
test(s, 50);
|
||||||
test(s, 100);
|
test(s, 100);
|
||||||
|
test(s, 1000);
|
||||||
test(s, S::npos);
|
test(s, S::npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,6 +127,7 @@ int main()
|
|||||||
test(s, 10);
|
test(s, 10);
|
||||||
test(s, 50);
|
test(s, 50);
|
||||||
test(s, 100);
|
test(s, 100);
|
||||||
|
test(s, 1000);
|
||||||
test(s, S::npos);
|
test(s, S::npos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
<tr><td><a href="https://wg21.link/P0809R0">P0809R0</a></td><td>LWG</td><td>Comparing Unordered Containers</td><td>Jacksonville</td><td></td><td></td></tr>
|
<tr><td><a href="https://wg21.link/P0809R0">P0809R0</a></td><td>LWG</td><td>Comparing Unordered Containers</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/P0858R0">P0858R0</a></td><td>LWG</td><td>Constexpr iterator requirements</td><td>Jacksonville</td><td></td><td></td></tr>
|
<tr><td><a href="https://wg21.link/P0858R0">P0858R0</a></td><td>LWG</td><td>Constexpr iterator requirements</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/P0905R1">P0905R1</a></td><td>CWG</td><td>Symmetry for spaceship</td><td>Jacksonville</td><td></td><td></td></tr>
|
<tr><td><a href="https://wg21.link/P0905R1">P0905R1</a></td><td>CWG</td><td>Symmetry for spaceship</td><td>Jacksonville</td><td></td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/P0966R1">P0966R1</a></td><td>LWG</td><td><tt>string::reserve</tt> Should Not Shrink</td><td>Jacksonville</td><td></td><td></td></tr>
|
<tr><td><a href="https://wg21.link/P0966R1">P0966R1</a></td><td>LWG</td><td><tt>string::reserve</tt> Should Not Shrink</td><td>Jacksonville</td><td>Complete</td><td>8.0</td></tr>
|
||||||
|
|
||||||
<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
|
<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>
|
||||||
<tr><td><a href="https://wg21.link/P0019R8">P0019R8</a></td><td>LWG</td><td>Atomic Ref</td><td>Rapperswil</td><td></td><td></td></tr>
|
<tr><td><a href="https://wg21.link/P0019R8">P0019R8</a></td><td>LWG</td><td>Atomic Ref</td><td>Rapperswil</td><td></td><td></td></tr>
|
||||||
@@ -291,7 +291,7 @@
|
|||||||
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
|
<!-- <tr><td></td><td></td><td></td><td></td></tr> -->
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<p>Last Updated: 27-Nov-2018</p>
|
<p>Last Updated: 28-Nov-2018</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user