www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Proposal: Static Invariant (C++ concept in D)

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  
 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
 Thanks for the great discussion & help from h3r3tic, LeoD, Alexander,  
 They gave me some comments, and ideas.
 Though it might not functionate all possiblities of C++ concept , but it  
 us a little bit more powerful way to make sure our templates go all fine.  
 people love this idea :D

Isn't this what a static assert is? If you want sets of static assertions, you can always use template mixins. template LionAssertions() { static assert(Lion.foodChainPosition == FoodChain.max); static assert(Mufasa > Aslan, "this program contains evil lies"); } class Lion : AwesomenessIncarnate { mixin LionAssertions!() }
Sep 17 2007