++Phobos

rikki cattermole rikki at cattermole.co.nz
Thu Oct 17 00:46:12 UTC 2019


On 17/10/2019 1:36 PM, Jesse Phillips wrote:
> 
> On Wednesday, 16 October 2019 at 22:34:00 UTC, rikki cattermole wrote:
>>
>> /// Docs go here
>> signature InputRange(@named ElementType) {
>>     @property {
>>         /// Docs go here
>>         ElementType front();
>>
>>         /// Docs go here
>>         bool empty();
>>     }
>>
>>     /// Docs go here
>>     void popFront();
>> }
>>
>> void func(T:InputRange)(T myInputRange) {}
>>
> 
> 
> The experimental.typecons has an incomplete modification to wrap. It 
> allows wrapping a structure into an interface if it conforms. If the 
> edge cases were worked out then similar logic would be applicable to the 
> function signature.
> 
> ...) if(implements!(InputRange, R))
> 
> What would be nice from the language is the ability to print a message 
> if no template matching occurs. Remember if it does not match it is just 
> pulled from overload resolution.

That works for matching an implementation to an interface.

It does miss out on better error messages and any ability to let the 
interface override or extend the implementation (e.g. extraction of 
ElementType from front or using the declared type in body of the 
implementation).

I.e.

signature InputRange(@named ElementType = 
ElementTypeCompat!(typeof(this)) { ... }

Not to mention it forces what amounts to idiomatic D into a second class 
position in many use cases. Not preferable IMO.


More information about the Digitalmars-d mailing list