Proposal: Static Invariant (C++ concept in D)
Robert Fraser
fraserofthenight at gmail.com
Mon Sep 17 19:17:01 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();
> }
> }
>
> Thanks for the great discussion & help from h3r3tic, LeoD, Alexander,
> Larsivi
> They gave me some comments, and ideas.
>
> Though it might not functionate all possiblities of C++ concept , but it
> brings
> us a little bit more powerful way to make sure our templates go all fine.
> Hope
> people love this idea :D
>
>
> DavidL
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!()
}
More information about the Digitalmars-d
mailing list