|
Boost Users : |
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2005-04-05 19:16:16
template <typename T>
::boost::type_traits::yes_type
BOOST_TT_DECL is_same_tester(T*, T*);
::boost::type_traits::no_type
BOOST_TT_DECL is_same_tester(...);
template <typename T, typename U>
struct is_same_impl
{
static T t;
static U u;
BOOST_STATIC_CONSTANT(bool, value =
(::boost::type_traits::ice_and<
(sizeof(type_traits::yes_type) ==
sizeof(detail::is_same_tester(&t,&u))),
(::boost::is_reference<T>::value == ::boost::is_reference<U>::value),
(sizeof(T) == sizeof(U))
>::value));
};
Would it be any better to do is_same_tester with just one arg, like this:
template <typename T>
::boost::type_traits::yes_type
BOOST_TT_DECL is_same_tester(T*);
template <typename T>
::boost::type_traits::no_type
BOOST_TT_DECL is_same_tester(...);
and then the call is:.
(sizeof(type_traits::yes_type) ==
sizeof(detail::is_same_tester<T>(&u))),
(and then not need a 'static T t' at all?)
And does it make any difference to declare the U as a pointer:
static U *u; // and/or leave off the static
and then not pass it in by address:
(sizeof(type_traits::yes_type) ==
sizeof(detail::is_same_tester<T>(u))),
Or not bother with a U at all, but just cast 0 into a U*:
(sizeof(type_traits::yes_type) ==
sizeof(detail::is_same_tester<T>(static_cast<U *>(0)))),
Or does none of it really make a difference?
And while I am at it, what would the value of 'same' be:
struct A { int x; };
struct B : A;
static bool same = boost::type_traits::is_same<A, B>::value;
I suspect same == true, as B is castable to an A, and sizeof(B) == sizeof(A).
checking both is_same_tester<T>(u) and is_same_tester<U>(t) might be better?
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