P4343R1 — Adding clear() to Container Adaptors
Shubham Avasthi
SG18
Revisions R1Sep 2026R0Aug 2026
This paper proposes adding a <ins>clear()</ins> member function to the standard container adaptors (<ins>std::priority_queue, std::queue, and std::stack</ins>). This addition allows developers to empty the contents of an adaptor while preserving the memory capacity of its underlying container, thereby avoiding unnecessary dynamic memory reallocations. To ensure strict backward compatibility with custom underlying containers, this method is conditionally enabled via a C++20 <ins>requires</ins> clause.