hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

8.9K
active users

Šimon Tóth

When implementing generic code that should operate on top of ranges, the std::advance and std::distance utilities can help.

Both utilities provide constant complexity for random access ranges and fallback to linear operations.

Compiler Explorer link: compiler-explorer.com/z/KGda1s

@simontoth I think if one is using ranges, std::ranges::advance and std::ranges::distance are wanted. They fix up some things, are constrained to concepts, and work with things like sentinels

@beached_whale Yeah, it's a good default to go for the range versions, except for std::less<> (and the other functors) since the range versions are badly over-constrained.