Namespaces
Variants

deduction guides for std::optional

From cppreference.net
Utilities library
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

#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);
}