C++ Logo


Advanced search

[std-proposals] Checked integral Math library?

From: Tor Shepherd <tor.aksel.shepherd_at_[hidden]>
Date: Mon, 1 Apr 2024 13:05:50 -0400

I was wondering if there are any in-flight proposals to add integral math
functions such as the ones rust has, for example

T std::checked_add(T lhs, T rhs); // might throw or return std::unexpected
T std::saturating_add(T lhs, T rhs) noexcept;
T std::unsafe_add(T lhs, T rhs) noexcept; // prevents integral promotion

The benefit of something like this would be that it would be trivial to
then write a clang tidy warning which automatically refactors code to
suggest different versions of these functions and bring us one step closer
to safe C++ with tooling.

Please excuse if this is commonly proposed or has already been settled 😅

Tor Shepherd

M.S. Robotics | University of Michigan, Ann Arbor
B.S. Mechanical Engineering | University of Illinois, Urbana-Champaign
LinkedIn <https://www.linkedin.com/in/tor-shepherd-294644148/> | GitHub

Received on 2024-04-01 17:06:03