Stroustrup's talk on C++0x

Walter Bright newshound1 at digitalmars.com
Sat Aug 25 23:02:39 PDT 2007


Bill Baxter wrote:
> Walter Bright wrote:
>> Bill Baxter wrote:
> 
>>> but some are also available in g++ now, I believe.  And there are 
>>> some features slated for  C++ 09 that aren't on the roadmap for D at 
>>> all (like concepts
>>
>> Concepts aren't a whole lot more than interface specialization, which 
>> is already supported in D.
> 
> I'm not sure what you mean by that, but the feature that I liked most 
> about it is interface checking.  So
> A) Being able to document someplace that if you want to use my 
> KewlContainer you must implement the KewlIteratorConcept which means, 
> say, you support opPostInc() and opSlice() (for dereferencing as x[]).
> and then once that is documented
> B) being able to say that my class implements that concept and have the 
> compiler check that indeed it does.
> 
> I suppose there may be some way to do all that in current D,

Yup:

interface KewlIteratorConcept
{
     T opPostInc();
     U opSlice();
}

class KewlContainer : KewlIteratorConcept
{
     T opPostInc() { ... }
     U opSlice() { ... }
}

class WrongContainer
{
}

template Foo(T : KewlIteratorConcept) { ... }

KewlContainer k;
WrongContainer w;

Foo!(k);	// ok
Foo!(w);	// error, w is not a KewlIteratorConcept



More information about the Digitalmars-d mailing list