> ## 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++ Rvalue Reference Parameter

An rvalue reference parameter is a function parameter declared with a double ampersand (`&&`) that binds exclusively to rvalues—temporary objects, literals, or objects explicitly cast to an rvalue reference. It provides a mechanism for a function to safely assume ownership of, or mutate, the internal state of an object that is guaranteed to be at the end of its lifetime.

```cpp theme={"dark"}
void process(std::string&& text);
```

## Binding Rules

An rvalue reference parameter strictly enforces value category binding during compilation:

* **Binds to prvalues (Pure Rvalues):** Literals (e.g., `42`) or temporary objects created by expression evaluation (e.g., `std::string("temp")`).
* **Binds to xvalues (eXpiring Values):** Objects explicitly cast to an rvalue reference, typically via `std::move()`.
* **Rejects lvalues:** It will result in a compilation error if an attempt is made to pass a named, persistent variable (an lvalue) directly to the parameter.

```cpp theme={"dark"}
void process(std::string&& text);

std::string str = "persistent";

process(std::string("temporary")); // Valid: binds to prvalue
process(std::move(str));           // Valid: binds to xvalue
process(str);                      // Error: cannot bind lvalue to rvalue reference
```

## Internal Value Category

A critical characteristic of an rvalue reference parameter is its value category *inside* the function scope. Although the parameter binds to an rvalue, the parameter itself has a name. In C++, any variable with a name is an **lvalue**.

Therefore, within the function body, the rvalue reference parameter is treated as an lvalue. If it needs to be passed to another function that also requires an rvalue reference, it must be explicitly cast back to an rvalue.

```cpp theme={"dark"}
void stepTwo(std::string&& data);

void stepOne(std::string&& data) {
    // 'data' is an lvalue here because it has a name.
    
    stepTwo(data);            // Error: 'data' is an lvalue
    stepTwo(std::move(data)); // Valid: explicitly cast back to xvalue
}
```

## Overload Resolution

Rvalue reference parameters participate heavily in overload resolution. When a function is overloaded with both an lvalue reference to `const` and an rvalue reference, the C++ compiler will deterministically route arguments based on their value category:

```cpp theme={"dark"}
void handle(const std::string& text); // Overload 1: Binds to lvalues (and rvalues as a fallback)
void handle(std::string&& text);      // Overload 2: Binds strictly to rvalues

std::string msg = "hello";
handle(msg);             // Resolves to Overload 1
handle(std::string("")); // Resolves to Overload 2
```

## Distinction from Forwarding References

An rvalue reference parameter requires a fully specified, concrete type (e.g., `Widget&&`). If the double ampersand is applied to a deduced template type parameter (e.g., `template <typename T> void func(T&& param)`), it ceases to be a strict rvalue reference. Instead, it becomes a **forwarding reference** (or universal reference), which utilizes reference collapsing rules to bind to either lvalues or rvalues depending on the argument passed.

<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>
