On 2022-12-14 at 10:48, Frederick Virchanza Gotham wrote:
> On Wednesday, December 14, 2022 at 9:27:06 AM UTC, Bo Persson wrote:
>
>> You are using it wrong, anyway. When the value is an int&, you should
>> "forward" is using forward<int&>(arg).
>>
>> That's what happens with a forwarding reference.
>
>
> If I knew for certain that it was an "int&" then why would I bother using 'forward' on it?
Beats me, it was your example.
>
> The question I'm asking is why 'forward' in this case is turning an L-value into an R-value?
Because that's how template argument deduction works. When you
explicitly supply <int> to a function returning T&&, you get an int&&.
No surprise here.
> Is it because it's UB to use 'forward' on something that isn't a "template parameter forwarding reference"?
No, but not very useful. The whole idea of std::forward is that it can
adapt to the deduced template parameter. If there is no template, it is
outside if the intended use pattern.