Boost logo

Boost Users :

From: Philippe Mori (philippe_mori_at_[hidden])
Date: 2005-02-15 14:02:47


>
> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net