[libcxx-commits] [libcxx] [libc++][string] P3044R2: sub-`string_view` from `string` (PR #147095)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 1 10:41:48 PDT 2025
================
@@ -46,79 +56,101 @@ void test1(std::basic_string_view<CharT> sv, std::size_t n, size_t pos) {
assert(sv[pos + i] == sv1[i]);
}
-template <typename CharT>
-void test(const CharT* s) {
- typedef std::basic_string_view<CharT> string_view_t;
+template <typename CharT, typename Test<CharT>::Sub TestSub>
+void testCases(const CharT* s) {
+ std::basic_string_view<CharT> sv(s);
- string_view_t sv1(s);
+ testDetail<CharT, TestSub>(sv, 0, 0);
+ testDetail<CharT, TestSub>(sv, 1, 0);
+ testDetail<CharT, TestSub>(sv, 20, 0);
+ testDetail<CharT, TestSub>(sv, sv.size(), 0);
- test1(sv1, 0, 0);
- test1(sv1, 1, 0);
- test1(sv1, 20, 0);
- test1(sv1, sv1.size(), 0);
+ testDetail<CharT, TestSub>(sv, 100, 3);
- test1(sv1, 0, 3);
- test1(sv1, 2, 3);
- test1(sv1, 100, 3);
+ testDetail<CharT, TestSub>(sv, 0, std::basic_string_view<CharT>::npos);
+ testDetail<CharT, TestSub>(sv, 2, std::basic_string_view<CharT>::npos);
+ testDetail<CharT, TestSub>(sv, sv.size(), std::basic_string_view<CharT>::npos);
- test1(sv1, 0, string_view_t::npos);
- test1(sv1, 2, string_view_t::npos);
- test1(sv1, sv1.size(), string_view_t::npos);
+ testDetail<CharT, TestSub>(sv, sv.size() + 1, 0);
+ testDetail<CharT, TestSub>(sv, sv.size() + 1, 1);
+ testDetail<CharT, TestSub>(sv, sv.size() + 1, std::basic_string_view<CharT>::npos);
+}
- test1(sv1, sv1.size() + 1, 0);
- test1(sv1, sv1.size() + 1, 1);
- test1(sv1, sv1.size() + 1, string_view_t::npos);
+template <typename CharT>
+void testSubs(const CharT* s) {
+ testCases<CharT, &std::basic_string_view<CharT>::substr>(s);
+#if TEST_STD_VER >= 26
+ testCases<CharT, &std::basic_string_view<CharT>::subview>(s);
+#endif // TEST_STD_VER >= 26
----------------
ldionne wrote:
```suggestion
#endif
```
Not needed for such a small block
https://github.com/llvm/llvm-project/pull/147095
More information about the libcxx-commits
mailing list