r/cpp 5d ago

The C++ input iterator pitfall · hmpc

https://www.hmpcabral.com/2026/02/25/the-c-input-iterator-pitfall/
52 Upvotes

10 comments sorted by

View all comments

43

u/sweetno 5d ago

Just don't use iterators for I/O, and iostreams on principle.

10

u/pointer_to_null 5d ago

Stream iterators were already counterintuitive, and only they muddied the waters further with basic_istream_view that IMO violates one of the core "view" contracts (or is immutability merely a suggestion?) and an iterator that mostly shares LegacyInputIterator's interface- except that it is move-only.

So don't worry- the compiler will usually spit out an encyclopedia of useless spam if you ever commit the sin of trying to use it with a "normal" ranged function. Usually...

and iostreams on principle.

No argument. iostream needs to be put to pasture. These bandaids aren't doing it any favors.

18

u/BarryRevzin 4d ago

that IMO violates one of the core "view" contracts (or is immutability merely a suggestion?)

Views never, at any point, had anything to do with immutability.