Every time I see "use ranges and algorithms!" examples, I am baffled that apparently, I am supposed to find inline double algorithm_call(std::span xs) noexcept { return std::accumulate( xs.begin(), xs.end(), 0.0, [](double acc, double volts) { auto mv = calibrated_mv(volts); auto err = residual(mv); return weighted_square(err) + acc; }); } more readable, concise, and easier on my eyes than inline double raw_loop(std:…
The first form is easier to send to 32 beefy cores or 1024 small CPUs or a Beowulf cluster or a GPU or people sitting in a room.
Trust your compiler: Modern C++
11–20 of 47 posts
Re: Trust your compiler: Modern C++
#12Re: Trust your compiler: Modern C++
#13Re: Trust your compiler: Modern C++
#14I’ve seen some terrible horrid nonsense from them and even the best compilers don’t use a third of the opcodes our modern CPUs boast of. Nobody understands the big compilers any more either, they’re all too huge. And soon AI will be “improving” hem too. You want to see a beautiful compiler? Look at Plan 9’s compiler suite. A man could understand and even build on that.
Re: Trust your compiler: Modern C++
#15Re: Trust your compiler: Modern C++
#16Earlier quoted context omitted.
The first form is easier to send to 32 beefy cores or 1024 small CPUs or a Beowulf cluster or a GPU or people sitting in a room.
Both of them have to be completely rewritten to make use of multiprocessing, so what exactly is the advantage?
Re: Trust your compiler: Modern C++
#17[flagged]
Quite funny comment on the vibe coding age.
Re: Trust your compiler: Modern C++
#18I’ve seen some terrible horrid nonsense from them and even the best compilers don’t use a third of the opcodes our modern CPUs boast of. Nobody understands the big compilers any more either, they’re all too huge. And soon AI will be “improving” hem too. You want to see a beautiful compiler? Look at Plan 9’s compiler suite. A man could understand and even build on that.
That’s not necessarily an indication of the weakness of compilers. It also could be an indication that hardware designers could leave out instructions.
X86, in particular, will have lots of them for backwards compatibility reasons (extreme example: the old 80-bit x87 FP stack)
There also are instructions that are expected to never get used by ‘normal’ compilers but cannot be removed because they only make sense in lower-level code such as those for switching between protection levels, implementing compare-and-swap, etc.
Re: Trust your compiler: Modern C++
#19Earlier quoted context omitted.
Both of them have to be completely rewritten to make use of multiprocessing, so what exactly is the advantage?
The first one too? Isn't that the map-reduce fork-join golden example of multiprocessing?
Re: Trust your compiler: Modern C++
#20Earlier quoted context omitted.
The first form is easier to send to 32 beefy cores or 1024 small CPUs or a Beowulf cluster or a GPU or people sitting in a room.
Both of them have to be completely rewritten to make use of multiprocessing, so what exactly is the advantage?
The actual equivalent might be something closer to:
inline double algorithm_call(std::span xs) noexcept {
return std::accumulate(
xs, 0.0,
[](double acc, double volts) {
auto mv = calibrated_mv(volts);
auto err = residual(mv);
return weighted_square(err) + acc;
});
}
(that is, without the boilerplate .begin and .end).Even that is enough to make ranges useful in my mind, but in a codebase which has started to integrate some functional programming techniques, there are also applications for things like views and transforms.
This can make it easier to reason about iteration pipelines in ways you might already be familiar with from POSIX.
That all said, it's C++ so sometimes the error messages get a lot more 'interesting' than they would have with STL-style iterators, especially when mixed with constexpr expressions as you might do with std::format or fmt libs.