P3978R1 — constant_wrapper should unwrap on call and subscript (3 items) LEWG
Matthias Kretz, Tomasz Kamiński
This paper proposes adding unwrapping overloads of operator() and operator[] to std::constant_wrapper, making them static. When all arguments satisfy constexpr-param, the operators re-wrap the result as a constant_wrapper (the 'can stay wrapped' behavior); otherwise they invoke the underlying value with the forwarded arguments (the 'it's the thing it holds' behavior). This resolves an inconsistency where call and subscript operators could not transparently unwrap constant_wrapper unlike other operators discoverable via ADL, mirroring the design of std::reference_wrapper. The paper also proposes moving constant_wrapper from to .

References — Anthropic Citations API

[1]
"The expression x + 1 in line #3 finds X::operator+ via ADL and thus converts the left operand to operator+ to X, returning int(2)."
[2]
"Do we expect cw to unwrap and then call the constant_wrapper overload?"
Summary: P3978R1 proposes extending constant_wrapper with operator() and operator[] overloads that unwrap their arguments, enabling constant_wrapper-wrapped callables and indexable objects to be invoked or subscripted while preserving compile-time constant propagation. Two surface-level prose errors were found.
Pipeline: Discovery (Anthropic Opus + Citations API) → Verification Gate (OpenRouter Opus) → Report Writer (OpenRouter Opus)
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.