Formatting text in C++: Old and new ways
11–20 of 73 posts
Re: Formatting text in C++: Old and new ways
#12I find it disappointing that cpp20 still doesn't have a solution that is more convenient than good ol printf (except for memory safety). Another example would be convenient list comprehension, convenient maps wihout juggling around with tuples, first(), second(), at()...
Maps have been improved quite a bit. For example, if you have a std::map , you can iterate over it like this: for (auto [s, n]: my_map) { // s = string key, n = int value } You can test for membership: if (my_map.contains(“foo”)) { /* do something * } Although I still usually use find because if the key is in the map, I probably want the value. You can use initialization lists with them too: std::map my_map = { { “on…
for (auto [s, n]: my_map)
copies all the data needlessly, better to use for (const auto& [s, n]: my_map)Re: Formatting text in C++: Old and new ways
#13I find it disappointing that cpp20 still doesn't have a solution that is more convenient than good ol printf (except for memory safety). Another example would be convenient list comprehension, convenient maps wihout juggling around with tuples, first(), second(), at()...
Re: Formatting text in C++: Old and new ways
#14Earlier quoted context omitted.
Maps have been improved quite a bit. For example, if you have a std::map , you can iterate over it like this: for (auto [s, n]: my_map) { // s = string key, n = int value } You can test for membership: if (my_map.contains(“foo”)) { /* do something * } Although I still usually use find because if the key is in the map, I probably want the value. You can use initialization lists with them too: std::map my_map = { { “on…
for (auto [s, n]: my_map) copies all the data needlessly, better to use for (const auto& [s, n]: my_map)
Re: Formatting text in C++: Old and new ways
#15I find it disappointing that cpp20 still doesn't have a solution that is more convenient than good ol printf (except for memory safety). Another example would be convenient list comprehension, convenient maps wihout juggling around with tuples, first(), second(), at()...
Re: Formatting text in C++: Old and new ways
#16Re: Formatting text in C++: Old and new ways
#17I find it disappointing that cpp20 still doesn't have a solution that is more convenient than good ol printf (except for memory safety). Another example would be convenient list comprehension, convenient maps wihout juggling around with tuples, first(), second(), at()...
For list comprehension, we have (C++23): `std::ranges::to (items | std::views::filter(shouldInclude) | std::views::transform(f))` it’s not quite `[f(x) for x in items if shouldInclude(x)]` but it’s the same idea.
Re: Formatting text in C++: Old and new ways
#18I find it disappointing that cpp20 still doesn't have a solution that is more convenient than good ol printf (except for memory safety). Another example would be convenient list comprehension, convenient maps wihout juggling around with tuples, first(), second(), at()...
Maps have been improved quite a bit. For example, if you have a std::map , you can iterate over it like this: for (auto [s, n]: my_map) { // s = string key, n = int value } You can test for membership: if (my_map.contains(“foo”)) { /* do something * } Although I still usually use find because if the key is in the map, I probably want the value. You can use initialization lists with them too: std::map my_map = { { “on…
Re: Formatting text in C++: Old and new ways
#19Re: Formatting text in C++: Old and new ways
#20They dropped locale support for `std::to_chars` so hopefully they can be turned off for `std::format` too