<xutility>: Generic code cannot call ranges::advance(i, s) #907
Labels
bug
Something isn't working
LWG issue needed
A wording defect that should be submitted to LWG as a new issue
The specification of the iterator & sentinel overload of
ranges::advance
reads:The assignment optimization in 4.1 is just fine for callers with concrete types who can decide whether or not to call
advance
depending on the semantics of the assignment performed. However, since this assignment operation isn't part of theinput_or_output_iterator
orsentinel_for
requirements its semantics are unknown for arbitrary types. Effectively, generic code is forbidden to call this overload ofadvance
whenassignable_from<I&, S>
is satisfied and non-generic code must tread lightly.WG21 can correct this problem by either (1) making the assignment operation in question an optional part of the
sentinel_for
concept with well-defined semantics, or (2) instead requiringsame_as<I, S>
to trigger the assignment operation in bullet 4.1 above.S
issemiregular
, soi = std::move(s)
is certainly well-formed (and has well-defined semantics thanks tosemiregular
) whenI
andS
are the same type.I'll submit an issue to the LWG outlying the above two possible fixes. Until LWG decides how they want this fixed, we should implement the safer option (2) above.
The text was updated successfully, but these errors were encountered: