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 | ||||
|
Definiert im Header
<optional>
|
||
|
template
<
class
T
>
optional ( T ) - > optional < T > ; |
(seit C++17) | |
Ein deduction guide wird für std::optional bereitgestellt, um die Randfälle abzudecken, die von den impliziten Deduction Guides nicht erfasst werden, insbesondere nicht kopierbare Argumente und Array-zu-Zeiger-Konvertierung.
Beispiel
Diesen Code ausführen
#include <optional> #include <type_traits> int main() { int a[2]; std::optional oa{a}; // verwendet expliziten Deduction Guide static_assert(std::is_same_v<decltype(oa), std::optional<int*>> == true); }