Will C++ ever get the possibility to just print the contents of an object like Rust does (with the automatic debug trait)? I am tired of writing my own print functions for random objects when debugging because the API developers did not bother to override the <<operator. One of those things that are hard to accept when coming back from Rust.
Formatting text in C++: Old and new ways
51–60 of 73 posts
Re: Formatting text in C++: Old and new ways
#52Earlier quoted context omitted.
Well you could write it as to (items | filter(shouldInclude) | transform(f)) if you really want to, but generally C++ programmers prefer to be explicit and include the namespaces.
>but generally C++ programmers prefer to be explicit and include the namespaces. why, though? Collisions in the stdlib? stdlib is too new to not be the default for these names?
From the docs:
namespace X
{
using ::f; // global f is now visible as ::X::f
using A::g; // A::g is now visible as ::X::g
}
void h()
{
X::f(); // calls ::f
X::g(); // calls A::g
}
Link to docs: https://en.cppreference.com/w/cpp/language/namespace#Using-d...Re: Formatting text in C++: Old and new ways
#53Will C++ ever get the possibility to just print the contents of an object like Rust does (with the automatic debug trait)? I am tired of writing my own print functions for random objects when debugging because the API developers did not bother to override the <<operator. One of those things that are hard to accept when coming back from Rust.
Not until we get reflection. And reflection efforts seem to be at an impasse, so I don’t imagine we will see it for a few years at least. I will add, though, that I’ve found copilot to be very handy when it comes to generating formatting. Last week I used it while writing fmt::formatter specialisations for a library with 50 structs, some having over 20 members. Writing all of them took about 10 minutes. I dare say th…
Re: Formatting text in C++: Old and new ways
#54Re: Formatting text in C++: Old and new ways
#55Why 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?
This question doesn't make sense for the context*. C++ is Ahead of Time, by design; there is nothing to "just in time" compile.
JIT (as a concept) only makes sense if you are, in some way, abstracting your code from native machine code (usually via some sort of VM, like Python or Java's), which the "system" languages (C, Rust, Zig, C++, etc) do not.
What I think you are trying to reference are "runtime optimizations"; in which case, the answer is probably no. Base and STD C++ are pretty conservative about what they put into the runtime. Extended runtimes like Windows' and glibc might do some conditional optimizations, however.
* Yes, some contrarian is going to point out a project like Cling or C++/CLI. This is why I'm being very clear about "context".
Re: Formatting text in C++: Old and new ways
#56Will C++ ever get the possibility to just print the contents of an object like Rust does (with the automatic debug trait)? I am tired of writing my own print functions for random objects when debugging because the API developers did not bother to override the <<operator. One of those things that are hard to accept when coming back from Rust.
Re: Formatting text in C++: Old and new ways
#57Re: Formatting text in C++: Old and new ways
#58Earlier 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.
(2) is a point I firmly agree with (though not everyone does), but it’s a hard one. Here’s the way I think about it. I don’t think I’m wrong but I’m absolutely open to being told otherwise. C++ is a language. It has a standard library. The library depends on the language, but the language shouldn’t depend on the library. This is because many applications cannot use the standard library, or parts of it. The conceptual…
Re: Formatting text in C++: Old and new ways
#59TIL C++ now has a third builtin way to format strings. Can't wait to not use it.
Re: Formatting text in C++: Old and new ways
#60Why 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?