c++ - Universal reference deduction if the argument is address -
quick query regarding universal references:
let's have code
int q = 10; auto && wtf = &q; this 1 compiles fine, have no idea what's happening behind hood. it's taking reference address? isn't pointer's job?
i trying deduce auto&&'s type , did by:
int & test = &q //error int && test = &q //error so become? need clarification on what's happening , what's purpose of taking & universal reference? doing because trying understand std::bind since can take address or pointers(which address of being pointed aka pointer's value).
when write &q create temporary value.
an rvalue [...] xvalue, temporary object (12.2) or subobject thereof, or value not associated object. [§ 3.10]
those best bound rvalue references, so
auto && wtf = &q; becomes rvalue reference (&& , && stays &&) type of &q. isn't int, it's int *. that's why manual attempt failed.
if instead bind lvalue, local variable, lvalue reference:
int * qptr = &q; auto && wtf2 = qptr; // auto becomes (int *)& // & combined && becomes & the whole thing can new seen in action here.
Comments
Post a Comment