Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-10-26 08:20:52


Alexander Neubeck wrote:
> Hi.
>
> I recognized a strange (wrong?) behaviour of gcc-3.4.1 (and
> gcc-3.3.3).
> When adding const to a type T and this type T is a reference, the
> result is just T again (with reference, but witout const)!
> Then I tested, if boost handles this case correctly, and it didn't.
> The type of add_const< int & >::result is int & and not as expected
> const int &.

Your expectation was wrong. A "const" reference to int is not the same as a
reference to a const int.

[...]

> My questions to you:
> Can anybody verify this behaviour?
> Is this behaviour intended?
> If yes, WHY?

Because that's how top-level const works. int * const != int const *, and
int & const != int const &.

> P.S:
> It was quite difficult to check, which result-type the add_const
> really created. First I used typeid( ... ).name(). But then I
> recognized that int, int &, const int & produce ALL THE SAME name?!?

Yes, that's how typeid works.


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