]>
Dogcows Code - chaz/yoink/blob - src/cml/et/scalar_promotions.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
13 #ifndef scalar_promotions_h
14 #define scalar_promotions_h
16 #include <cml/core/cml_meta.h>
24 * @brief Helper template to int-promote a type.
26 template<class T
> struct IntPromote
28 /* Signed -> signed int, unsigned -> unsigned int: */
29 typedef typename select_switch
<T
,
30 unsigned char, unsigned int,
31 unsigned short, unsigned int,
41 /** @class ScalarPromote
42 * @brief Template for compile-time type promotion via C promotion rules.
44 template<class E1_in
, class E2_in
> struct ScalarPromote
47 /* Integral-promote the types (if possible). */
48 typedef typename
detail::IntPromote
<E1_in
>::result E1
;
49 typedef typename
detail::IntPromote
<E2_in
>::result E2
;
51 /* If sizeof(long) == sizeof(unsigned int), promote to unsigned long.
52 * Otherwise, sizeof(long) > sizeof(int), so promote to long.
54 typedef typename select_if
<sizeof(long) == sizeof(unsigned int),
57 >::result uint_promotion
;
59 /* Do the selection on the promoted types: */
60 typedef typename select_switch
<
63 #if defined(CML_USE_LONG_DOUBLE)
64 type_pair
<long double,long double>, long double,
65 type_pair
<long double,E2
>, long double,
66 type_pair
<E1
,long double>, long double,
69 type_pair
<double,double>, double,
70 type_pair
<double,E2
>, double,
71 type_pair
<E1
,double>, double,
73 type_pair
<float,float>, float,
74 type_pair
<float,E2
>, float,
75 type_pair
<E1
,float>, float,
77 type_pair
<E1
,E2
>, void
79 >::result float_filter
;
81 /* The promoted integral types really matter here: */
82 typedef typename select_switch
<
85 type_pair
<unsigned long,unsigned long>, unsigned long,
86 type_pair
<unsigned long,E2
>, unsigned long,
87 type_pair
<E1
,unsigned long>, unsigned long,
89 type_pair
<long,long>, long,
90 type_pair
<long,unsigned int>, uint_promotion
,
91 type_pair
<unsigned int,long>, uint_promotion
,
93 type_pair
<long,E2
>, long,
94 type_pair
<E1
,long>, long,
96 type_pair
<unsigned int,unsigned int>, unsigned int,
97 type_pair
<unsigned int,E2
>, unsigned int,
98 type_pair
<E1
,unsigned int>, unsigned int,
100 type_pair
<int,int>, int,
101 type_pair
<int,E2
>, int,
102 type_pair
<E1
,int>, int,
104 type_pair
<E1
,E2
>, void
106 >::result int_filter
;
108 /* Deduce the final type: */
109 typedef typename select_if
<
110 same_type
<float_filter
,void>::is_true
,
111 int_filter
, float_filter
>::result type
;
119 // -------------------------------------------------------------------------
This page took 0.039761 seconds and 5 git commands to generate.