> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C++ Array Binding

Array binding, formally a subset of C++17 structured binding, is a language mechanism that unpacks the elements of a raw C-style array into distinct, named identifiers. It enables the simultaneous declaration and initialization of multiple variables directly from an array's contiguous memory layout.

## Syntax

```cpp theme={"dark"}
cv-auto ref-operator [ identifier-list ] = array_expression;
```

* **`cv-auto`**: The `auto` keyword, optionally modified by `const` or `volatile`.
* **`ref-operator`**: Optional reference declarators (`&` or `&&`).
* **`identifier-list`**: A comma-separated list of variable names.
* **`array_expression`**: The source raw array being unpacked.

## Core Mechanics

When an array is bound, the compiler generates a hidden, anonymous entity initialized by the `array_expression`. The identifiers in the bracketed list do not become standard reference variables; rather, they become compiler-level aliases to the individual elements of that hidden entity.

**Arity Matching:** The number of identifiers in the `identifier-list` must exactly match the number of elements in the array. If the array has *N* elements, exactly *N* identifiers must be provided. Failure to match the arity results in a compile-time error.

**Type Deduction:** The type of each identifier is deduced exactly as the type of the corresponding array element. Array-to-pointer decay does not occur during structured binding.

## Binding Modes

The behavior of the bound identifiers depends entirely on the `cv-qualifiers` and `ref-operators` applied to `auto`. These qualifiers apply to the *hidden array entity*, not directly to the individual identifiers.

### 1. Binding by Value (`auto`)

Creates a complete, element-wise copy of the source array into the hidden entity. The identifiers alias the elements of the *copy*.

```cpp theme={"dark"}
int arr[3] = {1, 2, 3};
auto [x, y, z] = arr; 

x = 10; // Modifies the hidden copy's first element. 'arr[0]' remains 1.
```

### 2. Binding by Lvalue Reference (`auto&`)

The hidden entity becomes an lvalue reference to the source array. The identifiers alias the elements of the original array, allowing direct mutation.

```cpp theme={"dark"}
int arr[3] = {1, 2, 3};
auto& [refX, refY, refZ] = arr;

refX = 10; // Modifies 'arr[0]'. 'arr' is now {10, 2, 3}.
```

### 3. Binding by Rvalue Reference (`auto&&`)

Used when the `array_expression` is an rvalue (either a prvalue or an xvalue). The hidden entity becomes an rvalue reference, extending the lifetime of the temporary array to the scope of the binding. A prvalue of a raw array type can be created directly using a type alias and brace initialization.

```cpp theme={"dark"}
using IntArray = int[2];
auto&& [rval1, rval2] = IntArray{100, 200};

// IntArray{100, 200} is a prvalue.
// rval1 and rval2 alias the elements of the temporary array, 
// whose lifetime is extended to the scope of the binding.
```

### 4. CV-Qualified Binding (`const auto&`)

Applies `const` to the hidden entity, rendering the aliased elements read-only. Because structured binding identifiers are aliases and not standard reference variables, the deduced type of the identifier is strictly the `const`-qualified element type, not a reference type.

```cpp theme={"dark"}
int arr[3] = {1, 2, 3};
const auto& [cx, cy, cz] = arr;

// decltype(cx) is strictly 'const int', not 'const int&'.
// cx = 10; // Compile-time error: assignment of read-only variable 'cx'
```

## Multidimensional Arrays

When applying structured binding to a multidimensional array, the binding operates strictly on the first dimension. The resulting identifiers alias the nested arrays. Even when bound with a reference operator, the deduced type of the identifiers is strictly the element type of the array, not a reference type.

```cpp theme={"dark"}
int matrix[2][3] = {
    {1, 2, 3},
    {4, 5, 6}
};

auto& [row1, row2] = matrix;
// decltype(row1) is strictly int[3] (the first row).
// decltype(row2) is strictly int[3] (the second row).
// The identifiers act as aliases to the nested arrays.

row1[0] = 99; // Modifies matrix[0][0]
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
