C++ guys hate static_if?

deadalnix deadalnix at gmail.com
Tue Mar 12 08:10:24 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

With the thing defined that way not that much. But consider :

concept InputRange(T) {
     bool empty;
     T front;
     void popFront();
}

Then you can :
  - Validate range in a static manner.
  - Validate template before they are instantiated.
  - Express intent.
  - Make overload rules easier to understand and more predictable 
when used.

Definitively the idea it nice. I don't see it a replacement of 
static if as it doesn't handle values.


More information about the Digitalmars-d mailing list