No we should not support enum types derived from strings

Steven Schveighoffer schveiguy at gmail.com
Fri May 7 17:36:01 UTC 2021


On 5/7/21 1:27 PM, Daniel N wrote:
> On Friday, 7 May 2021 at 17:16:06 UTC, Steven Schveighoffer wrote:
>> On 5/7/21 1:05 PM, Steven Schveighoffer wrote:
>>> I think the problem here is that the language doesn't give you a good 
>>> way to express that. So we rely on template constraints that both 
>>> can't exactly express that intention, and where the approximations 
>>> create various template instantiations that cause strange problems 
>>> (i.e. if you accept an enum that converts to string, it's still an 
>>> enum inside the template). Whereas the language
>>
>> I forgot to finish this thought, got interrupted.
>>
>> Whereas the language (with non-template parameters) does the matching 
>> and conversion simultaneously without needing special cases.
>>
> 
> What's wrong with this?
> 
> void fun(T : string)(T t)

Because T is not a string.

e.g. for an string-based enum, t.popFront won't work.

-Steve


More information about the Digitalmars-d mailing list