Date: Sun, 13 Apr 2025 17:25:59 +0100
On Sunday, April 13, 2025, Robin Savonen Söderholm <
robinsavonensoderholm_at_[hidden]> wrote:
> But '&&' does not mean 'forwarding reference'. It means 'rvalue
> reference'. It's just that an rvalue reference of an lvalue reference is an
> lvalue reference.
>
If what you say were true, then the following would also be a forwarding
reference:
template<typename T>
void Func( array<T, 8u> &&arg ) { }
But it's not. It'a actually just an Rvalue reference, and 'arg' will never
be an Lvalue.
It also ceases to be a forwarding reference if you throw in a CV qualifier
of any kind:
template<typename T>
void Func( T volatile &&arg ) { }
So if you have a template function with a template type of T, and a
function parameter of type 'T&&', then the '&&' doesn't mean Rvalue
reference. It means 'forwarding reference', and it is horrid. They should
have went with:
template<typename T>
void Func( T LorR arg ) { }
or perhaps even:
template<typename T>
void Func( T & || && arg ) { }
robinsavonensoderholm_at_[hidden]> wrote:
> But '&&' does not mean 'forwarding reference'. It means 'rvalue
> reference'. It's just that an rvalue reference of an lvalue reference is an
> lvalue reference.
>
If what you say were true, then the following would also be a forwarding
reference:
template<typename T>
void Func( array<T, 8u> &&arg ) { }
But it's not. It'a actually just an Rvalue reference, and 'arg' will never
be an Lvalue.
It also ceases to be a forwarding reference if you throw in a CV qualifier
of any kind:
template<typename T>
void Func( T volatile &&arg ) { }
So if you have a template function with a template type of T, and a
function parameter of type 'T&&', then the '&&' doesn't mean Rvalue
reference. It means 'forwarding reference', and it is horrid. They should
have went with:
template<typename T>
void Func( T LorR arg ) { }
or perhaps even:
template<typename T>
void Func( T & || && arg ) { }
Received on 2025-04-13 16:26:02