# deduction guides for std::optional

> C++ Atlas: `cppatlas.com/w/cpp/utility/optional/deduction_guides` | Source: https://en.cppreference.com/w/cpp/utility/optional/deduction_guides | Domain: Utility | Standards: C++17

One deduction guide is provided for std::optional to account for the edge cases missed by the implicit deduction guides, in particular, non-copyable arguments and array to pointer conversion.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <optional>

template< class T >
optional(T) -> optional<T>; // (since C++17)
```

One deduction guide is provided for `std::optional` to account for the edge cases missed by the implicit deduction guides, in particular, non-copyable arguments and array to pointer conversion.

### Example

```cpp
#include <optional>
#include <type_traits>

int main()
{
    int a[2];
    std::optional oa{a}; // uses explicit deduction guide
    static_assert(std::is_same_v<decltype(oa), std::optional<int*>> == true);
}
```

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