P4343

Adding clear() to Container Adaptors

R1

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.

Authors
Shubham Avasthi
Mailing
2026-09
Doc date
2026-09-10
Audience
SG18

Revision history

  1. 2026-09
    R1 Selected (shown above)
  2. 2026-08
    R0 SG18

    Adding clear() to Container Adaptors