Chris Goller
His solution is SO much better then mine.
You can do even better (hint: you don't need to use add_const).
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
::type, int &>::value; However! bool "a" is true. So my question is why is "a" true? Why isn't add_const
::type == int const &?
It's not a very interesting answer: that's just the way the C++ type system works. The rule is, essentially, that add_const<T>::type is equivalent to T const. When you do that with int&, you get int& const Think of that as being like int* const The int isn't const, here; the pointer is. But unlike pointers, references can't be made to refer to new things. So int& const and int& are really the same type. Both are different from int const& where the int is immutable through that reference. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com