digitalmars.D - Proposal: Static Invariant (C++ concept in D)
- davidl (24/24) Sep 17 2007 I've read a little bit stuff of C++ concept, and find it has some
- Tom S (6/9) Sep 17 2007 *cough* negative comments *cough*
- Alexander Panek (2/10) Sep 17 2007 Same here; read as: I don't like it either.
- davidl (5/13) Sep 17 2007 You didn't raise a valid point. And actually it's you who choose the nam...
- Alexander Panek (8/9) Sep 17 2007 I pointed out - as Bill Baxter did here in the newsgroup -, that your
- Alexander Panek (2/3) Sep 17 2007 That should be "static invariant" of course ... !
- davidl (5/9) Sep 17 2007 I replied to bb, and I don't know if that answer good enough for you.
- Bill Baxter (7/24) Sep 17 2007 Can't you just do the same thing now, with slightly different syntax?
- davidl (19/41) Sep 17 2007 it's a little bit different. Because the check means the prerequisite of...
- Alexander Panek (3/7) Sep 17 2007 I think this is one of the cases where a feature should be implemented
- Robert Fraser (11/41) Sep 17 2007 Isn't this what a static assert is? If you want sets of static assertion...
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
Sep 17 2007
davidl wrote:Thanks for the great discussion & help from h3r3tic, LeoD, Alexander, Larsivi They gave me some comments, and ideas.*cough* negative comments *cough* -- Tomasz Stachowiak http://h3.team0xf.com/ h3/h3r3tic on #D freenode
Sep 17 2007
Tom S wrote:davidl wrote:Same here; read as: I don't like it either.Thanks for the great discussion & help from h3r3tic, LeoD, Alexander, Larsivi They gave me some comments, and ideas.*cough* negative comments *cough*
Sep 17 2007
在 Mon, 17 Sep 2007 20:45:07 +0800,Alexander Panek <alexander.panek brainsware.org> 写道:Tom S wrote:You didn't raise a valid point. And actually it's you who choose the name. -- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/davidl wrote:Same here; read as: I don't like it either.Thanks for the great discussion & help from h3r3tic, LeoD, Alexander, Larsivi They gave me some comments, and ideas.*cough* negative comments *cough*
Sep 17 2007
davidl wrote:You didn't raise a valid point. And actually it's you who choose the name.I pointed out - as Bill Baxter did here in the newsgroup -, that your proposal is rendered useless. "static in" would only add syntactic sugar for a feature that is rather easy to implement in D already. I pointed out the name, because I thought /if/ there should be a kind of compile time constraint, "static variadic" would be the most fitting phrase - as opposed to "static in", which you kept repeating in the beginning of our "discussion".
Sep 17 2007
Alexander Panek wrote:[...] compile time constraint, "static variadic" would be the most fitting [...]That should be "static invariant" of course ... !
Sep 17 2007
在 Mon, 17 Sep 2007 22:15:11 +0800,Alexander Panek <alexander.panek brainsware.org> 写道:Alexander Panek wrote:I replied to bb, and I don't know if that answer good enough for you. -- 使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/[...] compile time constraint, "static variadic" would be the most fitting [...]That should be "static invariant" of course ... !
Sep 17 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
Sep 17 2007
在 Mon, 17 Sep 2007 20:55:12 +0800,Bill Baxter <dnewsgroup billbaxter.com> 写道:davidl wrote: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/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
Sep 17 2007
davidl wrote:[...] I think it's for elegance. With some prerequisite checking the template system would be nicer.I think this is one of the cases where a feature should be implemented in a library, rather than the language specification.
Sep 17 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 DavidLIsn'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