C++ Logo

std-proposals

Advanced search

Re: [std-proposals] explicit modifier for R-value references

From: Giuseppe D'Angelo <giuseppe.dangelo_at_[hidden]>
Date: Mon, 19 Jun 2023 14:11:18 +0200
Il 19/06/23 11:32, Frederick Virchanza Gotham via Std-Proposals ha scritto:
> You could use it in function parameters as well:
>
> void SetVector( vector<int> &&explicit arg )
> {
> static vector<int> vec;
> vec = arg; // no need for 'move' here
> }

This sounds extremely dangerous, because

void SetVector( vector<int> && explicit arg )
{
    use(arg); // e.g. print(arg). this is now use(std::move(arg))
    m_vec = arg; // hence this is using a moved-from instance
}


My 2 c,

-- 
Giuseppe D'Angelo

Received on 2023-06-19 12:11:22