C++ guys hate static_if?

TommiT tommitissari at hotmail.com
Tue Mar 12 07:24:10 PDT 2013


On Tuesday, 12 March 2013 at 14:16:15 UTC, H. S. Teoh wrote:
> On Tue, Mar 12, 2013 at 12:39:48PM +0100, TommiT wrote:
>> On Tuesday, 12 March 2013 at 04:34:05 UTC, Walter Bright wrote:
>> >It's interfaces without the vtable[].
>> >
>> >It's still solely based on type signatures. D constraints make
>> >pretty much anything that can be computed at compile time a
>> >testable gate.
>> 
>> Yeah, you're right. That kind of interface syntax doesn't 
>> really
>> lend itself to specifying concepts. So, here's another attempt 
>> at
>> a concept syntax (and functionality):
>> 
>> concept AscendingInfiniteInputRange {
>>      // 'this' is an instance of a type which implements the
>>      // AscendingInfiniteInputRange concept given the
>>      // if-condition below is true:
>>      if( is(typeof(this.empty) : bool)
>>      &&  is(typeof(this.front))
>>      && !is(typeof(this.front) == void)
>>      &&  is(typeof(this.popFront() == void)
>>      // testing a compile time evaluable value:
>>      &&  this.empty == false
>>      // static members can also be tested:
>>      &&  typeof(this).infinite == true
>>      &&  typeof(this).sortedAscending == true )
>> }
>
> How is this any different from the current isInputRange!R,
> isForwardRange!R, etc.?
>
>
> T

The difference is in function overload resolution. Polymorphic 
concept based template would know about the hierarchical nature 
of the concepts, say ForwardRange is a sub-concept of InputRange, 
and thus the function overload resolution would be able to choose 
the template which has the most derived/specialized concept 
parameter that still matches with the given template argument.


More information about the Digitalmars-d mailing list