C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::arithmetic (concept)

From: Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>
Date: Sat, 12 Apr 2025 08:18:00 +0200
I agree with Jens here. While I have occasionally made a similar concept in
code, I have ultimately been wanting to model something else than what
`std::is_arithmetic_v` brings. For example, I would need a concept that
would allow floating points, regular integers _and_ fixed point library
types, but not e.g. std::complex. `arithmetic` would not satisfy that. A
concept that represents "numbers that can be categorized as a subset of
real numbers", and I think that is not very easy to model as a standard
concept. And if you need to make your own concepts anyway then I don't see
much benefit from a std::arithmetic concept.

And as Jens is implying, the concept must be defined as:
template<typename T>
concept arithmetic = integral<T> || floating_point<T>;

// Robin

On Sat, Apr 12, 2025, 08:05 Jens Maurer via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
>
> On 12/04/2025 07.41, Tymi via Std-Proposals wrote:
> > Seems like that concept is missing, I would like to have it.
>
> Plausible, near-real-world use-cases, please?
> What can you meaningfully do with a type that is "arithmetic",
> as opposed to one satisfying one of the more specialized
> concepts?
>
> > We already have std::integral anyway... And std::is_arithmetic...
> >
> > Possible implementation:
> > ```cpp
> > template <typename T>
> > concept arithmetic = is_arithmetic_v<T>;
> > ```
>
> Should "integral" maybe subsume "arithmetic" for purposes
> of partial ordering? That seems eminently plausible.
> But your definition doesn't work for that.
>
> > Yeah it would be zero WG21 work and little SG work I guess..
>
> What's the basis for that "zero" guess?
>
> Any library-related paper needs to pass through LEWG and LWG
> and eventually plenary.
>
> Jens
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-04-12 06:18:14