Why is there no ambiguity?
struct B {}; struct C {}; struct A { A(B const &, C const &) {} A(B const &&, C const &&) = delete; #if 0 A(B const &, C const &&) = delete; A(B const &&, C const &) = delete; #endif }; B const b() { return {}; }
Here I want to save the lvalue const references for instances of B and C to instance A Of course, I want to make sure that the lifetime of referenced objects exceeds the lifetime of instance A
To achieve this, I simply overloaded = delete; for B const && and C const && , which also corresponds to B && and C && respectively.
The above approach works fine for conversion constructors (i.e. unary). But it turns out that for higher phenomena I must explicitly = delete; use all combinatorially possible combinations that include constant reference versions of the parameters of interest (i.e. #if 1 ).
Then I think, “Why is there no ambiguity?” Because ambiguity should also prevent compilation of the wrong code in the above case.
So the question is: “Why is there no ambiguity for the mixed case of calling the constructor?”.
source share