Title
It's unclear whether numeric_limits can be specialized by users
Status
new
Section
[numeric.limits.general]
Submitter
Christopher Di Bella

Created on 2023-04-14.00:00:00 last changed 18 months ago

Messages

Date: 2023-05-24.14:33:00

Proposed resolution:

This wording is relative to N4944.

[Drafting Note: Two mutually exclusive options are prepared, depicted below by Option A and Option B, respectively.]

Option A: (This assumes that the above described scenario is intended to be supported)

  1. Add the following new paragraph at the end of [numeric.limits.general] as indicated:

    [Drafting Note: The particular wording form "emulating an arithmetic type" has been borrowed from Table 99 — Cpp17Clock requirements [tab:time.clock] and [time.duration.general] p2, respectively.]

    -?- The numeric_limits template may be specialized for program-defined types emulating arithmetic types.

Option B: (This assumes that the above described scenario is not intended to be supported)

  1. Add the following new paragraph at the end of [numeric.limits.general] as indicated:

    [Drafting Note: The particular wording form has been borrowed from [coroutine.handle.general] p2 and [allocator.traits.general] p1, respectively.]

    -?- If a program declares an explicit or partial specialization of numeric_limits, the program is ill-formed, no diagnostic required.

Date: 2023-05-15.00:00:00

[ 2023-05-24; Reflector poll ]

Set priority to 3 after reflector poll.

Several votes for Tentatively Ready with Option A, but a request to consider LWG 3923 first/instead of this one.

Date: 2023-04-15.19:47:45

[namespace.std]/p2 notes that "unless explicitly prohibited", a user may conditionally specialize any class template for program-defined types. [numeric.limits.general]/p1 doesn't explicitly prohibit this, but it does create a bit of a grey area with its wording because it describes numeric_limits as a class template describing "the implementation's representation" of "the arithmetic types".

Since this type is about what the implementation provides, and about arithmetic types only, it's not clear whether a user can specialize it for their own library type such as ns::int256. ns::int256 isn't an arithmetic type (despite resembling one), so one can interpret [namespace.std]/p2's (b) condition to mean that numeric_limits<ns::int256> needs to be explicitly specialized as if it were the primary template.

Daniel:

This issue has overlap with LWG 3923.

History
Date User Action Args
2023-05-24 14:33:00adminsetmessages: + msg13572
2023-04-15 16:43:18adminsetmessages: + msg13524
2023-04-14 00:00:00admincreate