News for hackers. Stuff that matters.
Re:Writing a custom iterator in modern C++ by millstone on Sunday December 20, 2020 @11:01PM (#25492016)
Iterators are inconsistent, but this plays to the strengths of C++'s duck-typed generics. The same code can either copy or insert, depending on whether you use std::begin or std::back_inserter; this isn't principled but it's powerful.

The "six types of iterators" overstates it. You don't need to sweat those details unless you are writing boost or something. Just add what you need.

I miss C++ iterators in other languages. For example, in Rust it's hard to talk about "a position in a String" which may be advanced or retreated. Usually you give up, use an integer index, and this is much worse.

Re:Writing a custom iterator in modern C++ by Tyr42 on Monday December 21, 2020 @12:15AM (#25492321)
Backing up a utf8 stream is nontrivial though.
Re:Writing a custom iterator in modern C++ by millstone on Monday December 21, 2020 @01:31AM (#25492602)
This is an interesting point. Walking backwards through a UTF8 byte stream is easy: just look for the next non-continuation byte, and Rust really can do this, though the API is buried under `str.chars().rev()`.

C++ is structured around iterators that point into; this enables e.g. writing into the guts of a std::map but not the guts of a std::string if you care about Unicode, since the write might change the string's byte length.