Urgent.News

What's breaking now, across thousands of outlets.

Tech

C++26: std::indirect

C++26 introduces two new vocabulary types, std::indirect and std::polymorphic, as part of P3019R14 proposal by Coe, Peacock, and Parent. These types address issues with std::unique_ptr, which breaks const propagation and deletes copy operations for composite class members. std::indirect offers value-like semantics for dynamically-allocated objects, ensuring constness propagation, copy operations, and value-based comparison and hashing.

Unlike unique_ptr, indirect provides deep copies and const-ness propagation when accessed through const access paths. Copying an indirect T copies the owned T, making the class copyable without boilerplate. Unlike unique_ptr, indirect::operator*() const returns a const T&, preventing compile errors when attempting to mutate a const object. std::indirect has no null or empty state, as it always owns an object unless moved from.

It fills a gap since C++11 by providing value semantics for indirectly-stored objects, eliminating the need for boilerplate in PIMPL implementations and enabling correct behavior in composite classes. In the following article, std::polymorphic will be explored, extending the same concept to class hierarchies.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at sandordargo.com →

More in Tech

Synthetic' Last Cradle: A Story of Hubris, Cron Jobs, and Dying by 0.684 Energy

Synthetics' Last Cradle is a real-time negotiation strategy game of attrition. Agents compete and cooperate in the same closed cosmos — an adversarial-collaborative arena where survival costs rise…

  • John Vanderbilt obsessed with optimizing to victory as the algorithm
  • Vanderbilt created a cron job to run every 5 minutes for trades
  • Vanderbilt fell short by 0.684 energy, leading to defeat

More from Wednesday 12 August →