neonxc
neonxc

Reputation: 860

Why is difference_type part of std::weakly_incrementable concept?

I'm trying to find out the significance of the difference_type member for the satisfaction of std::weakly_incrementable concept. I'm currently defining a class satisfying std::output_iterator and have nothing in the domain to attach this type to (and struggling to find a use case for it).

I've tracked the root to n3351 paper and yet haven't found the actual reason there. Why did the commitee choose to put it this place in the hierarchy instead of std::input_iterator for example?

Upvotes: 4

Views: 648

Answers (1)

Caleth
Caleth

Reputation: 63059

It's used by ranges::advance et.al.

For an output iterator who's ++ is a no-op, it's fine to define it as whichever signed integer type you like. I'd recommend std::ptrdiff_t. See also: std::ostream_iterator::difference_type

Upvotes: 2

Related Questions