Title
Domain of ranges::ssize(E) doesn't match ranges::size(E)
Status
c++23
Section
[range.prim.ssize]
Submitter
Jonathan Wakely

Created on 2019-02-19.00:00:00 last changed 5 months ago

Messages

Date: 2020-11-09.21:40:50

Proposed resolution:

This wording is relative to N4861.

  1. Add a new paragraph after paragraph 1 in [ranges.syn]:

    [Drafting note: The following does not define an analog to-signed-like for to-unsigned-like since we don't need it at this time.]

    -?- Also within this Clause, make-signed-like-t<X> for an integer-like type X denotes make_signed_t<X> if X is an integer type; otherwise, it denotes a corresponding unspecified signed-integer-like type of the same width as X.
  2. Modify [range.prim.ssize] as indicated:

    -1- The name ranges::ssize denotes a customization point object ([customization.point.object]). The expression ranges::ssize(E) for a subexpression E of type T is expression-equivalent to:

    (1.1) — If range_difference_t<T> has width less than ptrdiff_t, static_cast<ptrdiff_t>(ranges::size(E)).

    (1.2) — Otherwise, static_cast<range_difference_t<T>>(ranges::size(E)).

    -?- Given a subexpression E with type T, let t be an lvalue that denotes the reified object for E. If ranges::size(t) is ill-formed, ranges::ssize(E) is ill-formed. Otherwise let D be make-signed-like-t<decltype(ranges::size(t))>, or ptrdiff_t if it is wider than that type; ranges::ssize(E) is expression-equivalent to static_cast<D>(ranges::size(t)).

Date: 2020-11-09.00:00:00

[ 2020-11-09 Approved In November virtual meeting. Status changed: Tentatively Ready → WP. ]

Date: 2020-08-15.00:00:00

[ 2020-08-21; Issue processing telecon: Tentatively Ready ]

Date: 2020-07-31.00:00:00
Per discussion on the reflector.

[ 2020-07-31 Casey provides updated wording ]

Per discussion on the reflector.
Date: 2020-07-22.00:00:00

[ 2020-07-22 Casey provides wording ]

Previous resolution [SUPERSEDED]:

This wording is relative to N4861.

  1. Add a new paragraph after paragraph 1 in [ranges.syn]:

    -?- Also within this clause, make-signed-like-t<X> for an integer-like type X denotes make_signed_t<X> if X is an integer type; otherwise, it denotes a corresponding unspecified signed-integer-like type of the same width as X.
  2. Modify [range.prim.ssize] as indicated:

    -1- The name ranges::ssize denotes a customization point object ([customization.point.object]). The expression ranges::ssize(E) for a subexpression E of type T is expression-equivalent to:

    (1.1) — If range_difference_t<T> has width less than ptrdiff_t, static_cast<ptrdiff_t>(ranges::size(E)).

    (1.2) — Otherwise, static_cast<range_difference_t<T>>(ranges::size(E)).

    -?- Given a subexpression E with type T, let t be an lvalue that denotes the reified object for E. If ranges::size(t) is ill-formed, ranges::ssize(E) is ill-formed. Otherwise, let D be the wider of ptrdiff_t or decltype(ranges::size(t)); ranges::ssize(E) is expression-equivalent to static_cast<make-signed-like-t<D>>(ranges::size(t)).

Date: 2020-03-11.00:00:00

[ 2020-03-11 Issue Prioritization ]

Priority to 2 after reflector discussion.

Date: 2019-02-19.00:00:00

ranges::size(E) works with a non-range for which E.size() or size(E) is valid. But ranges::ssize(E) requires the type range_difference_t which requires ranges::begin(E) to be valid. This means there are types for which ranges::size(E) is valid but ranges::ssize(E) is not.

Casey's reaction to this is:

I believe we want ranges::ssize to work with any argument that ranges::size accepts. That suggest to me that we're going to need make-signed-like-t<T> after all, so we can "Let E be an expression, and let D be the wider of ptrdiff_t or decltype(ranges::size(E)). Then ranges::ssize(E) is expression-equivalent to static_cast<make-signed-like-t<D>>(ranges::size(E))." Although this wording is still slightly icky since D isn't a valid type when ranges::size(E) isn't a valid expression, I think it's an improvement?

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 21:40:50adminsetmessages: + msg11560
2020-11-09 21:40:50adminsetstatus: ready -> wp
2020-08-21 20:28:46adminsetmessages: + msg11452
2020-08-21 20:28:46adminsetstatus: new -> ready
2020-08-01 03:51:09adminsetmessages: + msg11421
2020-07-22 04:17:37adminsetmessages: + msg11408
2020-07-22 04:17:37adminsetmessages: + msg11407
2020-03-11 18:56:33adminsetmessages: + msg11161
2019-02-19 00:00:00admincreate