-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[354] - Did you know that C++23 added range
string_view
constructor?
- Loading branch information
1 parent
c3eedd1
commit a7fc91f
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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,36 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* **Did you know that C++23 added range `string_view` constructor?** | ||
|
||
* https://wg21.link/P1989 | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
constexpr std::string text = "Hello, World!"; | ||
constexpr std::string_view view(text.c_str() + 7, 5); | ||
static_assert(view == std::string_view{"World"}); | ||
``` | ||
> https://godbolt.org/z/GYfWxPc17 | ||
</p></details><details open><summary>Puzzle</summary><p> | ||
* **Can you implement `buffer` with explicit conversion to string_view?** | ||
```cpp | ||
template<auto N> | ||
struct buffer; // TODO | ||
constexpr buffer<42> b; | ||
static_assert(42 == std::string_view{b}.size()); | ||
static_assert(&b.data[0] == std::string_view{b}.begin()); | ||
static_assert(&b.data[42] == std::string_view{b}.end()); | ||
``` | ||
|
||
> https://godbolt.org/z/hKjo8Pr88 | ||
</p></details> | ||
|
||
</p></details><details><summary>Solutions</summary><p> | ||
</p></details> |