]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/integer/test/integer_traits_test.cpp
1 /* boost integer_traits.hpp tests
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)
11 * 2000-02-22 Small improvements by Beman Dawes
12 * 2000-06-27 Rework for better MSVC and BCC co-operation
16 #include <boost/integer_traits.hpp>
17 // use int64_t instead of long long for better portability
18 #include <boost/cstdint.hpp>
20 #include <boost/detail/lightweight_test.hpp>
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.
29 * Therefore, avoid explicit function template instantiations.
32 #if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
33 template<typename T
> inline T
make_char_numeric_for_streaming(T x
) { return x
; }
35 inline int make_char_numeric_for_streaming(char c
) { return c
; }
36 inline int make_char_numeric_for_streaming(signed char c
) { return c
; }
37 inline int make_char_numeric_for_streaming(unsigned char c
) { return c
; }
38 inline long long int make_char_numeric_for_streaming(wchar_t c
) { return c
; }
42 template<typename T
> inline T
make_char_numeric_for_streaming(T x
) { return x
; }
43 inline int make_char_numeric_for_streaming(char c
) { return c
; }
44 inline int make_char_numeric_for_streaming(signed char c
) { return c
; }
45 inline int make_char_numeric_for_streaming(unsigned char c
) { return c
; }
46 inline long long int make_char_numeric_for_streaming(wchar_t c
) { return c
; }
50 void runtest(const char * type
, T
)
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
)())
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);
65 BOOST_TEST(traits::is_integer
);
67 BOOST_TEST(traits::is_integral
== true);
68 BOOST_TEST(traits::const_min
== (traits::min
)());
69 BOOST_TEST(traits::const_max
== (traits::max
)());
72 int main(int, char*[])
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
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());
97 std::cout
<< "Skipped int64_t and uint64_t" << std::endl
;
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();