www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - constraints,template specialization,drop IFTI

reply BLS <windevguy hotmail.de> writes:
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
next sibling parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
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
next sibling parent Ary Borenszweig <ary esperanto.org.ar> writes:
Daniel Keep wrote:
 
 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; }
And this? template Foo(int N) if ((N & 1) != 0) { } template Foo(int N) if ((N & 1) != 1) { }
Jul 15 2009
prev sibling parent BLS <windevguy hotmail.de> writes:
Daniel Keep wrote:
 
 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?
sure, but Mister Compiler makes that decision, What I want is _also_ programmer control. template Foo(T : Tuple) match T { case... } { //default }
 
 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
prev sibling parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
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=
ision
 for template specialization =A0a constraints could be used for : "I am no=
t the
 one 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
parent reply BLS <windevguy hotmail.de> writes:
Jarrett Billingsley wrote:
 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  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..
Quote : " Constraints are not involved with determining which template is more specialized than another. "
 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
parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
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
parent reply BLS <windevguy hotmail.de> writes:
Jarrett Billingsley wrote:
 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?
Tu me demande ? Pas d' idee. ..have to ask the gurus
Jul 15 2009
parent Max Samukha <spambox d-coding.com> writes:
On Wed, 15 Jul 2009 20:00:40 +0200, BLS <windevguy hotmail.de> wrote:

Jarrett Billingsley wrote:
 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?
Tu me demande ? Pas d' idee. ..have to ask the gurus
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.
Jul 15 2009