deductiongu...td::optional(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’… deductionguidesforstd::optional πŸ’…

okay so bestie, welcome to the C++ Standard Libary page for deductiongu...td::optional(3) β€” the header is giving cryptic, so we’re just folding the manual name in right here and keeping it cute. 🫢✨

πŸŽ€ NAME πŸŽ€

  • deductionguidesforstd::optional β€” deductionguidesforstd::optional

✨ Synopsis ✨

Defined in header <optional> πŸ¦‹

template< class 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. That’s literally the assignment, no cap. πŸ’…

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

source/version + date sign-off, bestie: http://cppreference.com Β· 2024.06.10 Β· deductiongu...td::optional(3) β€” slay and goodbye πŸ’–πŸŒˆ

πŸ“¦ where this page comes from