Title
The first template argument of `std::saturating_cast` must be specifiable
Status
new
Section
[numeric.sat.cast]
Submitter
Jiang An

Created on 2026-06-02.00:00:00 last changed 1 week ago

Messages

Date: 2026-06-13.12:27:45

Proposed resolution:

This wording is relative to N5046.

  1. Modify [numeric.sat.cast] as indicated:

    template<class R, class T>
      constexpr R saturating_cast(T x) noexcept;
    

    -1- Constraints: `R` and `T` are signed or unsigned integer types ([basic.fundamental]).

    -2- Returns: If `x` is representable as a value of type `R`, `x`; otherwise, either the largest or smallest representable value of type `R`, whichever is closer to the value of `x`.

    -?- Remarks: An invocation may explicitly specify an argument for the template parameter `R`.

Date: 2026-06-02.00:00:00

Currently, [algorithms.requirements]/15 allows implementations to reject explicitly specifying template arguments for algorithms. Unfortunately, `std::saturating_cast` is also an algorithm as it is specifying in the "Algorithms library" chapter, and its first template argument must be explicitly specified. Without being "explicitly stated otherwise", `std::saturating_cast` is effectively unusable.

History
Date User Action Args
2026-06-13 12:27:45adminsetmessages: + msg16433
2026-06-02 00:00:00admincreate