|
Boost : |
From: garfaus_at_[hidden]
Date: 2001-09-28 01:55:16
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.
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; };
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk