Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions content/expansion-statements-library-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
execute: true
---

## What It Does

`std::integer_sequence` can now be used in `template for`
to conveniently write a loop where the loop index is a `constexpr` variable,
as well as to create a `constexpr` pack using structured bindings.
This is made possible by specializing `std::tuple_size`, `std::tuple_element`, and `std::get`
for `std::integer_sequence`.

## Why It Matters

These changes remove boilerplate code such as creating an immediately invoked lambda expression
when creating a `constexpr` pack of indices or writing a loop with a `constexpr` index.
This is especially important because C++26 supports pack indexing,
where a `constexpr` index is needed.

## Example

```cpp
#include <utility>
#include <tuple>
#include <print>

int main() {
auto tup = std::tuple{1, 3.14, "hello"};

// Output:
// tup[0] = 1
// tup[1] = 3.14
// tup[2] = hello
template for (constexpr std::size_t I : std::make_index_sequence<3>()) {
std::println("tup[{}] = {}", I, std::get<I>(tup));
}

constexpr auto [...Is] = std::make_index_sequence<3>();
}
```
2 changes: 2 additions & 0 deletions features_cpp26.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,8 @@ features:

- desc: "Library Support for Expansion Statements"
paper: P1789
summary: "Specializes `std::tuple_size`, `std::tuple_element`, and `std::get` for `std::integer_sequence` to make it usable in expansion statements and structured bindings."
content: expansion-statements-library-support.md
lib: true
support: [Clang 22]
ftm:
Expand Down