Why is Phobos' isIntegral different from the built-in trait of the very same name?
Steven Schveighoffer
schveiguy at gmail.com
Sun Oct 17 15:07:21 UTC 2021
On 10/17/21 10:36 AM, Andrei Alexandrescu wrote:
> According to
> https://github.com/dlang/phobos/blob/master/std/traits.d#L6191:
>
> =====
> Detect whether `T` is a built-in integral type. Types `bool`, `char`,
> `wchar`, and `dchar` are not considered integral.
> =====
>
> Not considered by whom? Certainly they are considered by the language
> per __traits(isIntegral). Also all conversion rules scream "they're
> integral!"
>
> We even use the built-in trait to create a _different_ one!
>
> Why do we have a slightly different with no added usabilty in the
> standard library?
`isIntegral` dates back to D1, where `__traits` didn't exist. The
current implementation is a "shorter" version of what was already there,
without having to consider code breakage. This is the oldest thing I
could find on github:
https://github.com/dlang/phobos/commit/eec6be69edec9601f9f856afcd25a797e845c181#diff-b7918b17cede734a2dd4ecbf2a981d597a5978f52e02f9a3c6f53c9abd797f05R322-R327
Note that this is an import from the old subversion repository, so
attribution and PRs/etc. doesn't exist. You can keep looking on
dsource.org if you want to find the original commit, but I'm almost
positive it was Walter.
I think the original didn't include bool/[w|d]char either by
carelessness or a belief that these things really shouldn't be integers
(a great irony considering the contemporary pushback from Walter against
splitting bool out from the integral family).
Things like this should have never been done, but now we have to live
with it. Honestly, if we want to fix it, I would rather have the
language enforce what std.traits says. So many problems happen by
allowing e.g. integer promotion from `char` to `dchar`.
-Steve
More information about the Digitalmars-d
mailing list