The only difference between refand const refis that which const refis constand refis not. Both should take a variable. None of them can be temporary. This is different from C ++, where it const T&will take any type value T- including temporary ones.
opBinary ref, const ref, . . Create. , , , . , .
, opEquals:
bool opEquals(CustomReal x) const
{
return value == x.value;
}
.
, opEquals . , opEquals, , , , , , :
prog.d(15): Error: function prog.CustomReal.opEquals type signature should be const bool(ref const(CustomReal)) not const bool(CustomReal x)
opEquals structs ( , toString, ). , , . opEquals. CustomReal , const ref, CustomReal , . , .
,
assert(a == CustomReal(123.123456));
,
assert(a == Create());
, . , , , const ref , - - , , opEquals special. , , opEquals , , , , . opEquals .
EDIT: , ,
assert(a == CustomReal(123.123456));
,
assert(a == Create());
, ( , ) lvalue, , ref (), r. , , rvalues, , -, lvalues ( ). , , const ref, , .