Title
Unclear wording for precision in chrono-format-spec
Status
c++23
Section
[time.format]
Submitter
Jonathan Wakely

Created on 2022-12-14.00:00:00 last changed 4 months ago

Messages

Date: 2024-01-29.16:34:32

Proposed resolution:

This wording is relative to N4917.

  1. Modify [time.format] as indicated:

    -1- […]

    The productions fill-and-align, width, and precision are described in [format.string]. Giving a precision specification in the chrono-format-spec is valid only for types that are specializations of std::chrono::duration types where the representation type Rep isfor which the nested typedef-name rep denotes a floating-point type. For all other Rep types, an exception of type format_error is thrown if the chrono-format-spec contains a precision specification. […]

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]

Date: 2023-01-15.00:00:00

[ 2023-01-06; Reflector poll ]

Set status to Tentatively Ready after eight votes in favour during reflector poll.

Date: 2022-12-14.00:00:00

[time.format] says:

[…] Giving a precision specification in the chrono-format-spec is valid only for std::chrono::duration types where the representation type Rep is a floating-point type. For all other Rep types, an exception of type format_error is thrown if the chrono-format-spec contains a precision specification. […]

It's unclear whether the restriction in the first sentence applies to all types, or only duration types. The second sentence seems to restrict the exceptional case to only types with a non-floating-point Rep, but what about types with no Rep type at all?

Can you use a precision with sys_time<duration<float>>? That is not a duration type at all, so does the restriction apply? What about hh_mm_ss<duration<int>>? That's not a duration type, but it uses one, and its Rep is not a floating-point type. What about sys_info? That's not a duration and doesn't have any associated duration, or Rep type.

What is the intention here?

Less importantly, I don't like the use of Rep here. That's the template parameter of the duration class template, but that name isn't in scope here. Why aren't we talking about the duration type's rep type, which is the public name for it? Or about a concrete specialization duration<Rep, Period>, instead of the class template?

The suggested change below would preserve the intended meaning, but with more … precision.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 10:17:57adminsetmessages: + msg13367
2023-02-13 10:17:57adminsetstatus: voting -> wp
2023-02-06 15:33:48adminsetstatus: ready -> voting
2023-01-06 14:39:35adminsetmessages: + msg13169
2023-01-06 14:39:35adminsetstatus: new -> ready
2022-12-17 14:12:32adminsetmessages: + msg13159
2022-12-14 00:00:00admincreate