-
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.
[348] - Did you know that C++26 changed arithmetic overloads of std::…
…to_string and std::to_wstring to use std::format?
- Loading branch information
1 parent
57309b2
commit b4f3dcf
Showing
4 changed files
with
74 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,3 @@ | |
<!-- START FEED --> | ||
</channel> | ||
</rss> | ||
|
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,46 @@ | ||
<details open><summary>Info</summary><p> | ||
|
||
* **Did you know that C++26 changed arithmetic overloads of std::to_string and std::to_wstring to use std::format?** | ||
|
||
* https://wg21.link/P2587 | ||
|
||
</p></details><details open><summary>Example</summary><p> | ||
|
||
```cpp | ||
int main() { | ||
setlocale(LC_ALL, "C"); | ||
std::cout << std::to_string(42); // prints 42 | ||
std::cout << std::to_string(.42); // prints 0.42 | ||
std::cout << std::to_string(-1e7); // prints -1e+07 | ||
} | ||
``` | ||
|
||
> https://godbolt.org/z/a7xMEq336 | ||
</p></details><details open><summary>Puzzle</summary><p> | ||
|
||
* **Can you add required `locale` to match expectations?** | ||
|
||
```cpp | ||
int main() { | ||
using namespace boost::ut; | ||
using std::literals::string_literals::operator""s; | ||
|
||
"locale.to_string (all.us)"_test = [] { | ||
// TODO | ||
expect("-1e+07"s == std::to_string(-1e7)); | ||
}; | ||
|
||
"locale.to_string (numeric.eu)"_test = [] { | ||
// TODO | ||
expect("1,23"s == std::to_string(1.23)); | ||
}; | ||
} | ||
``` | ||
|
||
> https://godbolt.org/z/jocqoM7xd | ||
</p></details> | ||
|
||
</p></details><details><summary>Solutions</summary><p> | ||
</p></details> |