1
votes

Temporary materialization conversion is a standard conversion, see § 7.3 Standard Conversions; 7.3.4 [conv.rval]:

A prvalue of type T can be converted to an xvalue of type T. This conversion initializes a temporary object ([class.temporary]) of type T from the prvalue by evaluating the prvalue with the temporary object as its result object, and produces an xvalue denoting the temporary object. T shall be a complete type.

But why is it not mentioned in the list of standard conversion sequences?

See [conv]/1:

A standard conversion sequence is a sequence of standard conversions in the following order:

  • Zero or one conversion from the following set: lvalue-to-rvalue conversion, array-to-pointer conversion, and function-to-pointer conversion.

  • Zero or one conversion from the following set: integral promotions, floating-point promotion, integral conversions, floating-point conversions, floating-integral conversions, pointer conversions, pointer-to-member conversions, and boolean conversions.

  • Zero or one function pointer conversion.

  • Zero or one qualification conversion.

Is it because an object would have to be created either way, and therefore would have no impact on determining whether a conversion sequence is better than another?

1
Can you make your question self contained please? - πάντα ῥεῖ
Temporary materialization is not a "conversion" operation. So why would it be in the "standard conversion sequence" if it's not a conversion? - Nicol Bolas
All relevant parts of the question should be in the question. Not behind links to external sites. - Jesper Juhl
@NicolBolas The standard calls it a conversion: eel.is/c++draft/conv.rval In fact under the header standard conversions. - walnut
I think you're misunderstanding what it's saying. The conversion is from a prvalue to an xvalue. That conversion involves temporary materialization, but temporary matieralization is not the goal. - Nicol Bolas

1 Answers

2
votes

Is it because an object would have to be created either way, and therefore would have no impact on determining whether a conversion sequence is better than another?

Yes, temporary materialization is not a choice, so it's "free" and exempt from ICS ranking. It's applied when needed, see [expr.basic.lval]/7:

Whenever a prvalue appears as an operand of an operator that expects a glvalue for that operand, the temporary materialization conversion is applied to convert the expression to an xvalue.

For example, the dot-expression requires the left-hand side to be a glvalue:

struct X {
  void func(int) { }
  void func(long) { }
};

int n = 1;

X().func(n);

Here the X() prvalue must first become an xvalue (materialized) before we can proceed to .func(n), at which time ICS ranking comes into picture to decide how to invoke func(n), since there can be different conversion sequences leading to different alternatives.