Proposal: Static Invariant (C++ concept in D)

Bill Baxter dnewsgroup at billbaxter.com
Mon Sep 17 05:55:12 PDT 2007


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



More information about the Digitalmars-d mailing list