Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-09-28 05:51:47


----- Original Message -----
From: <garfaus_at_[hidden]>

> Just another idea for implementing usual arithmetic
> conversions between types. Perhaps it might be useful.
>
> It is is used as
>
> arithmetic_conversion<A, B>::result
>
> where 'result' is the resulting type from the usual
> arithmetic conversions between type A and type B.

The code below seems like it must treat a conversion from A to B the same
way as a conversion from B to A (since the expression true ? : A() : B() has
the same type as true ? : B() : A()). Is that intended?

-Dave

===================================================
       David Abrahams, C++ library designer
 resume: http://users.rcn.com/abrahams/resume.html

        C++ Booster (http://www.boost.org)
          email: david.abrahams_at_[hidden]
===================================================

> Regards
> --
> Gabriel Netterdag
>
>
> #include <cstddef>
>
> template<std::size_t N> struct selected;
>
> template<> struct selected<1> { typedef int type; };
> template<> struct selected<2> { typedef unsigned int type; };
> template<> struct selected<3> { typedef long type; };
> template<> struct selected<4> { typedef unsigned long type; };
> template<> struct selected<5> { typedef float type; };
> template<> struct selected<6> { typedef double type; };
> template<> struct selected<7> { typedef long double type; };
>
> template<std::size_t N>
> struct sized { typedef char (&type)[N]; };
>
> sized<1>::type selector(int);
> sized<2>::type selector(unsigned int);
> sized<3>::type selector(long);
> sized<4>::type selector(unsigned long);
> sized<5>::type selector(float);
> sized<6>::type selector(double);
> sized<7>::type selector(long double);
>
> template<typename A, typename B>
> struct arithmetic_conversion {
> typedef typename selected<sizeof(selector(true ? A() : B()))>::type
> result;
> };
>
>
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk