• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* boost integer_traits.hpp tests
2  *
3  * Copyright Jens Maurer 2000
4  * Distributed under the Boost Software License, Version 1.0. (See
5  * accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  * $Id$
9  *
10  * Revision history
11  *  2000-02-22  Small improvements by Beman Dawes
12  *  2000-06-27  Rework for better MSVC and BCC co-operation
13  */
14 
15 #include <iostream>
16 #include <boost/integer_traits.hpp>
17 // use int64_t instead of long long for better portability
18 #include <boost/cstdint.hpp>
19 
20 #include <boost/detail/lightweight_test.hpp>
21 
22 /*
23  * General portability note:
24  * MSVC mis-compiles explicit function template instantiations.
25  * For example, f<A>() and f<B>() are both compiled to call f<A>().
26  * BCC is unable to implicitly convert a "const char *" to a std::string
27  * when using explicit function template instantiations.
28  *
29  * Therefore, avoid explicit function template instantiations.
30  */
31 
32 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
make_char_numeric_for_streaming(T x)33 template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
34 namespace fix{
make_char_numeric_for_streaming(char c)35 inline int make_char_numeric_for_streaming(char c) { return c; }
make_char_numeric_for_streaming(signed char c)36 inline int make_char_numeric_for_streaming(signed char c) { return c; }
make_char_numeric_for_streaming(unsigned char c)37 inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
make_char_numeric_for_streaming(wchar_t c)38 inline long long int make_char_numeric_for_streaming(wchar_t c) { return c; }
39 }
40 using namespace fix;
41 #else
make_char_numeric_for_streaming(T x)42 template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
make_char_numeric_for_streaming(char c)43 inline int make_char_numeric_for_streaming(char c) { return c; }
make_char_numeric_for_streaming(signed char c)44 inline int make_char_numeric_for_streaming(signed char c) { return c; }
make_char_numeric_for_streaming(unsigned char c)45 inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
make_char_numeric_for_streaming(wchar_t c)46 inline long long int make_char_numeric_for_streaming(wchar_t c) { return c; }
47 #endif
48 
49 template<class T>
runtest(const char * type,T)50 void runtest(const char * type, T)
51 {
52   typedef boost::integer_traits<T> traits;
53   std::cout << "Checking " << type
54             << "; min is " << make_char_numeric_for_streaming((traits::min)())
55             << ", max is " << make_char_numeric_for_streaming((traits::max)())
56             << std::endl;
57   BOOST_TEST(traits::is_specialized);
58 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
59   // MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
60   // generates different symbol names with a very long common prefix:
61   // the dummy "&& true" disambiguates between the symbols generated by this
62   // BOOST_TEST instantiation and the preceding one.
63   BOOST_TEST(traits::is_integer && true);
64 #else
65   BOOST_TEST(traits::is_integer);
66 #endif
67   BOOST_TEST(traits::is_integral == true);
68   BOOST_TEST(traits::const_min == (traits::min)());
69   BOOST_TEST(traits::const_max == (traits::max)());
70 }
71 
main(int,char * [])72 int main(int, char*[])
73 {
74   runtest("bool", bool());
75   runtest("char", char());
76   typedef signed char signed_char;
77   runtest("signed char", signed_char());
78   typedef unsigned char unsigned_char;
79   runtest("unsigned char", unsigned_char());
80   runtest("wchar_t", wchar_t());
81   runtest("short", short());
82   typedef unsigned short unsigned_short;
83   runtest("unsigned short", unsigned_short());
84   runtest("int", int());
85   typedef unsigned int unsigned_int;
86   runtest("unsigned int", unsigned_int());
87   runtest("long", long());
88   typedef unsigned long unsigned_long;
89   runtest("unsigned long", unsigned_long());
90 #ifndef BOOST_NO_INTEGRAL_INT64_T
91   //
92   // MS/Borland compilers can't support 64-bit member constants
93   // BeOS doesn't have specialisations for long long in SGI's <limits> header.
94   runtest("int64_t (possibly long long)", boost::int64_t());
95   runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
96 #else
97   std::cout << "Skipped int64_t and uint64_t" << std::endl;
98 #endif
99   // Some compilers don't pay attention to std:3.6.1/5 and issue a
100   // warning here if "return 0;" is omitted.
101   return boost::report_errors();
102 }
103 
104