Stroustrup's talk on C++0x
Bill Baxter
dnewsgroup at billbaxter.com
Sat Aug 25 23:58:11 PDT 2007
Walter Bright wrote:
> 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
Ok, but does that work if you want it to work with a built-in type too?
Will a float be recognized as supporting opPostInc?
--bb
More information about the Digitalmars-d
mailing list