No we should not support enum types derived from strings

Q. Schroll qs.il.paperinik at gmail.com
Sat May 8 00:19:22 UTC 2021


On Friday, 7 May 2021 at 17:05:08 UTC, Steven Schveighoffer wrote:
> The problem I have is, you have a function like:
> ```D
> auto foo(T)(T s) if (isSomeString!T) { impl }
> ```
> The *intention* here is that, I want to NOT have to write:
> ```D
> auto foo(string s) { impl }
> auto foo(wstring s) { impl }
> auto foo(dstring s) { impl }
> ... // etc with const, mutable
> ```
> BUT, if I have an enum that converts to a string, then if I 
> actually DID write all those, then it would compile. However, 
> the template version does not. This is the confusion that a 
> user and library author has.

Maybe this is special casing here, but if you have a finite list 
of types you want to support, it might be easier to add an 
`AliasSeq` of all string types to `std.traits` or so and use

```D
static foreach (String; Strings)
auto foo(String s) { impl }
```

Looks generic, but actually isn't. The implementation bloat is a 
different beast though.


More information about the Digitalmars-d mailing list