Proposal: Static Invariant (C++ concept in D)
davidl
davidl at 126.com
Mon Sep 17 07:06:12 PDT 2007
在 Mon, 17 Sep 2007 20:55:12 +0800,Bill Baxter
<dnewsgroup at billbaxter.com> 写道:
> davidl wrote:
>> I've read a little bit stuff of C++ concept, and find it has some
>> similarity with
>> D's runtime invariant in some abstraction. In some extent , we can
>> imagine C++
>> concept is kind of compile time invariant.
>> So the following:
>> class TemplateClass(T)
>> {
>> static invariant() // reuse keywords, nothing more get introduced
>> {
>> // prerequisite checking, does T have foo , does T have bar
>> Base_Concept_check(); // these emulate the inheritance of concept
>> Derived_Concept_check();
>> }
>> }
>
> Can't you just do the same thing now, with slightly different syntax?
>
> For instance Base_Concept_check could be a template mixin with nothing
> but static ifs and other compile-time checks. Then you just have to say
> "mixin Base_Concept_check;" instead of calling it like a function, but
> same basic thing, no?
>
> --bb
it's a little bit different. Because the check means the prerequisite of
the template,
This is for the whole template scope. not till the last moment of making a
call. So
a mixin would trigger the "static invariant".
And "static invariant" itself is for prerequisite checking , so it's an
enforcement for
template design. The template inner scope can only use the stuffs which
are checked in
the "static invariant", I mean any stuff or members related to type T.
Also IDE could
provide nice code completion for template writers.
I think it's for elegance. With some prerequisite checking the template
system would be
nicer.
--
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list