Title
`std::midpoint` should not accept `const bool`
Status
wp
Section
[numeric.ops.midpoint]
Submitter
Jan Schultke

Created on 2025-05-21.00:00:00 last changed 1 month ago

Messages

Date: 2025-11-11.10:48:16

Proposed resolution:

This wording is relative to N5008.

  1. Modify [numeric.ops.midpoint] as indicated:

    template<class T>
      constexpr T midpoint(T a, T b) noexcept;
    

    -1- Constraints: `T` is an arithmetic type other than cv `bool`.

Date: 2025-11-11.10:48:16

[ Kona 2025-11-08; Status changed: Voting → WP. ]

Date: 2025-10-15.00:00:00

[ 2025-10-21; Reflector poll. ]

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

This requires template argument to be explicty specified, i.e. midpoint<const bool>. I would prefer to address all cv-qualified types at once, e.g. Constraints: remove_cv_t<T> is an arithmetic type other than `bool`."

"This is locally consistent with `gcd` and `lcm` which only exclude cv `bool`. [algorithms.requirements p15 makes it unspecified to use an explicit template argument list here, so midpoint<const bool> and midpoint<const int> are already unspecified, this issue just ensures that `const bool` is explicitly rejected, like `bool`."

Date: 2025-05-21.00:00:00

The constraints of the first overload of `std::midpoint` are as follows:

template<class T>
  constexpr T midpoint(T a, T b) noexcept;

-1- Constraints: `T` is an arithmetic type other than `bool`.

It does not appear intentional that `const bool` is supported considering that [numeric.ops.gcd] excludes cv `bool`.

More generally, it is questionable that cv-qualified arithmetic types aren't excluded in general, considering that [numeric.sat] excludes them with the "signed or unsigned integer type" constraint. However, tightening the constraints for these other functions seems evolutionary, not like fixing an obvious oversight, and so it likely requires a separate issue.

History
Date User Action Args
2025-11-11 10:48:16adminsetmessages: + msg15621
2025-11-11 10:48:16adminsetstatus: voting -> wp
2025-10-30 17:45:31adminsetstatus: ready -> voting
2025-10-21 10:13:46adminsetmessages: + msg15295
2025-10-21 10:13:46adminsetstatus: new -> ready
2025-05-24 09:46:59adminsetmessages: + msg14766
2025-05-21 00:00:00admincreate