
However, when I first saw it I thought it must be wrong because I assumed that add_const on a reference would would return a const reference. In other words, the code below would be false:
bool a = is_same<add_const<int &>::type, int &>::value;
However! bool "a" is true. So my question is why is "a" true? Why isn't add_const<int &>::type == int const &?
I thought the same thing at first but it makes senses when we compare a reference to a constant pointer. add_const<int * const>::type would be int * const and not int const * const. You might also try the following : template <typename T> struct AC { typedef const T type; }; and then check the result of is_same<AC<int &>, int&>::value. Under Visual C++ with default compilation setting AC struct will give a compilation warning when template argument is a reference : warning C4181: qualifier applied to reference type; ignored
Thanks,
Chris
Philippe