www.digitalmars.com         C & C++   DMDScript  

D - Template specialized search

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
the following does not compile
instance base(cast(Linkage)0,void) matches more than one template
declaration

I assume it matches
template base( Linkage T, R : void )
and
template base( Linkage T : Linkage.Windows, R ){

I would like a way to match base( Linkage.Windows, void ) is the first
without having I have to write
template base( Linkage T : Linkage.Windows, R : void )
template base( Linkage T : .... , R : void )
etc. to give the compiler perfect matches.
perhaps a way to say template base( Linkage T, R : !void )
or to consider value params as less important than type params
or ordering the template search some how

------------------ code -----------------------------

enum Linkage { Windows, C, D }

template proc( Linkage T : Linkage.Windows ){
 extern (Windows) alias void (*fp)();
 fp func;
}

template proc( Linkage T : Linkage.C ){
 extern (C) alias void (*fp)();
 fp func;
}

template base( Linkage T, R : void )
{
 instance proc( T ) realTemplate;
 alias realTemplate.fp fp;
 alias realTemplate.func func;
}

template base( Linkage T : Linkage.Windows, R ){
 extern (Windows) alias R (*fp)();
 fp func;
}

template base( Linkage T : Linkage.C, R ){
 extern (C) alias R (*fp)();
 fp func;
}

instance base( Linkage.Windows, void ) other;

extern (Windows) void myw_func(){ }
void myd_func(){ }

int main( char[][] args )
{
 other.func = &myw_func;
// other.func = &myd_func;
 return 0;
}

---------------- work around -----------------------
template base( Linkage T : Linkage.Windows, R : void )
{
 instance proc( T ) realTemplate;
 alias realTemplate.fp fp;
 alias realTemplate.func func;
}

template base( Linkage T : Linkage.C, R : void )
{
 instance proc( T ) realTemplate;
 alias realTemplate.fp fp;
 alias realTemplate.func func;
}
Feb 08 2003
parent reply "Walter" <walter digitalmars.com> writes:
I've been trying to keep D at using simple rules for ambiguity resolution -
a 3 level system of it's an exact match, or a match with conversions, or no
match. The C++ notion of 'better' matches gets overwhelmingly complicated.

"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:b246a7$1f7s$1 digitaldaemon.com...
 the following does not compile
 instance base(cast(Linkage)0,void) matches more than one template
 declaration

 I assume it matches
 template base( Linkage T, R : void )
 and
 template base( Linkage T : Linkage.Windows, R ){

 I would like a way to match base( Linkage.Windows, void ) is the first
 without having I have to write
 template base( Linkage T : Linkage.Windows, R : void )
 template base( Linkage T : .... , R : void )
 etc. to give the compiler perfect matches.
 perhaps a way to say template base( Linkage T, R : !void )
 or to consider value params as less important than type params
 or ordering the template search some how

 ------------------ code -----------------------------

 enum Linkage { Windows, C, D }

 template proc( Linkage T : Linkage.Windows ){
  extern (Windows) alias void (*fp)();
  fp func;
 }

 template proc( Linkage T : Linkage.C ){
  extern (C) alias void (*fp)();
  fp func;
 }

 template base( Linkage T, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.Windows, R ){
  extern (Windows) alias R (*fp)();
  fp func;
 }

 template base( Linkage T : Linkage.C, R ){
  extern (C) alias R (*fp)();
  fp func;
 }

 instance base( Linkage.Windows, void ) other;

 extern (Windows) void myw_func(){ }
 void myd_func(){ }

 int main( char[][] args )
 {
  other.func = &myw_func;
 // other.func = &myd_func;
  return 0;
 }

 ---------------- work around -----------------------
 template base( Linkage T : Linkage.Windows, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.C, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

Mar 11 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Walter" <walter digitalmars.com> wrote in message
news:b4m74o$to8$1 digitaldaemon.com...
 I've been trying to keep D at using simple rules for ambiguity

 a 3 level system of it's an exact match, or a match with conversions, or

 match. The C++ notion of 'better' matches gets overwhelmingly complicated.

hence allowing a not condition, the problem was; template foo( T, R ) { ... } I want to have foo( T, R : void ) // any linkage as this is effecivly an alias to foonotreturn( T ) and foo( T : Linkage.windows, R ) where R is not void also I keep finding my self wanting base( T , R : char | wchar ) where R is only char or wchar I agree the matching should be exact (or N depth super class) only but it would be nice to be able to specify the match pattern i.e !<match> never match that type <match> | <match> or || and & or && for 'and' so sometemp( T : (Base | R[]), R : !(char | wchar) ) { } sometemp( T : (Base | R[]), R : (char | wchar) ) { } sometemp( T : (!int & !(Base | R[])), R : !(char | wchar) ) { } sometemp( T : (!int & !(Base | R[])), R : (char | wchar) ) { } sometemp( T : int, R ) { } simple rules, but allow full specification of templates types.
 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:b246a7$1f7s$1 digitaldaemon.com...
 the following does not compile
 instance base(cast(Linkage)0,void) matches more than one template
 declaration

 I assume it matches
 template base( Linkage T, R : void )
 and
 template base( Linkage T : Linkage.Windows, R ){

 I would like a way to match base( Linkage.Windows, void ) is the first
 without having I have to write
 template base( Linkage T : Linkage.Windows, R : void )
 template base( Linkage T : .... , R : void )
 etc. to give the compiler perfect matches.
 perhaps a way to say template base( Linkage T, R : !void )
 or to consider value params as less important than type params
 or ordering the template search some how

 ------------------ code -----------------------------

 enum Linkage { Windows, C, D }

 template proc( Linkage T : Linkage.Windows ){
  extern (Windows) alias void (*fp)();
  fp func;
 }

 template proc( Linkage T : Linkage.C ){
  extern (C) alias void (*fp)();
  fp func;
 }

 template base( Linkage T, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.Windows, R ){
  extern (Windows) alias R (*fp)();
  fp func;
 }

 template base( Linkage T : Linkage.C, R ){
  extern (C) alias R (*fp)();
  fp func;
 }

 instance base( Linkage.Windows, void ) other;

 extern (Windows) void myw_func(){ }
 void myd_func(){ }

 int main( char[][] args )
 {
  other.func = &myw_func;
 // other.func = &myd_func;
  return 0;
 }

 ---------------- work around -----------------------
 template base( Linkage T : Linkage.Windows, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.C, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }


Mar 12 2003
parent "Walter" <walter digitalmars.com> writes:
I see your point. The not thing would be an interesting addition.

"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
news:b4na6o$1k14$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:b4m74o$to8$1 digitaldaemon.com...
 I've been trying to keep D at using simple rules for ambiguity

 a 3 level system of it's an exact match, or a match with conversions, or

 match. The C++ notion of 'better' matches gets overwhelmingly



hence allowing a not condition, the problem was; template foo( T, R ) { ... } I want to have foo( T, R : void ) // any linkage as this is effecivly an alias to foonotreturn( T ) and foo( T : Linkage.windows, R ) where R is not void also I keep finding my self wanting base( T , R : char | wchar ) where R is only char or wchar I agree the matching should be exact (or N depth super class) only but it would be nice to be able to specify the match pattern i.e !<match> never match that type <match> | <match> or || and & or && for 'and' so sometemp( T : (Base | R[]), R : !(char | wchar) ) { } sometemp( T : (Base | R[]), R : (char | wchar) ) { } sometemp( T : (!int & !(Base | R[])), R : !(char | wchar) ) { } sometemp( T : (!int & !(Base | R[])), R : (char | wchar) ) { } sometemp( T : int, R ) { } simple rules, but allow full specification of templates types.
 "Mike Wynn" <mike.wynn l8night.co.uk> wrote in message
 news:b246a7$1f7s$1 digitaldaemon.com...
 the following does not compile
 instance base(cast(Linkage)0,void) matches more than one template
 declaration

 I assume it matches
 template base( Linkage T, R : void )
 and
 template base( Linkage T : Linkage.Windows, R ){

 I would like a way to match base( Linkage.Windows, void ) is the first
 without having I have to write
 template base( Linkage T : Linkage.Windows, R : void )
 template base( Linkage T : .... , R : void )
 etc. to give the compiler perfect matches.
 perhaps a way to say template base( Linkage T, R : !void )
 or to consider value params as less important than type params
 or ordering the template search some how

 ------------------ code -----------------------------

 enum Linkage { Windows, C, D }

 template proc( Linkage T : Linkage.Windows ){
  extern (Windows) alias void (*fp)();
  fp func;
 }

 template proc( Linkage T : Linkage.C ){
  extern (C) alias void (*fp)();
  fp func;
 }

 template base( Linkage T, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.Windows, R ){
  extern (Windows) alias R (*fp)();
  fp func;
 }

 template base( Linkage T : Linkage.C, R ){
  extern (C) alias R (*fp)();
  fp func;
 }

 instance base( Linkage.Windows, void ) other;

 extern (Windows) void myw_func(){ }
 void myd_func(){ }

 int main( char[][] args )
 {
  other.func = &myw_func;
 // other.func = &myd_func;
  return 0;
 }

 ---------------- work around -----------------------
 template base( Linkage T : Linkage.Windows, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }

 template base( Linkage T : Linkage.C, R : void )
 {
  instance proc( T ) realTemplate;
  alias realTemplate.fp fp;
  alias realTemplate.func func;
 }



Mar 12 2003