samedi 1 décembre 2018

Why does `std::is_const_v` not behave as expected?

#include <iostream>
#include <type_traits>

using namespace std;

template<typename T>
void f(T&&)
{
    cout << boolalpha << std::is_const_v<T> << endl;
    cout << boolalpha << std::is_const_v<T&&> << endl;
}

int main()
{
    const int n = 1;
    f(n);
}

The output is:

false
false

Here, n is an obvious const variable, why does std::is_const_v not behave as expected?

Aucun commentaire:

Enregistrer un commentaire