|
Boost : |
From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2005-06-22 15:12:54
"Andy Little" <andy_at_[hidden]> wrote in message
news:d9ccs0$qm7$2_at_sea.gmane.org...
>
> "Alexander Nasonov" <alnsn-boost_at_[hidden]> wrote in message
> news:loom.20050622T171035-650_at_post.gmane.org...
> > Andy Little <andy <at> servocomm.freeserve.co.uk> writes:
> >
> >> Isnt any use case for this covered by Boost.Typeof ?
> >
> > Quote from Boost.Typeof documentation:
> >
> > Other integral types, such as *enums*, need to be described explicitly
with
> > the
> > BOOST_TYPEOF_INTEGRAL macro, like (BOOST_TYPEOF_INTEGRAL(MyEnum))
>
> I think that applies when the type of the enum is taken, but where
required
> enums are promoted to some integer type,dependent on numeric value.
> In what other situation is promotion required?
>
> #define BOOST_TYPEOF_COMPLIANT
> #include <boost/typeof/typeof.hpp>
> #include <iostream>
>
> struct X{
> enum id{x,y};
> };
>
> int main()
> {
> BOOST_AUTO( result , X::x + X::y);
> std::cout << typeid(result).name() <<'\n';
> }
>
> Andy Little
FWIW, something like this:
template<class T>
struct promoted
{
typedef BOOST_TYPEOF_TPL(T()+T()) type;
};
Would work on any integral type without registration.
Enums can't be the result of a promotion, so no need to worry about their
registration.
Regards,
Arkadiy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk