11

While browsing cppreference I noticed that in several places the words "a temporary" are replaced by "a materialized prvalue" for C++17 (see here for a quick example).

The link on cppreference takes you to this page, which gives this description of what "materialized" means:

A prvalue of any complete type T can be converted to an xvalue of the same type T. This conversion initializes a temporary object 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.

Unfortunately this description is a little too close to standardese for me to properly get my head around, and the end result as I read it ("a temporary appears, briefly") doesn't seem any different to how things worked in C++14.

So I'm wondering if anyone can explain, in layman's terms:

  • What exactly has changed in C++17 with regard to temporaries?
  • What problem(s) does this solve?
  • What difference (if any) will this make for C++ users?
Tristan Brindle
  • 16,281
  • 4
  • 39
  • 82
  • 10
    In brief , a prvalue is now like a "delayed evaluation" expression; if the prvalue is passed across function calls and returns, there is not actually an object created until it reaches its final destination. This avoids the possibility of intermediate temporaries and the need for some copy elision cases; it enables you to have a function that creates a non-copyable non-movable object and returns it – M.M May 24 '17 at 00:26
  • The temporary materialization rules are defined for the sole purpose of allowing guaranteed elision to work. So... that's the difference. – Nicol Bolas May 24 '17 at 00:29

0 Answers0