Date: Tue, 15 Apr 2025 13:38:37 +0200
On 15/04/2025 02:21, Frederick Virchanza Gotham via Std-Proposals wrote:
> Then someone comes along and writes one of those arbitrary precision
> math libraries, and they have a class called "HugeInt", and they want
> to tell the compiler that "HugeInt" is an arithmetic type, so in the
> header file for "HugeInt", they write a line something like as
> follows:
>
> concept arithmetic << HugeInt;
>
> which changes the "std::arithmetic" concept as though it had
> originally been written:
>
> template <typename T>
> concept arithmetic = is_arithmetic_v<T> || is_same_v<T, HugeInt>;
>
> Of course, this would mean that "std::arithmetic" would have different
> definitions in different translation units, but it wouldn't matter
> because the translation units that don't include the HugeInt header
> file won't ever use the HugeInt type.
If one wanted to go in that direction, this is doable (and indeed done)
today without requiring any fancy language extensions:
> // customization point as per [namespace.std], with semantic requirements
> template <typename T>
> constexpr bool enable_arithmetic = false;
>
> template <typename T>
> concept arithmetic = is_arithmetic_v<T> || enable_arithmetic<T>;
For instance see enable_view, enable_borrowed_range.
My 2 c,
--
Giuseppe D'Angelo
> Then someone comes along and writes one of those arbitrary precision
> math libraries, and they have a class called "HugeInt", and they want
> to tell the compiler that "HugeInt" is an arithmetic type, so in the
> header file for "HugeInt", they write a line something like as
> follows:
>
> concept arithmetic << HugeInt;
>
> which changes the "std::arithmetic" concept as though it had
> originally been written:
>
> template <typename T>
> concept arithmetic = is_arithmetic_v<T> || is_same_v<T, HugeInt>;
>
> Of course, this would mean that "std::arithmetic" would have different
> definitions in different translation units, but it wouldn't matter
> because the translation units that don't include the HugeInt header
> file won't ever use the HugeInt type.
If one wanted to go in that direction, this is doable (and indeed done)
today without requiring any fancy language extensions:
> // customization point as per [namespace.std], with semantic requirements
> template <typename T>
> constexpr bool enable_arithmetic = false;
>
> template <typename T>
> concept arithmetic = is_arithmetic_v<T> || enable_arithmetic<T>;
For instance see enable_view, enable_borrowed_range.
My 2 c,
--
Giuseppe D'Angelo
Received on 2025-04-15 11:38:42