Date: Sun, 12 Jan 2025 10:06:17 +0000
On Sun, 12 Jan 2025, 08:53 Simon Kraemer via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> I don't get your question.
> You are calling operator() on the return value of min()/lowest()/max()
> (see the double parenthesis?).
>
> This won't work for actual numerics, generally:
> <source>:12:36: error: expression cannot be used as a function
> 12 | std::numeric_limits<int>::min()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
> <source>:13:39: error: expression cannot be used as a function
> 13 | std::numeric_limits<int>::lowest()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
> <source>:14:36: error: expression cannot be used as a function
> 14 | std::numeric_limits<int>::max()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
>
> If you omit one of the parentheses, nothing is printed (as expected)
> https://godbolt.org/z/o7z6M7qje
>
> Could you please clarify?
>
It's an unnecessarily complicated way to show that numeric_limits returns
zero for unknown arithmetic-like types, or a value-initialized value for
arbitrary types. Using numeric_limits for non-numeric types doesn't seem
like an important use case, but it's still an odd API.
See https://wg21.link/p1841 for a stalled proposal to replace
numeric_limits with something better.
std-proposals_at_[hidden]> wrote:
> I don't get your question.
> You are calling operator() on the return value of min()/lowest()/max()
> (see the double parenthesis?).
>
> This won't work for actual numerics, generally:
> <source>:12:36: error: expression cannot be used as a function
> 12 | std::numeric_limits<int>::min()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
> <source>:13:39: error: expression cannot be used as a function
> 13 | std::numeric_limits<int>::lowest()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
> <source>:14:36: error: expression cannot be used as a function
> 14 | std::numeric_limits<int>::max()();
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
>
> If you omit one of the parentheses, nothing is printed (as expected)
> https://godbolt.org/z/o7z6M7qje
>
> Could you please clarify?
>
It's an unnecessarily complicated way to show that numeric_limits returns
zero for unknown arithmetic-like types, or a value-initialized value for
arbitrary types. Using numeric_limits for non-numeric types doesn't seem
like an important use case, but it's still an odd API.
See https://wg21.link/p1841 for a stalled proposal to replace
numeric_limits with something better.
Received on 2025-01-12 10:07:35