ROOT  6.06/09
Reference Guide
implicit_type_conversion.cpp
Go to the documentation of this file.
1 /*{{{
2  Copyright (C) 2012 Matthias Kretz <kretz@kde.org>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 }}}*/
18 
19 #include "unittest.h"
20 
21 //#define QUICK 1
22 
23 using namespace Vc;
24 
25 typedef unsigned short ushort;
26 typedef unsigned int uint;
27 typedef unsigned long ulong;
28 typedef long long longlong;
29 typedef unsigned long long ulonglong;
30 
31 #ifdef QUICK
32 #define _TYPE_TEST(a, b, c)
33 #define _TYPE_TEST_ERR(a, b)
34 #else
35 #if defined(VC_GCC) && VC_GCC == 0x40801
36 // Skipping tests involving operator& because of a bug in GCC 4.8.1 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57532)
37 #define _TYPE_TEST(a, b, c) \
38  COMPARE(typeid(a() * b()), typeid(c)); \
39  COMPARE(typeid(a() / b()), typeid(c)); \
40  COMPARE(typeid(a() + b()), typeid(c)); \
41  COMPARE(typeid(a() - b()), typeid(c)); \
42  COMPARE(typeid(a() | b()), typeid(c)); \
43  COMPARE(typeid(a() ^ b()), typeid(c)); \
44  COMPARE(typeid(a() == b()), typeid(c::Mask)); \
45  COMPARE(typeid(a() != b()), typeid(c::Mask)); \
46  COMPARE(typeid(a() <= b()), typeid(c::Mask)); \
47  COMPARE(typeid(a() >= b()), typeid(c::Mask)); \
48  COMPARE(typeid(a() < b()), typeid(c::Mask));
49 #else
50 #define _TYPE_TEST(a, b, c) \
51  COMPARE(typeid(a() * b()), typeid(c)); \
52  COMPARE(typeid(a() / b()), typeid(c)); \
53  COMPARE(typeid(a() + b()), typeid(c)); \
54  COMPARE(typeid(a() - b()), typeid(c)); \
55  COMPARE(typeid(a() & b()), typeid(c)); \
56  COMPARE(typeid(a() | b()), typeid(c)); \
57  COMPARE(typeid(a() ^ b()), typeid(c)); \
58  COMPARE(typeid(a() == b()), typeid(c::Mask)); \
59  COMPARE(typeid(a() != b()), typeid(c::Mask)); \
60  COMPARE(typeid(a() <= b()), typeid(c::Mask)); \
61  COMPARE(typeid(a() >= b()), typeid(c::Mask)); \
62  COMPARE(typeid(a() < b()), typeid(c::Mask));
63 #endif
64 #define _TYPE_TEST_ERR(a, b) \
65  COMPARE(typeid(a() * b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
66  COMPARE(typeid(a() / b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
67  COMPARE(typeid(a() + b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
68  COMPARE(typeid(a() - b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
69  COMPARE(typeid(a() & b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
70  COMPARE(typeid(a() | b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
71  COMPARE(typeid(a() ^ b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
72  COMPARE(typeid(a() == b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
73  COMPARE(typeid(a() != b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
74  COMPARE(typeid(a() <= b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
75  COMPARE(typeid(a() >= b()), typeid(Vc::Error::invalid_operands_of_types<a, b>)); \
76  COMPARE(typeid(a() < b()), typeid(Vc::Error::invalid_operands_of_types<a, b>));
77 #endif
78 
79 #define TYPE_TEST(a, b, c) \
80  _TYPE_TEST(a, b, c) \
81  COMPARE(typeid(a() > b()), typeid(c::Mask))
82 
83 template<typename T>
84 struct TestImplicitCast {
85  static bool test(const T &) { return true; }
86  static bool test( ... ) { return false; }
87 };
88 
89 enum SomeEnum { EnumValue = 0 };
90 SomeEnum Enum() { return EnumValue; }
91 
93 {
94  VERIFY( TestImplicitCast< int>::test(double()));
95  VERIFY( TestImplicitCast< int>::test( float()));
96  VERIFY( TestImplicitCast< int>::test( Enum()));
97  VERIFY( TestImplicitCast< int>::test( short()));
98  VERIFY( TestImplicitCast< int>::test(ushort()));
99  VERIFY( TestImplicitCast< int>::test( char()));
100  VERIFY( TestImplicitCast< int>::test( uint()));
101  VERIFY( TestImplicitCast< int>::test( long()));
102  VERIFY( TestImplicitCast< int>::test( ulong()));
103  VERIFY( TestImplicitCast< int>::test( bool()));
104  VERIFY( TestImplicitCast<double_v>::test(double()));
105  VERIFY(!TestImplicitCast<double_v>::test( float()));
106  VERIFY(!TestImplicitCast<double_v>::test( int()));
107  VERIFY( TestImplicitCast< float_v>::test( float()));
108  VERIFY( TestImplicitCast<sfloat_v>::test( float()));
109  VERIFY( TestImplicitCast< int_v>::test( int()));
110  VERIFY( TestImplicitCast< uint_v>::test( uint()));
111  VERIFY( TestImplicitCast< short_v>::test( short()));
112  VERIFY( TestImplicitCast<ushort_v>::test(ushort()));
113 
115  TYPE_TEST( double_v, double, double_v);
116  TYPE_TEST( double_v, float, double_v);
117  TYPE_TEST( double_v, short, double_v);
119  TYPE_TEST( double_v, int, double_v);
121  TYPE_TEST( double_v, long, double_v);
126  TYPE_TEST( double, double_v, double_v);
127  TYPE_TEST( float, double_v, double_v);
128  TYPE_TEST( short, double_v, double_v);
130  TYPE_TEST( int, double_v, double_v);
132  TYPE_TEST( long, double_v, double_v);
136  // double_v done
137 
139  TYPE_TEST( float_v, float, float_v);
140  TYPE_TEST( float_v, short, float_v);
143  TYPE_TEST( float_v, int, float_v);
146  TYPE_TEST( float_v, long, float_v);
150  TYPE_TEST( float, float_v, float_v);
151  TYPE_TEST( short, float_v, float_v);
154  TYPE_TEST( int, float_v, float_v);
157  TYPE_TEST( long, float_v, float_v);
161  // double_v + float_v done
162 
164  TYPE_TEST( sfloat_v, float, sfloat_v);
166  TYPE_TEST( sfloat_v, short, sfloat_v);
169  TYPE_TEST( sfloat_v, int, sfloat_v);
171  TYPE_TEST( sfloat_v, long, sfloat_v);
176  TYPE_TEST( float, sfloat_v, sfloat_v);
178  TYPE_TEST( short, sfloat_v, sfloat_v);
181  TYPE_TEST( int, sfloat_v, sfloat_v);
183  TYPE_TEST( long, sfloat_v, sfloat_v);
187  // double_v + float_v + sfloat_v done
188 
190  TYPE_TEST( short_v, short, short_v);
193  TYPE_TEST( short_v, int, short_v);
195  TYPE_TEST( short_v, long, short_v);
199  TYPE_TEST( short, short_v, short_v);
202  TYPE_TEST( int, short_v, short_v);
204  TYPE_TEST( long, short_v, short_v);
208  // double_v + float_v + sfloat_v + short_v done
209 
210  TYPE_TEST( ushort_v, short, ushort_v);
213  TYPE_TEST( ushort_v, int, ushort_v);
215  TYPE_TEST( ushort_v, long, ushort_v);
219  TYPE_TEST( short, ushort_v, ushort_v);
221  TYPE_TEST( int, ushort_v, ushort_v);
223  TYPE_TEST( long, ushort_v, ushort_v);
227  // double_v + float_v + sfloat_v + short_v + ushort_v done
228 
230  TYPE_TEST( int_v, short, int_v);
232  TYPE_TEST( int_v, int, int_v);
235  TYPE_TEST( int_v, long, int_v);
240  TYPE_TEST( short, int_v, int_v);
241  TYPE_TEST( int, int_v, int_v);
244  TYPE_TEST( long, int_v, int_v);
248 
249  TYPE_TEST( uint_v, short, uint_v);
252  TYPE_TEST( uint_v, int, uint_v);
255  TYPE_TEST( uint_v, long, uint_v);
259  TYPE_TEST( short, uint_v, uint_v);
262  TYPE_TEST( int, uint_v, uint_v);
264  TYPE_TEST( long, uint_v, uint_v);
268 }
269 
270 int main(int argc, char **argv)
271 {
272  initTest(argc, argv);
274  return 0;
275 }
VECTOR_NAMESPACE::uint_v uint_v
Definition: vector.h:88
void testImplicitTypeConversions()
VECTOR_NAMESPACE::sfloat_v sfloat_v
Definition: vector.h:82
void initTest(int argc, char **argv)
Definition: unittest.h:169
double T(double x)
Definition: ChebyshevPol.h:34
unsigned long ulong
VECTOR_NAMESPACE::short_v short_v
Definition: vector.h:90
VECTOR_NAMESPACE::ushort_v ushort_v
Definition: vector.h:92
SomeEnum Enum()
unsigned int uint
int main(int argc, char **argv)
VECTOR_NAMESPACE::int_v int_v
Definition: vector.h:86
VECTOR_NAMESPACE::double_v double_v
Definition: vector.h:80
unsigned short ushort
unsigned long long ulonglong
#define VERIFY(cond)
Definition: unittest.h:515
#define TYPE_TEST(a, b, c)
Enum
Definition: load.cpp:93
VECTOR_NAMESPACE::float_v float_v
Definition: vector.h:84
Definition: casts.h:28
long long longlong
#define runTest(name)
Definition: unittest.h:42