Skip to content

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

@igel-kun

Description

@igel-kun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions