I'm reading ranges::distance
source and don't get the idea that:
struct __distance_fn
final?void operator&() const = delete
(source)I know that a final class has no derived classes, and the unary &
is to get a pointer (or something alike) of an object. But I can't comprehend what they really do here with ranges::distance
.
Same case for ranges::advance/prev/next
, while other functors don't have such details, e.g. ranges::begin.
ranges::begin
(and other functors) have final
or deleted operator &
?ranges::next
is a so-called niebloid, unlike customization point objects (CPO), they are not function objects.
To mimic their characteristics and prevent them from being misused as objects, this commit in libstdc++ added final
and deleted oeprator&
to them so that it is not possible to derive from them and take their addresses.
On the other hand, ranges::begin
is specified as CPO in the standard which is a function object that can be copied freely.
There is also a paper P3136: Retiring niebloids that turns niebloids into CPOs to remove their annoying non-object nature.