|
Boost Users : |
From: Alexander Neubeck (aneubeck_at_[hidden])
Date: 2004-10-26 06:43:56
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 &.
Next I was looking into the boost-Implementation of add_const and found
something like (hidden in a makro):
template< class T >
struct add_const {
typedef const T result;
// same result with:
// typedef T const result;
};
The only way I could get the correct behaviour was to add
specializations for ALL combinations:
template< class T >
struct add_const< T & > {
typedef const T & result;
};
template< class T >
struct add_const< const T & > {
typedef const T & result;
};
template< class T >
struct add_const< T * > {
typedef const T * result;
};
...
My questions to you:
Can anybody verify this behaviour?
Is this behaviour intended?
If yes, WHY?
thx a lot
Alexander
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?!?
Therefore I used an abstract function with the unknown type. In a
derived class I overloaded all possible solutions and printed the
CORRECT type...
Any suggestions here?
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