deduction guides for std::optional
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::optional
(C++26)
(C++26)
(C++23)
(C++23)
(C++23)
Deduction guides
Defined in header
<optional>
template< class T >
optional(T) -> optional<T>;
(since C++17)
optional(T) -> optional<T>;
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.
[edit] Example
Run this code
#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); }