std::is_rvalue_reference inside template function with rvalue reference parameter

StackOverflow https://stackoverflow.com/questions/19753450

  •  03-07-2022
  •  | 
  •  

Pergunta

#include<iostream>
#include<vector>

struct Empty {};

template <typename V>
void add(V&& element)
{
    static_assert( std::is_rvalue_reference<V>::value, "V is not a rvalue reference");
}

int main(int argc, char *argv[])
{
    add(Empty());   

    std::cin.ignore();
    return 0;
}

I don't get why static_assert fail here, V isn't equal to V&& here ?

Foi útil?

Solução

V is not the rvalue-reference - decltype(element) is (if element is an rvalue). V is simply the general type of element. Specifically:

typename std::remove_reference<decltype(element)>::type; // V
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top