C++ guys hate static_if?

TommiT tommitissari at hotmail.com
Tue Mar 12 08:47:21 PDT 2013


On Tuesday, 12 March 2013 at 15:37:01 UTC, deadalnix wrote:
> On Tuesday, 12 March 2013 at 15:26:19 UTC, TommiT wrote:
>>> With the thing defined that way not that much. But consider :
>>>
>>> concept InputRange(T) {
>>>   bool empty;
>>>   T front;
>>>   void popFront();
>>> }
>>
>> What if I write a type like the following:
>>
>> struct MyType {
>>    int _value;
>>
>>    @property bool empty() const { return true; }
>>    @property ref const(int) front() const { return _value; }
>>    void popFront() const { }
>> }
>>
>> Does MyType fulfill the requirements of your InputRange(T) 
>> concept? I don't think it does since its front returns by ref 
>> const(int) and InputRange(T)'s front returns by value.
>
> It doesn't because popFront is const and that don't make any 
> sense.

I didn't mean to make popFront const. My point was that 
InputRange concept requires that the front property returns a 
non-void type but it doesn't care whether or not it is returned 
by ref, const ref, or by value. I don't see how you could easily 
convey that kind of requirement in an interface-like syntax.


More information about the Digitalmars-d mailing list