www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Function template arg promotion

reply Artur Skawina <art.08.09 gmail.com> writes:
------------------------------------------------------------------------
void set_from_4ub_f(ubyte red, ubyte green, ubyte blue, ubyte alpha) { }
void set_from_4ub()(ubyte red, ubyte green, ubyte blue, ubyte alpha) { }

void f() {
   set_from_4ub_f(0x00, 0x00, 0x00, 0xff); // Works.
   set_from_4ub(0x00, 0x00, 0x00, 0xff);   // Fails.
}
------------------------------------------------------------------------

results in:

templargpromo.d:6: Error: template templargpromo.set_from_4ub() does not match
any function template declaration
templargpromo.d:6: Error: template templargpromo.set_from_4ub() cannot deduce
template function from argument types !()(int,int,int,int)


Any way to make the template version work, without requiring changes for users?
And without having to cast the args back to ubyte before using them?

artur
Feb 03 2012
next sibling parent reply "Daniel Murphy" <yebblies nospamgmail.com> writes:
void set_from_4ub(dummy = int)(ubyte red, ubyte green, ubyte blue, ubyte 
alpha) { }
??

(not tested) 
Feb 03 2012
parent reply Artur Skawina <art.08.09 gmail.com> writes:
On 02/03/12 17:39, Daniel Murphy wrote:
 void set_from_4ub(dummy = int)(ubyte red, ubyte green, ubyte blue, ubyte 
 alpha) { }
 ??
 
 (not tested) 
That doesn't change anything; the issue is: the "int" literals wont implicitly convert to ubyte, even when there is no better match and an assignment would succeed. artur
Feb 03 2012
parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
Ah ok, I just guessed.  It sounds like you've hit 
http://d.puremagic.com/issues/show_bug.cgi?id=4953

"Artur Skawina" <art.08.09 gmail.com> wrote in message 
news:mailman.343.1328308873.25230.digitalmars-d puremagic.com...
 On 02/03/12 17:39, Daniel Murphy wrote:
 void set_from_4ub(dummy = int)(ubyte red, ubyte green, ubyte blue, ubyte
 alpha) { }
 ??

 (not tested)
That doesn't change anything; the issue is: the "int" literals wont implicitly convert to ubyte, even when there is no better match and an assignment would succeed. artur
Feb 03 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/03/2012 04:10 PM, Artur Skawina wrote:
 ------------------------------------------------------------------------
 void set_from_4ub_f(ubyte red, ubyte green, ubyte blue, ubyte alpha) { }
 void set_from_4ub()(ubyte red, ubyte green, ubyte blue, ubyte alpha) { }

 void f() {
     set_from_4ub_f(0x00, 0x00, 0x00, 0xff); // Works.
     set_from_4ub(0x00, 0x00, 0x00, 0xff);   // Fails.
 }
 ------------------------------------------------------------------------

 results in:

 templargpromo.d:6: Error: template templargpromo.set_from_4ub() does not match
any function template declaration
 templargpromo.d:6: Error: template templargpromo.set_from_4ub() cannot deduce
template function from argument types !()(int,int,int,int)


 Any way to make the template version work, without requiring changes for users?
 And without having to cast the args back to ubyte before using them?

 artur
It should already work. It is a bug, probably related to http://d.puremagic.com/issues/show_bug.cgi?id=7366
Feb 03 2012