# std::experimental::swap(std::experimental::observer_ptr)

> C++ Atlas: `cppatlas.com/w/cpp/experimental/observer_ptr/swap2` | Source: https://en.cppreference.com/w/cpp/experimental/observer_ptr/swap2 | Domain: Technical specifications

Specializes the swap algorithm for std::experimental::observer_ptr. Swaps the pointers of lhs and rhs. Calls lhs.swap(rhs).

## Official Specification Summary (cppreference)

```cpp
template< class W >
void swap( observer_ptr<W>& lhs, observer_ptr<W>& rhs ) noexcept; // (library fundamentals TS v2)
```

Specializes the `swap` algorithm for `std::experimental::observer_ptr`. Swaps the pointers of `lhs` and `rhs`. Calls `lhs.swap(rhs)`.

### Parameters

- `lhs, rhs` - `observer_ptr`s whose contents to swap

### Return value

(none)

### Complexity

Constant.

### See also

- [`swap`](https://en.cppreference.com/w/cpp/algorithm/swap): swaps the values of two objects (function template)
- [`swap`](https://en.cppreference.com/w/cpp/experimental/observer_ptr/swap): swaps the watched objects (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/experimental/observer_ptr/swap2 (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.