Date: Tue, 4 Mar 2025 08:40:20 +0100
On 04/03/2025 08.07, Tymi via Std-Proposals wrote:
> Some functions have no side effects, and while they can be often optimised, the compiler is not aware of that.
> Consider this example:
> ```cpp
> template <std::arithmetic T> constexpr T(const T a, const T b) { return a + b; }
> ```
> That function could be declared as pure, or in other words, produces no side effects.
If the function is inline (as shown above), the optimizer already has all
the information it needs, and any "pure" declaration won't change much.
> I think this is a great way to optimise frequent calls, such as a pure function's result can be cached for the same arguments provided.
> Diagnostics: if a pure function has side effects, the compiler shall issue a warning and calling that function is undefined.
What is a "side effect"? We need a clear definition so that the rules
in the standard are well-defined. The definition of "side effect" that
we already have is likely undesirable.
Jens
> pure member function shall be declared as const, otherwise, the program is ill-formed.
>
>
> Some functions have no side effects, and while they can be often optimised, the compiler is not aware of that.
> Consider this example:
> ```cpp
> template <std::arithmetic T> constexpr T(const T a, const T b) { return a + b; }
> ```
> That function could be declared as pure, or in other words, produces no side effects.
If the function is inline (as shown above), the optimizer already has all
the information it needs, and any "pure" declaration won't change much.
> I think this is a great way to optimise frequent calls, such as a pure function's result can be cached for the same arguments provided.
> Diagnostics: if a pure function has side effects, the compiler shall issue a warning and calling that function is undefined.
What is a "side effect"? We need a clear definition so that the rules
in the standard are well-defined. The definition of "side effect" that
we already have is likely undesirable.
Jens
> pure member function shall be declared as const, otherwise, the program is ill-formed.
>
>
Received on 2025-03-04 07:40:23