Date: Tue, 4 Mar 2025 09:07:04 -0300
By the way, it would be dangerous to mark this function as pure because you
don't know which types are going to be used on it.
What if a type has a non pure implementation of operator+, or copy/move
operators that might be involved?
Perhaps the operator is tracking calls with a global counter. Perhaps
memory is being allocated?
Em ter., 4 de mar. de 2025, 04:07, Tymi via Std-Proposals <
std-proposals_at_[hidden]> escreveu:
> 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.
>
> 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.
>
> pure member function shall be declared as const, otherwise, the program is
> ill-formed.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
don't know which types are going to be used on it.
What if a type has a non pure implementation of operator+, or copy/move
operators that might be involved?
Perhaps the operator is tracking calls with a global counter. Perhaps
memory is being allocated?
Em ter., 4 de mar. de 2025, 04:07, Tymi via Std-Proposals <
std-proposals_at_[hidden]> escreveu:
> 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.
>
> 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.
>
> pure member function shall be declared as const, otherwise, the program is
> ill-formed.
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2025-03-04 12:07:18