Thread overview
Function template arg promotion
Feb 03, 2012
Artur Skawina
Feb 03, 2012
Daniel Murphy
Feb 03, 2012
Artur Skawina
Feb 04, 2012
Daniel Murphy
Feb 03, 2012
Timon Gehr
February 03, 2012
------------------------------------------------------------------------
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
February 03, 2012
void set_from_4ub(dummy = int)(ubyte red, ubyte green, ubyte blue, ubyte
alpha) { }
??

(not tested)


February 03, 2012
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
February 03, 2012
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
February 04, 2012
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