Overloading for lvalue and rvalue.
    Balagopal Komarath via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Mon Jun 12 13:40:52 PDT 2017
    
    
  
Is there a way to avoid the following combinatorial explosion of 
overloaded functions when overloading for lvalue and rvalue 
arguments? The following may be a bad example because int is 
cheap to copy. So assume a large datatype instead of int.
import std.stdio;
void foo(in ref int a, in ref int b)
{
     writeln("r, r");
}
void foo(in ref int a, in int b)
{
     writeln("r, i");
}
void foo(in int a, in ref int b)
{
     writeln("i, r");
}
void foo(in int a, in int b)
{
     writeln("i, i");
}
void main()
{
     int a, b;
     foo(a, b);
     foo(a, 0);
     foo(0, a);
     foo(0, 0);
}
    
    
More information about the Digitalmars-d-learn
mailing list