|
Boost Users : |
Subject: Re: [Boost-users] How does BOOST_TYPEOF works?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-20 23:30:42
AMDG
Peng Yu wrote:
> I tried to read the source code to figure out how BOOST_TYPEOF works.
> But I still don't understand how it works. Can somebody tell me how it
> works?
>
It works in 3 different ways depending on your compiler.
1) If your compiler has a typeof operator, Boost.Typeof uses that.
2) If your compiler has a specific bug that allows certain class
templates to be specialized on the fly, Boost.Typeof uses this
capability to associate each type with a unique integer and
get something to the effect of
typename get_associated_type<sizeof(get_size(T))>::type
where get_size is defined as
template<class T>
char (&get_size(const T&))[get_associated_int<T>::value];
3) If all else fails, Boost.Typeof associates a unique integer with each
type/class template. (This is what BOOST_TYPEOF_REGISTER_TYPE and
friends are for). Then, every type can be represented as a sequence
of integers.
This sequence of integers is retrieved using sizeof.
In Christ,
Steven Watanabe
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