Proposal: static template(fail)

Sean Kelly sean at f4.ca
Thu Dec 13 12:37:00 PST 2007


Bill Baxter wrote:
> Sean Kelly wrote:
>> Janice Caron wrote:
>>> I would like to propose a new statement:
>>>
>>>     static template(fail);
>>>
>>> which causes a compile-time substitution failure. And remember: SFINAE
>>> - Substitution Failure Is Not An Error
>>>
>>> Let me give you an example:
>>>
>>>     struct S(T)
>>>     {
>>>         static if(isFloatingPoint!(T))
>>>         {
>>>             /*...*/
>>>         }
>>>         else static if(passesSomeVeryComplicatedTest!(T))
>>>         {
>>>             /*...*/
>>>         }
>>>         else
>>>         {
>>>             static template(fail); // SFINAE
>>>         }
>>>     }
>>>
>>> This has advantages over old-style specialisation.
>>
>> I guess this would require the compiler to not complain if I did this?
>>
>> struct S(T)
>> {
>>     static if(is(T==int))
>>         static template(fail);
>> }
>>
>> struct S(T)
>> {
>>
>> }
>>
>> S!(int);
> 
> No, you have to make one of them specialized somehow, otherwise it's 
> just a good old fashioned redundant definition error.  Like if you tried 
> to make two functions "void foo(int)".

So either way I'd need to use specialization?  I suppose this would 
still simplify coding a tad, but...


Sean



More information about the Digitalmars-d mailing list