-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[libc++][string] P3044R2: sub-string_view
from string
#147095
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
Open
H-G-Hristov
wants to merge
20
commits into
llvm:main
Choose a base branch
from
H-G-Hristov:hgh/libcxx/P3044R2-sub-string_view-from-string
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0510c78
WIP [libc++][string] P3044R2: sub-`string_view` from `string`
H-G-Hristov ad5e410
Renamed test
H-G-Hristov 14162bf
LLVM22
H-G-Hristov f9efc16
Updated test
H-G-Hristov 3dbebae
Fix the test!!!
H-G-Hristov 43e3c15
Address review comments
H-G-Hristov b6c564a
Addressed comments
H-G-Hristov 1482740
Addressed comments
H-G-Hristov 6dde7ee
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov 568336f
Fix CI
H-G-Hristov 22dae80
Merge branch 'hgh/libcxx/P3044R2-sub-string_view-from-string' of http…
H-G-Hristov b8ddff6
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov fb19c8a
Updated implementation and tests
H-G-Hristov 47fb941
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov 5f64a5a
Update libcxx/test/std/strings/string.view/string.view.ops/subview.pa…
H-G-Hristov d3eeeb4
Update some more
H-G-Hristov 67cc843
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov 292cb6c
Fixed `<version>`
H-G-Hristov ca61837
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov a36e4d2
Merge branch 'main' into hgh/libcxx/P3044R2-sub-string_view-from-string
H-G-Hristov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
libcxx/test/std/strings/basic.string/string.ops/string_substr/subview.pass.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++26 | ||
|
||
// <string> | ||
|
||
// constexpr basic_string_view<_CharT, _Traits> subview(size_type __pos = 0, size_type __n = npos) const; | ||
|
||
#include <cassert> | ||
#include <string> | ||
|
||
#include "constexpr_char_traits.h" | ||
#include "make_string.h" | ||
#include "min_allocator.h" | ||
#include "test_allocator.h" | ||
#include "test_macros.h" | ||
|
||
#define CS(S) MAKE_CSTRING(CharT, S) | ||
|
||
template <typename CharT, typename TraitsT, typename AllocT> | ||
constexpr void test() { | ||
std::basic_string<CharT, TraitsT, AllocT> s{CS("Hello cruel world!"), AllocT{}}; | ||
|
||
{ // With a default position and a character length. | ||
std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(); | ||
assert(sv == CS("Hello cruel world!")); | ||
} | ||
|
||
{ // With a explict position and a character length. | ||
std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(6, 5); | ||
assert(sv == CS("cruel")); | ||
} | ||
|
||
{ // From the beginning of the string with a explicit character length. | ||
std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(0, 5); | ||
assert(sv == CS("Hello")); | ||
} | ||
|
||
{ // To the end of string with the default character length. | ||
std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(12); | ||
assert(sv == CS("world!")); | ||
} | ||
|
||
{ // From the beginning to the end of the string with explicit values. | ||
std::same_as<std::basic_string_view<CharT, TraitsT>> decltype(auto) sv = s.subview(0, s.size()); | ||
assert(sv == CS("Hello cruel world!")); | ||
} | ||
} | ||
|
||
template <typename CharT> | ||
constexpr void test() { | ||
test<CharT, std::char_traits<CharT>, std::allocator<CharT>>(); | ||
test<CharT, std::char_traits<CharT>, min_allocator<CharT>>(); | ||
test<CharT, std::char_traits<CharT>, safe_allocator<CharT>>(); | ||
test<CharT, std::char_traits<CharT>, test_allocator<CharT>>(); | ||
|
||
test<CharT, constexpr_char_traits<CharT>, std::allocator<CharT>>(); | ||
test<CharT, constexpr_char_traits<CharT>, min_allocator<CharT>>(); | ||
test<CharT, constexpr_char_traits<CharT>, safe_allocator<CharT>>(); | ||
test<CharT, constexpr_char_traits<CharT>, test_allocator<CharT>>(); | ||
} | ||
|
||
constexpr bool test() { | ||
test<char>(); | ||
#ifndef TEST_HAS_NO_WIDE_CHARACTERS | ||
test<wchar_t>(); | ||
#endif | ||
#ifndef TEST_HAS_NO_CHAR8_T | ||
test<char8_t>(); | ||
#endif | ||
test<char16_t>(); | ||
test<char32_t>(); | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.