Reputation:
If an identity conversion does not do anything (whenever I have encountered it in the standard, it was simply to tell that there was no need for conversion), why is it a thing? What is its true purpose?
Exmaples of its usage
From the standard (n3690 13.3.3.1.1):
As described in Clause 4, a standard conversion sequence is either the Identity conversion by itself (that is, no conversion) or consists of one to three conversions from the other four categories.
13.3.3.1:
If no conversions are required to match an argument to a parameter type, the implicit conversion sequence is the standard conversion sequence consisting of the identity conversion
Otherwise, if the parameter type is an aggregate which can be initialized from the initializer list according by aggregate initialization, the implicit conversion sequence is a user-defined conversion sequence with the second standard conversion sequence an identity conversion.
struct A { int m1; double m2;};
void f(A);
f({'a','b'}); // calls f(A(int,double)), user-defined conversion
"with the second standard conversion sequence an identity conversion" - is that even worth mentioning?
Upvotes: 0
Views: 524
Reputation: 3871
The purpose of the identity conversion is to act as a base case and allow us to reason about conversions without having to single out the case where no conversion is needed.
Upvotes: 2