Earlier quoted context omitted.
That's why some newer languages have 'const are the default'.
I'm pretty sure it's the reference that makes the data not be copied.
Formatting text in C++: Old and new ways
31–40 of 73 posts
Re: Formatting text in C++: Old and new ways
#32Something else to consider is compile time versus runtime validation with formatting libraries, e.g. due to passing the wrong number or type of arguments. The Abseil str_format library does compile time validation for both when possible: https://abseil.io/docs/cpp/guides/format
Re: Formatting text in C++: Old and new ways
#33Earlier quoted context omitted.
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.
To be honest, if that's the notation, i will not be very eager to jump on cpp23. That said, I admire people who's minds stay open for c++ improvements and make that effort.
to(items | filter(shouldInclude) | transform(f))
if you really want to, but generally C++ programmers prefer to be explicit and include the namespaces.Re: Formatting text in C++: Old and new ways
#34Earlier quoted context omitted.
Nothing but (1) notation wise not very different from the old printf which is looked down upon. (2) f"{name}'s hobby is {hobby} " would read like a novel and there a lot less comma seperated arguments. (3) std::format is quite a lot of characters to type for something so ubiquitous.
Typically, you'd just `using namespace std` on top of you file. Afterwards calls to `format` have the exact same length as `printf`.
Re: Formatting text in C++: Old and new ways
#35Earlier quoted context omitted.
Nothing but (1) notation wise not very different from the old printf which is looked down upon. (2) f"{name}'s hobby is {hobby} " would read like a novel and there a lot less comma seperated arguments. (3) std::format is quite a lot of characters to type for something so ubiquitous.
Typically, you'd just `using namespace std` on top of you file. Afterwards calls to `format` have the exact same length as `printf`.
using fmt = std::format
and then use fmt(...) as the function call.... at least that the current advice AIUI.
Re: Formatting text in C++: Old and new ways
#36Why do execution times drop so drastically with increasing number of iterations? Shouldn’t the caches be filled after one iteration already? There is no JIT in C++, or is it?
Of course, it isn't able to do quite as much as a VM running in software (because fixed buffers for everything, etc.), but even so...
Re: Formatting text in C++: Old and new ways
#37Re: Formatting text in C++: Old and new ways
#38Re: Formatting text in C++: Old and new ways
#39Earlier quoted context omitted.
Nothing but (1) notation wise not very different from the old printf which is looked down upon. (2) f"{name}'s hobby is {hobby} " would read like a novel and there a lot less comma seperated arguments. (3) std::format is quite a lot of characters to type for something so ubiquitous.
Typically, you'd just `using namespace std` on top of you file. Afterwards calls to `format` have the exact same length as `printf`.