Why is Phobos' isIntegral different from the built-in trait of the very same name?
schveiguy at gmail.com
Sun Oct 17 15:07:21 UTC 2021
On 10/17/21 10:36 AM, Andrei Alexandrescu wrote:
> According to
> 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
> 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:
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`.
More information about the Digitalmars-d