[RFC] std.experimental.concepts

Rikki Cattermole via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 07:24:33 PDT 2015


On 26/07/2015 2:14 a.m., Martin Nowak wrote:
> On Saturday, 25 July 2015 at 14:06:05 UTC, Daniel N wrote:
>> On Friday, 24 July 2015 at 19:56:55 UTC, Shammah Chancellor wrote:
>>> I put up a PR for phobos awhile ago for concepts as a library to kind
>>> of start the discussion around concepts.   There seemed to be some
>>> interest around the PR, so I have rebased it and fixed the formatting.
>>>
>>> Please take a look:
>>> https://github.com/D-Programming-Language/phobos/pull/2627
>>>
>>> -Shammah
>>
>> For those who are on a sugar-rush from Concepts, maybe this is a fun
>> trick?
>>
>> It almost works, if only IFTI was smart enough to deal with eponymous
>> identity templates.
>>
>> ========================================
>> int fun(T)(T t) if(is(typeof(T.Put)))
>> {
>> }
>> ========================================
>> template Putty(T)
>> {
>>   static assert(is(typeof(T.Put)));
>>
>>   alias Putty = T;
>> }
>> void fun(T)(Putty!T t)
>> {
>> }
>> ========================================
>
> Templates are not bijective, so we'll never be generally able to
> determine T by matching Putty, i.e. 2 different T could have the same
> Putty!T type.
> Adding an exception for identity templates seems to be a hack.

======================================

template Putty(T)
{
   static assert(is(typeof(T.Put)));

   alias Putty = T;
}
void fun(!T)(Putty!T t)
{
}

=======================================

void fun(__original_T)(__original_T t) if (is(Putty!__original_T == 
__original_T))
{
}

=======================================

Humm, minor rewrite of source by the front end. Definitely would be doable.


More information about the Digitalmars-d mailing list