Create a compile-time C++ utility that concatenates two index-sequence packs unchanged through variadic-template specialization, a convenient alias, and static assertions for boundary cases.
Concatenate Two C++ Index Sequences at Compile Time
Company: Squarepoint
Role: Risk Technology Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
## Interview Prompt
Write a compile-time C++ utility that takes two `std::index_sequence` types and
produces one `std::index_sequence` containing the first pack followed by the
second pack. Explain the variadic-template partial specialization, expose a
convenient alias, and show compile-time tests. Preserve values exactly; do not
offset the second sequence unless the contract explicitly asks for that variant.
### Constraints & Assumptions
- Both inputs are `std::index_sequence` specializations over `std::size_t` values.
- The result is a type computed entirely at compile time.
- Empty sequences and repeated values are valid.
- No runtime container or loop is involved.
### Clarifying Questions to Ask
- Should the second pack be appended unchanged or offset by the first pack's length?
- Is a struct with a nested `type`, an alias template, or both expected?
- Which C++ language standard is available?
### What a Strong Answer Covers
- A primary template plus specialization that pattern-matches both index-sequence packs.
- Expansion into `std::index_sequence<I..., J...>` in the required order.
- An alias that removes repeated `typename ...::type` syntax.
- Static assertions for empty, singleton, repeated, and multi-element sequences.
### Follow-up Questions
- How would you offset every value in the second sequence by the first sequence's length?
- How would you concatenate an arbitrary number of sequences?
- Where are index sequences useful in tuple or parameter-pack code?
Overview: Create a compile-time C++ utility that concatenates two index-sequence packs unchanged through variadic-template specialization, a convenient alias, and static assertions for boundary cases.
Write a compile-time C++ utility that takes two std::index_sequence types and
produces one std::index_sequence containing the first pack followed by the
second pack. Explain the variadic-template partial specialization, expose a
convenient alias, and show compile-time tests. Preserve values exactly; do not
offset the second sequence unless the contract explicitly asks for that variant.
Constraints & Assumptions
Both inputs are
std::index_sequence
specializations over
std::size_t
values.
The result is a type computed entirely at compile time.
Empty sequences and repeated values are valid.
No runtime container or loop is involved.
Clarifying Questions to Ask Guidance
Should the second pack be appended unchanged or offset by the first pack's length?
Is a struct with a nested
type
, an alias template, or both expected?
Which C++ language standard is available?
What a Strong Answer Covers Guidance
A primary template plus specialization that pattern-matches both index-sequence packs.
Expansion into
std::index_sequence<I..., J...>
in the required order.
An alias that removes repeated
typename ...::type
syntax.
Static assertions for empty, singleton, repeated, and multi-element sequences.
Follow-up Questions Guidance
How would you offset every value in the second sequence by the first sequence's length?
How would you concatenate an arbitrary number of sequences?
Where are index sequences useful in tuple or parameter-pack code?