logoalt Hacker News

Neoclassical C++: segmented iterators revisited

36 pointsby ibobevlast Friday at 2:06 PM20 commentsview on HN

Comments

SuperV1234today at 10:52 AM

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.

willtemperleytoday at 8:07 AM

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.

show 5 replies
FpUsertoday at 8:21 AM

>"where does te average developer go to learn CPP "

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