~ubuntu-branches/ubuntu/raring/blitz++/raring

« back to all changes in this revision

Viewing changes to blitz/promote.h

  • Committer: Bazaar Package Importer
  • Author(s): Konstantinos Margaritis
  • Date: 2005-02-28 20:25:01 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050228202501-3i4f2sknnprsqfhz
Tags: 1:0.8-4
Added missing build-depends (Closes: #297323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * promote.h   Arithmetic type promotion trait class
3
3
 * Author: Todd Veldhuizen         (tveldhui@oonumerics.org)
4
4
 *
5
 
 * Copyright (C) 1997-1999 Todd Veldhuizen <tveldhui@oonumerics.org>
 
5
 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU General Public License
20
20
 * For more information, please see the Blitz++ Home Page:
21
21
 *    http://oonumerics.org/blitz/
22
22
 *
23
 
 ***************************************************************************
24
 
 */
 
23
 ***************************************************************************/
25
24
 
26
25
#ifndef BZ_PROMOTE_H
27
26
#define BZ_PROMOTE_H
30
29
 
31
30
BZ_NAMESPACE(blitz)
32
31
 
33
 
#ifdef BZ_TEMPLATE_QUALIFIED_RETURN_TYPE
34
 
    #define BZ_PROMOTE(A,B) _bz_typename promote_trait<A,B>::T_promote
 
32
#ifdef BZ_HAVE_TEMPLATE_QUALIFIED_RETURN_TYPE
 
33
    #define BZ_PROMOTE(A,B) _bz_typename BZ_BLITZ_SCOPE(promote_trait)<A,B>::T_promote
35
34
#else
36
35
    #define BZ_PROMOTE(A,B) A
37
36
#endif
38
37
 
39
 
#if defined(BZ_PARTIAL_SPECIALIZATION) && !defined(BZ_DISABLE_NEW_PROMOTE)
 
38
#if defined(BZ_HAVE_PARTIAL_SPECIALIZATION) && !defined(BZ_DISABLE_NEW_PROMOTE)
40
39
 
41
40
/*
42
41
 * This compiler supports partial specialization, so type promotion
44
43
 * by Jean-Louis Leroy.
45
44
 */
46
45
 
47
 
template<class T>
 
46
template<typename T>
48
47
struct precision_trait {
49
48
    enum { precisionRank = 0,
50
49
           knowPrecisionRank = 0 };
71
70
BZ_DECLARE_PRECISION(complex<long double>,1000)
72
71
#endif
73
72
 
74
 
template<class T>
 
73
template<typename T>
75
74
struct autopromote_trait {
76
75
    typedef T T_numtype;
77
76
};
91
90
BZ_DECLARE_AUTOPROMOTE(short int, int)
92
91
BZ_DECLARE_AUTOPROMOTE(short unsigned int, unsigned int)
93
92
 
94
 
template<class T1, class T2, int promoteToT1>
 
93
template<typename T1, typename T2, int promoteToT1>
95
94
struct _bz_promote2 {
96
95
    typedef T1 T_promote;
97
96
};
98
97
 
99
 
template<class T1, class T2>
 
98
template<typename T1, typename T2>
100
99
struct _bz_promote2<T1,T2,0> {
101
100
    typedef T2 T_promote;
102
101
};
103
102
 
104
 
template<class T1_orig, class T2_orig>
 
103
template<typename T1_orig, typename T2_orig>
105
104
struct promote_trait {
106
105
    // Handle promotion of small integers to int/unsigned int
107
106
    typedef _bz_typename autopromote_trait<T1_orig>::T_numtype T1;
132
131
    // We know T1 but not T2: true
133
132
    // We know T2 but not T1: false
134
133
    // Otherwise, if T1 is bigger than T2: true
135
 
      defaultPromotion = knowT1butNotT2 ? _bz_false : 
136
 
         (knowT2butNotT1 ? _bz_true : T1IsLarger)
 
134
      defaultPromotion = knowT1butNotT2 ? false : 
 
135
         (knowT2butNotT1 ? true : T1IsLarger)
137
136
    };
138
137
 
139
138
    // If we have both ranks, then use them.
145
144
        : BZ_ENUM_CAST(defaultPromotion)) ? 1 : 0
146
145
    };
147
146
 
148
 
    typedef typename _bz_promote2<T1,T2,promoteToT1>::T_promote T_promote;
 
147
    typedef _bz_typename _bz_promote2<T1,T2,promoteToT1>::T_promote T_promote;
149
148
};
150
149
 
151
 
#else  // !BZ_PARTIAL_SPECIALIZATION
 
150
#else  // !BZ_HAVE_PARTIAL_SPECIALIZATION
152
151
 
153
152
  // No partial specialization -- have to do it the ugly way.
154
153
  #include <blitz/promote-old.h>
155
154
 
156
 
#endif // !BZ_PARTIAL_SPECIALIZATION
 
155
#endif // !BZ_HAVE_PARTIAL_SPECIALIZATION
157
156
 
158
157
BZ_NAMESPACE_END
159
158