digitalmars.D - constraints,template specialization,drop IFTI
- BLS (19/19) Jul 15 2009 I have somehow the idea that D constraints and template specialization
- Daniel Keep (17/33) Jul 15 2009 Firstly, why not
- Ary Borenszweig (8/38) Jul 15 2009 And this?
- BLS (10/51) Jul 15 2009 sure, but Mister Compiler makes that decision, What I want is _also_
- Jarrett Billingsley (10/20) Jul 15 2009 t the
- BLS (12/34) Jul 15 2009 Quote : "
- Jarrett Billingsley (6/9) Jul 15 2009 Well that is *completely* lame. I would have expected
- BLS (2/16) Jul 15 2009 Tu me demande ? Pas d' idee. ..have to ask the gurus
- Max Samukha (29/45) Jul 15 2009 And template oveloading with refined concepts is not supported, which
I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the compiler decision for template specialization a constraints could be used for : "I am not the one who is able to fulfill your needs.. try this template instead." template Foo(int N) if ( ( N & 1 _else_ FooOdd!(int N)) ) { ... } Already something. To quote Christian Kamm : -- /I also feel that specialization may just be a special case of constraints - with the added benefit that implicit function template instantiation works./ A smarter implementation will probably support tuple based pattern matching. In case that D will have such a feature ...we have to find a new snappy word for _fuzzy secure meta-programming_ . What do you think ?
Jul 15 2009
BLS wrote:I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the compiler decision for template specialization a constraints could be used for : "I am not the one who is able to fulfill your needs.. try this template instead." template Foo(int N) if ( ( N & 1 _else_ FooOdd!(int N)) ) { ... }Firstly, why not template Foo(int N) if( N&1 ) else FooOdd!N { ... } Secondly, why? I mean, isn't this equivalent to: template Foo(int N) { static if( N&1 ) { ... } else alias FooOdd!N Foo; }... A smarter implementation will probably support tuple based pattern matching.Huh? Isn't this how template matching works anyway; match a given argument tuple against the available templates? Lastly, what's that in the subject about dropping IFTI? I seriously hope you're joking about that.
Jul 15 2009
Daniel Keep wrote:BLS wrote:And this? template Foo(int N) if ((N & 1) != 0) { } template Foo(int N) if ((N & 1) != 1) { }I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the compiler decision for template specialization a constraints could be used for : "I am not the one who is able to fulfill your needs.. try this template instead." template Foo(int N) if ( ( N & 1 _else_ FooOdd!(int N)) ) { ... }Firstly, why not template Foo(int N) if( N&1 ) else FooOdd!N { ... } Secondly, why? I mean, isn't this equivalent to: template Foo(int N) { static if( N&1 ) { ... } else alias FooOdd!N Foo; }
Jul 15 2009
Daniel Keep wrote:BLS wrote:sure, but Mister Compiler makes that decision, What I want is _also_ programmer control. template Foo(T : Tuple) match T { case... } { //default }I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the compiler decision for template specialization a constraints could be used for : "I am not the one who is able to fulfill your needs.. try this template instead." template Foo(int N) if ( ( N & 1 _else_ FooOdd!(int N)) ) { ... }Firstly, why not template Foo(int N) if( N&1 ) else FooOdd!N { ... } Secondly, why? I mean, isn't this equivalent to: template Foo(int N) { static if( N&1 ) { ... } else alias FooOdd!N Foo; }... A smarter implementation will probably support tuple based pattern matching.Huh? Isn't this how template matching works anyway; match a given argument tuple against the available templates?Lastly, what's that in the subject about dropping IFTI? I seriously hope you're joking about that.ok, wrong description, wrong words. should be -> make implicit function template instantiation explicit :) work.
Jul 15 2009
On Wed, Jul 15, 2009 at 12:30 PM, BLS<windevguy hotmail.de> wrote:I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the =A0compiler dec=isionfor template specialization =A0a constraints could be used for : "I am no=t theone who is able to fulfill your needs.. try this template instead." template Foo(int N) =A0 =A0 =A0 =A0if ( ( N & 1 _else_ FooOdd!(int N)) ) { =A0 =A0... }I'm not sure why you'd need that.. template Foo(int N) if(N & 1) { // odd } template Foo(int N) { // even }
Jul 15 2009
Jarrett Billingsley wrote:On Wed, Jul 15, 2009 at 12:30 PM, BLS<windevguy hotmail.de> wrote:Quote : " Constraints are not involved with determining which template is more specialized than another. "I have somehow the idea that D constraints and template specialization should merge. Guess what I want to say is that instead of accepting the compiler decision for template specialization a constraints could be used for : "I am not the one who is able to fulfill your needs.. try this template instead." template Foo(int N) if ( ( N & 1 _else_ FooOdd!(int N)) ) { ... }I'm not sure why you'd need that..template Foo(int N) if(N & 1) { // odd } template Foo(int N) { // even }//programmer's control template Foo(T : Tuple) match T { case... } { //default } Better ? --well maybe I am completely wrong
Jul 15 2009
On Wed, Jul 15, 2009 at 1:42 PM, BLS<windevguy hotmail.de> wrote:Quote : " Constraints are not involved with determining which template is more specialized than another. "Well that is *completely* lame. I would have expected template Foo(int N : 5) to be sugar for template Foo(int N) if(N == 5) Why *isn't* that the case?
Jul 15 2009
Jarrett Billingsley wrote:On Wed, Jul 15, 2009 at 1:42 PM, BLS<windevguy hotmail.de> wrote:Tu me demande ? Pas d' idee. ..have to ask the gurusQuote : " Constraints are not involved with determining which template is more specialized than another. "Well that is *completely* lame. I would have expected template Foo(int N : 5) to be sugar for template Foo(int N) if(N == 5) Why *isn't* that the case?
Jul 15 2009
On Wed, 15 Jul 2009 20:00:40 +0200, BLS <windevguy hotmail.de> wrote:Jarrett Billingsley wrote:And template oveloading with refined concepts is not supported, which makes constraints less useful than C++'s concepts: // InputRange concept template isInputRange(T) { .... } // Refinement of InputRange concept template isForwardRange(T) { enum isForwardRange = isInputRange!T && ....; } void foo(T)(T r) if (isInputRange!T) { } void foo(T)(T r) if (isForwardRange!T) { } void bar() { ForwardRange fr; InputRange ir; foo(fr); foo(ir); } The above doesn't compile, of course. The limitation can be worked around in a number of graceless ways but claiming that D's constraints are superior to C++ concepts seems to be premature.On Wed, Jul 15, 2009 at 1:42 PM, BLS<windevguy hotmail.de> wrote:Tu me demande ? Pas d' idee. ..have to ask the gurusQuote : " Constraints are not involved with determining which template is more specialized than another. "Well that is *completely* lame. I would have expected template Foo(int N : 5) to be sugar for template Foo(int N) if(N == 5) Why *isn't* that the case?
Jul 15 2009