What's the equivalent of std::is_const for references to const?

前端 未结 1 819
傲寒
傲寒 2021-01-07 19:53

Consider the code:

int const  x = 50;
int const& y = x;
cout << std::is_const::value << endl; // 1
cout << std::is_c         


        
相关标签:
1条回答
  • 2021-01-07 20:15

    Use 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;
    }
    

    See on coliru

    0 讨论(0)
提交回复
热议问题