P1306R5 — Expansion statements
Dan Katz, Barry Revzin, Andrew Sutton, Sam Goodrick, Daveed Vandevoorde
WG21
This paper proposes a new kind of statement that enables the compile-time repetition of a statement for each element of a tuple, array, class, range, or brace-delimited list of expressions. Existing methods for iterating over a heterogeneous container inevitably leverage recursively instantiated templates to allow some part of the repeated statement to vary (e.g., by type or constant) in each instantiation. While such behavior can be encapsulated in a single library operation (e.g., Boost.Hana’s `for_each`) or, potentially in the future, using the `[:expand(...):]` construct built on top of [[P2996R10] (Reflection for C++26)](https://wg21.link/p2996r10) reflection facilities, there are several reasons to prefer language support: