2
#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;
}

我不明白为什么 static_assert 在这里失败,V不等于V&&这里?

4

1 回答 1

2

V不是右值引用 -decltype(element)是(如果element是右值)。V只是 的一般类型element。具体来说:

typename std::remove_reference<decltype(element)>::type; // V
于 2013-11-03T13:32:48.170 回答