Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lifetime-talk of 2018 and take on structured bindings #13

Open
igel-kun opened this issue May 17, 2024 · 0 comments
Open

lifetime-talk of 2018 and take on structured bindings #13

igel-kun opened this issue May 17, 2024 · 0 comments

Comments

@igel-kun
Copy link

igel-kun commented May 17, 2024

hey, I love your talks, but one thing had me confused:
In the CppCon2018 talk about object lifetimes, the slides claim that auto [s, i] = get_Holder(); was essentially equivalent to

auto e = get_Holder();
auto& s = e.s;
auto& i = e.i;

But that would mean s is a reference, which is not how I understand auto [s, i] to behave. Indeed, std::is_reference_v<decltype(s)> says it's not a reference:

[...]

struct Holder { S s; int i; };
Holder get_Holder() { return {}; }

[...]

S get_S() {
    auto [s, i] = get_Holder(); /// structured bindings
    
    auto e = get_Holder();
    auto& _s = e.s;
    auto& _i = e.i;
    
    std::cout << std::is_reference_v<decltype(s)> << std::is_reference_v<decltype(_s)> <<"\n";
    return s;
}

Output:

01

So, I seem to not get something here. Do you have a guess on what's up?

Cheers & thanks for your time, man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant