Why does std::is_const<const int&>::value evaluate to false?
c++, c++11, type-traits
Solution
Perhaps it'll be easier to understand with this example
std::cout << std::is_const<int const *>::value << "\n"; // pointer to const int
std::cout << std::is_const<int * const>::value << "\n"; // const pointer to int
Output:
false
true
The first type is a pointer to a `const int`, while in the second the `int *` itself is `const`. Hence it results in `true` while the former is `false`. Similarly, what you have a reference to a `const int`. If `int& const` were valid it'd result in `true`.
Problem
This is a spin off of the question How to check if object is const or not?. I was surprised to see the following program ``` #include <iostream> #include <type_traits> int main() { std::cout << std::boolalpha; std::cout << std::is_const<const int&>::value << "\n"; } ``` produced this output ``` false ``` In what context does it make sense to think of `const int&` as a non-const type?