deduction guides for
std::optional
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::optional
| Member functions | ||||
| Observers | ||||
| Iterators | ||||
|
(C++26)
|
||||
|
(C++26)
|
||||
| Monadic operations | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Modifiers | ||||
| Non-member functions | ||||
| Deduction guides | ||||
| Helper classes | ||||
| Helper objects | ||||
|
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
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); }