Neoclassical C++: segmented iterators revisited
32 points
1 day ago
| 3 comments
| boostedcpp.net
| HN
SuperV1234
1 hour ago
[-]
Very interesting, this is the first time I hear about segmented iterators and hierarchical algorithms.

I faced a similar issue myself when implementing a chunked vector a la `std::deque`, but opted for callback-based internal iteration, i.e.

    void ChunkedVector::forEach(auto&& f)
    {
        for (auto& chunk : chunks)
            for (auto& item : chunk) 
                if (f(item) == ControlFlow::Break)
                    return;
    }
Where `ControlFlow` is just:

    enum class [[nodiscard]] ControlFlow : bool
    {
        Continue,
        Break
    };
This is massively simpler to implement, and can model simpler algorithms such as `for_each`, `fill`, `transform`, `count`, `accumulate`.

It's sometimes inferior in terms of ergonomics, and cannot express more complicated algorithms or iteration patterns (e.g. partial range, going backwards), but so far it has served me well.

Just something to consider if implementation simplicity is the priority and there's no need for a very generic suite of algorithms.

reply
willtemperley
4 hours ago
[-]
Genuine question, where does te average developer go to learn CPP in 2026? Despite the usual complaints it’s alive and well and Rust will not replace it.

CPP has become infinitely easier to write for me. That’s an exact figure, my total output of usable CPP lines was zero prior to LLMs.

I do however need to at least be able to write basic CPP to evaluate the code I’m generating. It’s just so hard to comb through all the bad and over complicated code out there, bad advice and outdated opinions.

reply
ozgrakkurt
1 hour ago
[-]
Read Bjarne Stroustrup’s intro to programming book and then read other books.

find more books from additional readings sections of books you end up liking.

Don’t use LLM for learning as it is useless compared to searching amazon or doing general web search to find books.

You can recursively learn anything you need by finding books about needed subjects.

reply
tcfhgj
2 hours ago
[-]
> Despite the usual complaints it’s alive and well and Rust will not replace it.

to some degree it is already being replaced:

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj...

source: https://blog.google/security/rust-in-android-move-fast-fix-t...

reply
willtemperley
21 minutes ago
[-]
> We adopted Rust for its security and are seeing a 1000x reduction in memory safety vulnerability density compared to Android’s C and C++ code.

This is a pretty poor post. It’s impossible to see what exactly they’re comparing but they seem to be comparing post LLM code to pre LLM code.

reply
arcadialeak
1 hour ago
[-]
Why does any mention of C++ nowadays turn into a Rust debate? These can coexist even in a single project via C ABI. Also, despite the vast syntax and semantic differences, an experienced dev will be able to apply most of their knowledge from one to the other.
reply
willtemperley
6 minutes ago
[-]
My fault for mentioning Rust (perhaps I did it because it’s vaguely amusing watching Rust maximalists flex).

Just to add to the bait, I find CPP libraries much more terse and functional, Rust libs tend towards over complexity and feature flexing.

reply
bregma
57 minutes ago
[-]
It's because crowing about Rust is like sending dick pics. I suspect it's the same part of the brain responsible with the same neural pathways stimulated.
reply
FpUser
1 hour ago
[-]
>"Why does any mention of C++ nowadays turn into a Rust debate?"

Because for most developers language is a religion rather than just a tool.

reply
twic
27 minutes ago
[-]
If a tool had been replaced by a better tool, wouldn't it be natural to discuss that?
reply
arcadialeak
2 hours ago
[-]
Since you are already making use of LLMs, you could also ask questions about the code that it produces. I've been asking Google's AI overview and Deepseek while doing my first ever C++26 project, usually not to produce any code but to give advice or list possible approaches to implementing a feature. It's a very slow path, to the point that my project has currently more git commits than lines of code, but I'm convinced that it will pay off in the long run.
reply
rbancroft
43 minutes ago
[-]
Cppreference.com is my favorite resource for up to date info.
reply
pwdisswordfishq
2 hours ago
[-]
reply
FpUser
3 hours ago
[-]
>"where does te average developer go to learn CPP "

ain't nothing better than books and doing some real project

reply