Question

#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 ?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top