R-values and const ref

Max Samukha spambox at d-coding.com
Wed Sep 15 03:12:30 PDT 2010


On 09/09/2010 06:26 PM, Steven Schveighoffer wrote:

>
> Yes, I forgot that you are allowed to overload via ref. That would make
> sense for virtual functions.

That forces us to provide multiple overloads, each matching one of the 
possible combinations of rvalue/lvalue arguments. A function with n 
struct parameters would require 2^n overloads. The only way to avoid the 
mess is to implement a single function taking all struct arguments by 
value or use templates, which is unacceptable in the general case.

There is also an unspecified part related to default arguments. For 
example, this compiles:

struct S
{
}

S bar()
{
     return S();
}

void foo(ref const S s = bar())
{
}

Is it safe to rely on this feature?





More information about the Digitalmars-d mailing list