Pointers don't need customized iterator behavior
Casey Carter

Created on 2019-10-07.00:00:00 last changed 4 months ago


Date: 2019-11-16.12:50:33

Proposed resolution:

This wording is relative to N4830.

[Drafting note: 3247 touches the same wording in [iterator.cust.move]; if both are resolved simultaneously the changes should be reconciled before passing them on to the Editor.]

  1. Modify [iterator.cust.move] as follows:

    (1.1) — iter_move(E), if that expression is valid, E has class or enumeration type and iter_move(E) is a well-formed expression with overload resolution performed in a context that does not include a declaration of ranges::iter_move.

  2. Modify [iterator.cust.swap] as follows:

    (4.1) — (void)iter_swap(E1, E2), if that expression is valid, either E1 or E2 has class or enumeration type and iter_swap(E1, E2) is a well-formed expression with overload resolution performed in a context that includes the declaration

    template<class I1, class I2>
    void iter_swap(I1, I2) = delete;
    and does not include a declaration of ranges::iter_swap. If the function selected by overload resolution does not exchange the values denoted by E1 and E2, the program is ill-formed with no diagnostic required.

Date: 2019-11-16.00:00:00

[ 2019-11-16 Issue Prioritization ]

Status to Tentatively Ready and priority to 0 after seven positive votes on the reflector.

Date: 2019-10-07.00:00:00

It is not intentional design that users may customize the behavior of ranges::iter_move ([iterator.cust.move]) and ranges::iter_swap ([iterator.cust.swap]) for pointers to program-defined type by defining e.g. iter_move(my_type*) or iter_swap(my_type*, my_type*) in a namespace associated with my_type. The intent of customization points is that users may define behavior for types they define, not that users may mess with the well-defined semantics for existing types like pointers.

We should forbid such silliness by constraining the "finds an overload via ADL" cases for customization points to only trigger with argument expressions of class or enumeration type. Note that WG21 made a similar change to ranges::swap shortly before merging it into the working draft to forbid users customizing behavior for pointers to program-defined types or arrays of program-defined types.

Date User Action Args
2020-02-24 16:02:59adminsetstatus: voting -> wp
2020-01-17 04:54:50adminsetstatus: ready -> voting
2019-11-16 12:50:33adminsetmessages: + msg10811
2019-11-16 12:50:33adminsetstatus: new -> ready
2019-10-07 21:12:50adminsetmessages: + msg10688
2019-10-07 00:00:00admincreate