RE: [Boost-users] gcc-3.4.1 and add_const
This randomly made me wonder ... if(const int * == int const *) Is that just a personal preference thing? Gaz -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: 26 October 2004 14:21 To: boost-users@lists.boost.org Subject: Re: [Boost-users] gcc-3.4.1 and add_const 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Foster, Gareth wrote:
This randomly made me wonder ...
if(const int * == int const *)
Is that just a personal preference thing?
Yes, in fact the only reason for allowing const int as an alias for int const is because people prefer it that way. However the regular syntax has some advantages. For example, people that are used to 'const int *' sometimes expect const PtrInt, where PtrInt is a typedef to int *, to produce the same result. It doesn't; it yields int * const.
participants (2)
-
Foster, Gareth
-
Peter Dimov