C++: A prvalue is not a temporary

C++ geeks fight over 'temporary' talk as Rust fans pile on

TLDR: The post says a C++ “prvalue” is like a plan, not a real object, and only becomes one when necessary—no extra copies. Commenters split between “please explain the jargon,” war stories about C++ pain, and Rust fans arguing their language is simpler. It matters for performance and clarity.

A new blog post claims a “prvalue” in C++ isn’t necessarily a temporary—think blueprint, not furniture—and the comments exploded. Curious readers like Night_Thastus were delighted to learn there are more value types than the classic two, while veterans chimed in with “old habits die hard” and asked if C++ used to always spawn extra objects. The piece explains that C++ tries to avoid needless copying, using a value to directly set a variable or function parameter until it absolutely must create a real object. Nerdy, yes—but also spicy.

Then came the jargon meltdown. dzdt begged for plain English, saying the phrase “move from” reads like legalese for code. Folks started dropping Stack Overflow links and “explain like I’m five” threads. Meanwhile, p0w3n3d told a war story about nearly failing an exam and having to learn plain C first just to make sense of C++. Cue violin.

And because it’s the internet, Rust showed up. steveklabnik argued Rust is simpler, with fewer “value categories,” while C++ diehards insisted those extra labels are why the language squeezes out performance. For newbies, the takeaway is simple: prvalues aren’t automatically real objects; C++ only makes them “materialize” when needed. Faster code, messier comments. For reference-heads: see cppreference.

Key Points

  • A prvalue in C++ is not inherently a temporary; it represents the “idea of the object” and materializes only when needed.
  • Converting an lvalue with std::move produces an xvalue, enabling moves from an existing object.
  • Prvalues like std::vector{1,2,3} can directly initialize variables or parameters passed by value without creating extra temporaries.
  • Binding a prvalue to a reference parameter (e.g., const T&) triggers temporary materialization to provide an object to bind to.
  • Function calls that return by value are prvalues and directly initialize their targets at the call site, avoiding intermediate temporaries.

Hottest takes

"you have to know an awful lot about the topic he is writing about to even parse what he is saying." — dzdt
"When people say "Rust is just as complex as C++," I think value categories are a great example of why it's actually simpler, even if it also seems complex." — steveklabnik
"C++ is so complicated that I had to almost fail my exam" — p0w3n3d
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.