lundi 1 février 2016

Implicit conversion to lvalue reference

I'm looking at the standard 5.16 paragraph 3, trying to understand what is going on. Consider the type M defined as

struct M {
  M();
  M(const M&);
  M(M&&);
};

If I have a ternary expression pred ? E1 : E2, where the type of E1 is const M& and the type of E2 is M&& does 5.16 paragraph 3 bullet 1 apply?

— If E2 is an lvalue: E1 can be converted to match E2 if E1 can be implicitly converted (Clause 4) to the type “lvalue reference to T2”, subject to the constraint that in the conversion the reference must bind directly (8.5.3) to an lvalue.

I think it doesn't, because to have an implicit conversion to const M&, which requires M to have the member function operator const M&(). However, I'm not sure, because it could be converted to const M implicitly, can the reference be implicitly added?

Aucun commentaire:

Enregistrer un commentaire