Maybe i'm fixing myself too much on the reference definition, which states references cannot be assigned to diferent types.
hmm... I do not recall such a rule. My reasoning is that a reference is effectively an alias for what it refers to, so if what the reference refers to is convertible to another type, the reference too should be convertible to that type.
I think what you mean to say is that one cannot assign to a reference of a different type (but note the exception where polymorphism comes into play).
The contrast would then be between:
Code:
int main() {
double a = 0.0;
int& b = static_cast<int>(a);
}
which produces a compile error, and
Code:
int main() {
double a = 0.0;
const int& b = static_cast<int>(a);
}
which doesnt. In the latter my opinion is that it is safe for the rvalue to be passed to const reference, since the const-ness means the rvalue wont be changed.
As such I cannot assign a double reference to an int type.
You can assign a double (reference or not) to an int, but with possible loss of data.
Your initial example, laserlight... you mean it is useful for function templates?
Um, my example is a non-template function. My use of 'T' is just laziness since it can be any appropriate type.