deductiongu...rstd::tuple(3)

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

πŸ’– NAME πŸ’–

okay so bestie, this page is deductiongu...rstd::tuple(3) from the C++ Standard Libary section (yes, that’s literally how the header spells it, we’re keeping it πŸ’…). The actual name situation is deductionguidesforstd::tuple β€” and it’s exactly what it sounds like: deduction guides for std::tuple ✨.


🌸 Synopsis 🌸

Defined in header <tuple>. Every single one of these is since C++17, no cap 🫢.

(1) β€” since C++17

template<class... UTypes>
tuple(UTypes...) -> tuple<UTypes...>;

(2) β€” since C++17

template<class T1, class T2>
tuple(std::pair<T1, T2>) -> tuple<T1, T2>;

(3) β€” since C++17

template<class Alloc, class... UTypes>
tuple(std::allocator_arg_t, Alloc, UTypes...) -> tuple<UTypes...>;

(4) β€” since C++17

template<class Alloc, class T1, class T2>
tuple(std::allocator_arg_t, Alloc, std::pair<T1, T2>) -> tuple<T1, T2>;

(5) β€” since C++17

template<class Alloc, class... UTypes>
tuple(std::allocator_arg_t, Alloc, tuple<UTypes...>) -> tuple<UTypes...>;

These deduction guides are here for std::tuple to cover the edge cases that the implicit deduction guides miss β€” especially non-copyable arguments and array to pointer conversion 😭πŸ”₯.


πŸ§ͺ Example πŸ§ͺ

// Run this code

#include <tuple>
int main()
{
    int a[2], b[3], c[4];
    std::tuple t1{a, b, c}; // explicit deduction guide is used in this case
}

like, this example is literally the moment: int a[2], b[3], c[4]; and then std::tuple t1{a, b, c}; β€” and the explicit deduction guide is used in this case πŸ’–. iconic behavior, honestly.


mwah πŸ’‹ sign-off time: source is http://cppreference.com, version/date is 2024.06.10, and the footer manual name is deductiongu...rstd::tuple(3) β€” periodt πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from