P3978R2 — 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, and using INVOKE consistently in both the wrapping and unwrapping modes of the call operator. The design follows the principle that constant_wrapper should transparently unwrap into the value it holds unless all operands are constant_wrappers and the result can remain wrapped, achieving behavioral consistency with how other operators already work via ADL and the conversion operator. The paper also proposes moving constant_wrapper from to .

References — Anthropic Citations API

[1]
"The subscript in #2 does not work because, even though array is an associated namespace and x is convertible to array, the array::operator[] member function is not found."
Summary: Proposes extending std::constant_wrapper so that its operator() and operator[] forward to the underlying wrapped value, enabling constant_wrapper objects to be called or subscripted directly when the wrapped value supports those operations.
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.