P3978R1 — constant_wrapper should unwrap on call and subscript
(3 items)
LEWG
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 .
-
Section 4.1 (Exploration of potential ambiguities) — Prose refers to cw
(a type argument), but cw requires a value; the corresponding code block correctly uses cw (a value argument). The prose should read cw . [1] - Section 3.2 (Status Quo Examples) — The phrase 'converts the left operand to operator+ to X' is ungrammatical; 'to operator+' is extraneous. Should read 'converts the left operand of operator+ to X' or 'converts the left operand to X'. [2]
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)."
"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?"
"Do we expect cw
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.
Provenance: All references are machine-verified character positions from the Anthropic Citations API — deterministic, exact substrings, not model-generated quotes.