You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## II. Real-World Case — Compile-Time Index Sequences in the STL
122
+
123
+
> C++14 introduced `std::integer_sequence` and `std::make_index_sequence`, which rely on relaxed constexpr for compile-time integer generation. The examples below cite the vendored [MSVC STL](https://github.com/mcpp-community/d2mcpp/tree/main/msvc-stl) (source: [`msvc-stl/stl/inc/tuple`](https://github.com/mcpp-community/d2mcpp/blob/main/msvc-stl/stl/inc/tuple#L323-L343)); `_Tag` / `_Tpl` are internal tags and types and can be ignored while reading
124
+
125
+
### std::tuple Compile-Time Construction — index_sequence Unfolds Parameter Packs
126
+
127
+
`std::tuple` must extract elements one by one from a tuple-like object and construct its own members — this process must happen at compile time. MSVC STL uses `make_index_sequence` to generate compile-time indices and expand parameter packs:
`make_index_sequence<N>` generates `index_sequence<0, 1, ..., N-1>` at compile time, enabling the tuple constructor to extract elements via `get<0>` / `get<1>` / ... sequentially. This is the canonical post-C++14 constexpr pattern — iteration is not a runtime concept but achieved through compile-time integer sequences and pack expansion
145
+
146
+
### std::integer_sequence — the C++14 Compile-Time Integer Carrier
147
+
148
+
```cpp
149
+
// MSVC STL · msvc-stl/stl/inc/utility (abridged)
150
+
template <class_Ty, _Ty... _Vals>
151
+
struct integer_sequence {
152
+
static_assert(is_integral_v<_Ty>,
153
+
"integer_sequence<T, I...> requires T to be an integral type.");
154
+
};
155
+
156
+
template <size_t... _Vals>
157
+
using index_sequence = integer_sequence<size_t, _Vals...>;
158
+
159
+
template <size_t _Size>
160
+
using make_index_sequence = __make_integer_seq<integer_sequence, size_t, _Size>;
161
+
```
162
+
163
+
> Summary: Both `std::make_index_sequence` and `std::tuple`'s compile-time construction depend on the relaxed constexpr environment introduced in C++14. Without constexpr that supports loops and branches, the standard library would rely entirely on compiler internals for integer sequence generation rather than on the expressive power of the C++ language itself
164
+
165
+
## III. Notes
122
166
123
167
### Operations Still Banned in C++14 constexpr
124
168
@@ -157,7 +201,7 @@ int main() {
157
201
158
202
A constexpr specifier does not change the ODR linkage in C++14 (C++17 later made constexpr functions implicitly inline), nor does it mean every function that can be constexpr should be. If a function is almost always called at runtime, adding constexpr increases the interface constraint with little practical benefit
159
203
160
-
## III. Exercise Code
204
+
## IV. Exercise Code
161
205
162
206
### Exercise Code Topics
163
207
@@ -170,7 +214,7 @@ A constexpr specifier does not change the ODR linkage in C++14 (C++17 later made
0 commit comments