No we should not support enum types derived from strings

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed May 12 09:23:21 UTC 2021


On Friday, May 7, 2021 9:39:40 AM MDT Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 5/7/21 11:33 AM, Adam D. Ruppe wrote:
> > On Friday, 7 May 2021 at 15:25:30 UTC, Andrei Alexandrescu wrote:
> >> Enums derived from strings should not be supported as strings in the
> >> standard library.
> >
> > I don't think the stdlib should special case much of anything.
> >
> > Special casing enums is a mistake. If the user wants it treated as a
> > string, they can cast it to a string.
>
> yes
>
> > Special casing static arrays is a mistake. The user can just slice it
> > out the outside.
>
> Yes
>
> > Special casing alias this is a mistake. The user can pass what they
> > meant to pass.
>
> YES
>
> > The phobos templates should work like all other templates - on the exact
> > type passed. Other functions work with the normal overloading and
> > implicit conversion rules.
> >
> > Kill all the special cases!
>
> YES!!!

Agreed. While implicit conversions can at times be useful, they cause a ton
of problems when templates are involved. Ideally, we should accept no
implicit conversions of any kind with templated code. And honestly, I wish
that the language had fewer implicit conversions in it. In particular, I
think that implicitly slicing static arrays was a big mistake, and we've had
a number of issues in Phobos because of it when trying to later generalize
functions that originally just took strings.

- Jonathan M Davis





More information about the Digitalmars-d mailing list