Подтвердить что ты не робот

Что эквивалентно std:: is_const для ссылок на const?

Рассмотрим код:

int const  x = 50;
int const& y = x;
cout << std::is_const<decltype(x)>::value << endl; // 1
cout << std::is_const<decltype(y)>::value << endl; // 0

Это имеет смысл, потому что y не является ссылкой const, это ссылка на const.

Существует ли foo такое, что std::foo<decltype(y)>::value равно 1? Если нет, то каково это было бы определить мою собственную?

4b9b3361

Ответ 1

Используйте remove_reference:

#include <string>
#include <iostream>
#include <type_traits>
using namespace std;

int main()
{
    int const  x = 50;
    int const& y = x;
    cout << std::is_const<std::remove_reference<decltype(x)>::type>::value << endl; // 1
    cout << std::is_const<std::remove_reference<decltype(y)>::type>::value << endl; // 1

    return 0;
}

Смотрите на coliru