r值参数确实是函数范围内的l值参数吗?

问题描述 投票:1回答:1

我在实现list类的代码中找到了以下代码段

    void push_front( const T & x ) { insert( begin( ), x ); }

    void push_front( T && x ) { insert( begin( ), std::move( x ) );}

现在我知道,如果我有一个将参数作为r-value的函数,则该参数在函数范围内将为l-value(不是吗?)>]

所以我可以用以下内容替换之前的代码段

void push_front( const T & x ) { insert( begin( ), x ); }

void push_front( T && x ) { push_front( x );}

第一个问题:我对吗?

[第二个:通过考虑第一个代码段中的r-value参数是第二个函数内部的l-value参数,将std::move( x )x强制转换为l-valuer-value和函数[C0 ]调用函数push_front()r-value版本或什么?

我在实现列表类的代码中找到以下代码段void push_front(const T&x){insert(begin(),x); } void push_front(T && x){insert(begin(),std:...

c++ move-semantics
1个回答
0
投票

我有一个将参数作为r值的函数,该参数在函数范围内将是l值

© www.soinside.com 2019 - 2024. All rights reserved.