Date: Sat, 06 Sep 2025 02:59:08 +0100
> There is no way to tell, from inside the function block, if the parameter> passed to this function is a prvalue or an xrvalueI assume that you meant to say xvalue instead of xrvalue.Your assumption is correct.The reason theycan't be distinguished is that it's not possible to forward a prvalue. Consider:struct S{ S(); S(S&&)=delete;};void foo(S);void bar(S s){ //...}The class S cannot be copied nor moved.Correct There is no mechanism currently thatwould allow for forwarding bar's parameter to foo, I don't see this statement in the example!But I assume you mean this:void bar (S s){ foo(s); // compilation error}If so, then from foo signature it is clear that you are asking for temporary, not lvalue ref nor an rvalue ref.since to achieve somethinglike that would mean the caller of bar would somehow need to know where bar willforward it to construct the object correctly.I didn't understand this statement. When taking a prvalue of type T there are only two types of parameters thatwould make sense: T and T&&. As described above, when the parameter has type Tit can still only be forwarded as an xvalue. So, when just forwarding the Tthere generally won't be any differences. The parameter having type T&& has afew advantages though. If a reference to the object is returned, the caller canuse that object inside of the full expression which the call is in. When theparameter has type T it might be destroyed at the end of the call. For genericcode that forwards arbitrary types, using T&& simplifies code since it can relyon reference collapsing and that the parameter has a reference type.Logical and intuitively: T is not T&&T is about to die in the scope it was created.T&& is not.Calling foo:foo(T{}) <---1Should be different than callingfoo(std::move(t_val)) <--2Inside call 1, I can still the parameter resource since I'm certain it is about to end lifetime. But inside call 2, I'm not sure.This has an impact on the assembly that would be generated if we can make a difference between xvalue and prvalue. On Fri, Sep 5, 2025 at 8:18 PM organicoman via Std-Proposals<std-proposals_at_[hidden]> wrote:>> Hello,> Given the following function signature:>> RetType foo(T&& arg);>> There is no way to tell, from inside the function block, if the parameter passed to this function is a prvalue or an xrvalue, since both can bind to T&&.> Despite there is a fundamental difference between prvalue and xrvalue, yet we are not taking advantage of that because we cannot differentiate between them.>> Is there any proposal talking about this problem?>> Regards> Og>> --> Std-Proposals mailing list> Std-Proposals_at_[hidden]> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals-- Std-Proposals mailing listStd-Proposals_at_[hidden]://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-09-06 01:59:10