Topic: is_const<T> gives wrong answer for references and functions


Author: notbob@tessellation.com (Robert Allan Schwartz)
Date: Wed, 7 May 2003 23:52:19 +0000 (UTC)
Raw View
The program:

template <typename T>
class is_const { public: static const bool value = false; };

template <typename T>
class is_const<const T> { public: static const bool value = true; };

#include <iostream>

int main()
{
 std::cout << "is_const<bool &>::value = " << is_const<bool &>::value
<< std::endl;

 std::cout << "is_const<void (void)>::value = " << is_const<void
(void)>::value << std::endl;
 std::cout << "is_const<int  (void)>::value = " << is_const<int
(void)>::value << std::endl;
 std::cout << "is_const<int  (int )>::value = " << is_const<int  (int
)>::value << std::endl;

 return 0;
}

gives the results:

is_const<bool &>::value = 1
is_const<void (void)>::value = 1
is_const<int  (void)>::value = 1
is_const<int  (int )>::value = 1

on g++ v3.2, but gives the results:

is_const<bool &>::value = 0
is_const<void (void)>::value = 0
is_const<int  (void)>::value = 0
is_const<int  (int )>::value = 0

on metrowerks v7.

I believe the answers should all be 0.

What does the standard say?

Thank you,

Robert Schwartz

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: google@vandevoorde.com (Daveed Vandevoorde)
Date: Thu, 8 May 2003 18:57:38 +0000 (UTC)
Raw View
notbob@tessellation.com (Robert Allan Schwartz) wrote:
> The program:
>
> template <typename T>
> class is_const { public: static const bool value = false; };
>
> template <typename T>
> class is_const<const T> { public: static const bool value = true; };
>
> #include <iostream>
>
> int main()
> {
>  std::cout << "is_const<bool &>::value = " << is_const<bool &>::value
> << std::endl;
>
>  std::cout << "is_const<void (void)>::value = " << is_const<void
> (void)>::value << std::endl;
>  std::cout << "is_const<int  (void)>::value = " << is_const<int
> (void)>::value << std::endl;
>  std::cout << "is_const<int  (int )>::value = " << is_const<int  (int
> )>::value << std::endl;
>
>  return 0;
> }
>
> gives the results:
>
> is_const<bool &>::value = 1
> is_const<void (void)>::value = 1
> is_const<int  (void)>::value = 1
> is_const<int  (int )>::value = 1
>
> on g++ v3.2, but gives the results:
>
> is_const<bool &>::value = 0
> is_const<void (void)>::value = 0
> is_const<int  (void)>::value = 0
> is_const<int  (int )>::value = 0
>
> on metrowerks v7.
>
> I believe the answers should all be 0.
>
> What does the standard say?

I believe it agrees with you.  All these types
have a certain immutability about them, but that
doesn't make them const qualified.

        Daveed

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]