Monday, September 24, 2018

Digest for comp.lang.c++@googlegroups.com - 3 updates in 2 topics

Bart <bc@freeuk.com>: Sep 24 11:15PM +0100

On 24/09/2018 21:53, Vir Campestris wrote:
>> number of precedences.
 
> ... which is why I bracket everything. I'm "agnostic" in this - I don't
> know the full order of precedences, and I don't believe you do either.
 
Tim Rentsch does. I think he expects everyone else to as well (as you
might notice in his code).
 
--
bart
ram@zedat.fu-berlin.de (Stefan Ram): Sep 24 09:22PM

> };
>Both look like an "universal reference" situation, but apparently
>the second isn't?
 
Yes, because the second template does not directly precede
the function.
 
And then, I believe, the following might happen here:
 
When you call
 
instantiate( a, b, c )
 
,
 
Types...
 
in »instantiate« is deduced to be »( int&, int&, int& )«,
so the return type of »instantiate« is
 
MyClass< int&, int&, int& >
 
, thus the constructor now has the (hypothetical) signature
 
MyClass( int & &&, int & &&, int & && ) {}
 
and, IIRC, this is reduced to
 
MyClass( int &, int &, int & ) {}
 
. So you might be using a constructor with lvalue reference
parameters, in which case it would be no surprise that it
accepts lvalue arguments!
 
Disclaimer: I'm not actually familiar with these techniques,
so I might be totally wrong!
ram@zedat.fu-berlin.de (Stefan Ram): Sep 24 09:52PM

>in »instantiate« is deduced to be »( int&, int&, int& )«,
 
No parameter packs are required to see this.
The following example suffices.
 
template< typename T >void c( T && ){}
template< typename F >void f( F && r ){ c< F >( r ); }
int main(){ int a = 1; f( a ); }
 
When »f( a )« is called, »F« becomes »int&«, and c accepts lvalues.
When »f( 1 )« is called, »F« becomes »int«, and c accepts rvalues.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: