|
Boost : |
From: Brad King (brad.king_at_[hidden])
Date: 2001-01-25 09:47:18
Hello, all:
I've been digging through the type_traits package to find how various
hacks were done to support compilers like MSVC++, and I noticed a
simplification that could be made to the library. The is_const struct
uses a static member in order to get a pointer of the appropriate type to
pass to its helper function. This could be done with a cast of a null
pointer instead:
template <typename T>
struct is_const
{
private:
static T t;
public:
enum{ value = (sizeof(detail::yes_result)
== sizeof(detail::is_const_helper(&t))) };
};
could become
template <typename T>
struct is_const
{
enum{ value = (sizeof(detail::yes_result)
== sizeof(detail::is_const_helper(static_cast<T*>(0)))) };
};
static_cast<T*>(0) could be replaced with (T*)0 if static_cast isn't
supported by some compiler.
This seems to work fine under gcc 2.95.2 and VC++ 6.0sp4 for me. Is there
some other compiler for which it won't work?
-Brad
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk