From 87490c040d82f5b61fdfb24e73ae97c61c5a77ec Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 7 Jul 2000 16:04:40 +0000 Subject: [PATCH] 1.16.1 initial CVS checkin [SVN r7620] --- .gitattributes | 96 +++++++++++++++++ cstdint_test.cpp | 74 +++++++++++++ include/boost/cstdint.hpp | 63 +++++++++++ include/boost/integer.hpp | 79 ++++++++++++++ include/boost/integer_traits.hpp | 147 ++++++++++++++++++++++++++ include/boost/stdint.h | 119 +++++++++++++++++++++ integer_test.cpp | 176 +++++++++++++++++++++++++++++++ integer_traits_test.cpp | 83 +++++++++++++++ 8 files changed, 837 insertions(+) create mode 100644 .gitattributes create mode 100644 cstdint_test.cpp create mode 100644 include/boost/cstdint.hpp create mode 100644 include/boost/integer.hpp create mode 100644 include/boost/integer_traits.hpp create mode 100644 include/boost/stdint.h create mode 100644 integer_test.cpp create mode 100644 integer_traits_test.cpp diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3e84d7c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,96 @@ +* text=auto !eol svneol=native#text/plain +*.gitattributes text svneol=native#text/plain + +# Scriptish formats +*.bat text svneol=native#text/plain +*.bsh text svneol=native#text/x-beanshell +*.cgi text svneol=native#text/plain +*.cmd text svneol=native#text/plain +*.js text svneol=native#text/javascript +*.php text svneol=native#text/x-php +*.pl text svneol=native#text/x-perl +*.pm text svneol=native#text/x-perl +*.py text svneol=native#text/x-python +*.sh eol=lf svneol=LF#text/x-sh +configure eol=lf svneol=LF#text/x-sh + +# Image formats +*.bmp binary svneol=unset#image/bmp +*.gif binary svneol=unset#image/gif +*.ico binary svneol=unset#image/ico +*.jpeg binary svneol=unset#image/jpeg +*.jpg binary svneol=unset#image/jpeg +*.png binary svneol=unset#image/png +*.tif binary svneol=unset#image/tiff +*.tiff binary svneol=unset#image/tiff +*.svg text svneol=native#image/svg%2Bxml + +# Data formats +*.pdf binary svneol=unset#application/pdf +*.avi binary svneol=unset#video/avi +*.doc binary svneol=unset#application/msword +*.dsp text svneol=crlf#text/plain +*.dsw text svneol=crlf#text/plain +*.eps binary svneol=unset#application/postscript +*.gz binary svneol=unset#application/gzip +*.mov binary svneol=unset#video/quicktime +*.mp3 binary svneol=unset#audio/mpeg +*.ppt binary svneol=unset#application/vnd.ms-powerpoint +*.ps binary svneol=unset#application/postscript +*.psd binary svneol=unset#application/photoshop +*.rdf binary svneol=unset#text/rdf +*.rss text svneol=unset#text/xml +*.rtf binary svneol=unset#text/rtf +*.sln text svneol=native#text/plain +*.swf binary svneol=unset#application/x-shockwave-flash +*.tgz binary svneol=unset#application/gzip +*.vcproj text svneol=native#text/xml +*.vcxproj text svneol=native#text/xml +*.vsprops text svneol=native#text/xml +*.wav binary svneol=unset#audio/wav +*.xls binary svneol=unset#application/vnd.ms-excel +*.zip binary svneol=unset#application/zip + +# Text formats +.htaccess text svneol=native#text/plain +*.bbk text svneol=native#text/xml +*.cmake text svneol=native#text/plain +*.css text svneol=native#text/css +*.dtd text svneol=native#text/xml +*.htm text svneol=native#text/html +*.html text svneol=native#text/html +*.ini text svneol=native#text/plain +*.log text svneol=native#text/plain +*.mak text svneol=native#text/plain +*.qbk text svneol=native#text/plain +*.rst text svneol=native#text/plain +*.sql text svneol=native#text/x-sql +*.txt text svneol=native#text/plain +*.xhtml text svneol=native#text/xhtml%2Bxml +*.xml text svneol=native#text/xml +*.xsd text svneol=native#text/xml +*.xsl text svneol=native#text/xml +*.xslt text svneol=native#text/xml +*.xul text svneol=native#text/xul +*.yml text svneol=native#text/plain +boost-no-inspect text svneol=native#text/plain +CHANGES text svneol=native#text/plain +COPYING text svneol=native#text/plain +INSTALL text svneol=native#text/plain +Jamfile text svneol=native#text/plain +Jamroot text svneol=native#text/plain +Jamfile.v2 text svneol=native#text/plain +Jamrules text svneol=native#text/plain +Makefile* text svneol=native#text/plain +README text svneol=native#text/plain +TODO text svneol=native#text/plain + +# Code formats +*.c text svneol=native#text/plain +*.cpp text svneol=native#text/plain +*.h text svneol=native#text/plain +*.hpp text svneol=native#text/plain +*.ipp text svneol=native#text/plain +*.tpp text svneol=native#text/plain +*.jam text svneol=native#text/plain +*.java text svneol=native#text/plain diff --git a/cstdint_test.cpp b/cstdint_test.cpp new file mode 100644 index 0000000..3a6c938 --- /dev/null +++ b/cstdint_test.cpp @@ -0,0 +1,74 @@ +// boost cstdint.hpp test program ------------------------------------------// + +// (C) Copyright Beman Dawes 2000. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 28 Jun 00 Initial version + +#include +#include +#include + +#ifdef NDEBUG +#error This test makes no sense with NDEBUG defined +#endif + +int main() +{ + boost::int8_t int8 = -127; + boost::int_least8_t int_least8 = -127; + boost::int_fast8_t int_fast8 = -127; + + boost::uint8_t uint8 = 255; + boost::uint_least8_t uint_least8 = 255; + boost::uint_fast8_t uint_fast8 = 255; + + boost::int16_t int16 = -32767; + boost::int_least16_t int_least16 = -32767; + boost::int_fast16_t int_fast16 = -32767; + + boost::uint16_t uint16 = 65535; + boost::uint_least16_t uint_least16 = 65535; + boost::uint_fast16_t uint_fast16 = 65535; + + boost::int32_t int32 = -2147483647; + boost::int_least32_t int_least32 = -2147483647; + boost::int_fast32_t int_fast32 = -2147483647; + + boost::uint32_t uint32 = 4294967295; + boost::uint_least32_t uint_least32 = 4294967295; + boost::uint_fast32_t uint_fast32 = 4294967295; + + boost::intmax_t intmax = -2147483647; + boost::uintmax_t uintmax = 4294967295; + + assert( int8 == -127 ); + assert( int_least8 == -127 ); + assert( int_fast8 == -127 ); + assert( uint8 == 255 ); + assert( uint_least8 == 255 ); + assert( uint_fast8 == 255 ); + assert( int16 == -32767 ); + assert( int_least16 == -32767 ); + assert( int_fast16 == -32767 ); + assert( uint16 == 65535 ); + assert( uint_least16 == 65535 ); + assert( uint_fast16 == 65535 ); + assert( int32 == -2147483647 ); + assert( int_least32 == -2147483647 ); + assert( int_fast32 == -2147483647 ); + assert( uint32 == 4294967295 ); + assert( uint_least32 == 4294967295 ); + assert( uint_fast32 == 4294967295 ); + assert( intmax == -2147483647 ); + assert( uintmax == 4294967295 ); + + std::cout << "OK\n"; + return 0; +} \ No newline at end of file diff --git a/include/boost/cstdint.hpp b/include/boost/cstdint.hpp new file mode 100644 index 0000000..3e58eee --- /dev/null +++ b/include/boost/cstdint.hpp @@ -0,0 +1,63 @@ +// boost cstdint.hpp header file -------------------------------------------// + +// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost +// 8 Aug 99 Initial version + +#ifndef BOOST_CSTDINT_HPP +#define BOOST_CSTDINT_HPP + +#include // implementation artifact; not part of interface + +#include + +namespace boost +{ + + using ::int8_t; + using ::int_least8_t; + using ::int_fast8_t; + using ::uint8_t; + using ::uint_least8_t; + using ::uint_fast8_t; + + using ::int16_t; + using ::int_least16_t; + using ::int_fast16_t; + using ::uint16_t; + using ::uint_least16_t; + using ::uint_fast16_t; + + using ::int32_t; + using ::int_least32_t; + using ::int_fast32_t; + using ::uint32_t; + using ::uint_least32_t; + using ::uint_fast32_t; + +# ifdef ULLONG_MAX + + using ::int64_t; + using ::int_least64_t; + using ::int_fast64_t; + using ::uint64_t; + using ::uint_least64_t; + using ::uint_fast64_t; + +# endif + + using ::intmax_t; + using ::uintmax_t; + +} // namespace boost + +#endif + \ No newline at end of file diff --git a/include/boost/integer.hpp b/include/boost/integer.hpp new file mode 100644 index 0000000..3023fc7 --- /dev/null +++ b/include/boost/integer.hpp @@ -0,0 +1,79 @@ +// boost integer.hpp header file -------------------------------------------// + +// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 28 Aug 99 Initial version + +#ifndef BOOST_INTEGER_HPP +#define BOOST_INTEGER_HPP + +#include + +namespace boost +{ + + // Helper templates ------------------------------------------------------// + + // fast integers from least integers + template< typename LeastInt > + struct int_fast_t { typedef LeastInt fast; }; // imps may specialize + + // convert category to type + template< int Category > struct int_least_helper {}; // default is empty + + // specializatons: 1=long, 2=int, 3=short, 4=signed char, + // 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long + template<> struct int_least_helper<1> { typedef long least; }; + template<> struct int_least_helper<2> { typedef int least; }; + template<> struct int_least_helper<3> { typedef short least; }; + template<> struct int_least_helper<4> { typedef signed char least; }; + template<> struct int_least_helper<6> { typedef unsigned long least; }; + template<> struct int_least_helper<7> { typedef unsigned int least; }; + template<> struct int_least_helper<8> { typedef unsigned short least; }; + template<> struct int_least_helper<9> { typedef unsigned char least; }; + + // integer templates specifying number of bits ---------------------------// + + // signed + template< int Bits > // bits (including sign) required + struct int_t + { + typedef int_least_helper + < + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + + (Bits-1 <= std::numeric_limits::digits) + >::least least; + typedef int_fast_t::fast fast; + }; + + // unsigned + template< int Bits > // bits required + struct uint_t + { + typedef int_least_helper + < + 5 + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + + (Bits <= std::numeric_limits::digits) + >::least least; + typedef int_fast_t::fast fast; + }; + +// The same dispatching technique can be used to select types based on +// values. That will be added once boost::integer_traits is available. + + +} // namespace boost + +#endif // BOOST_INTEGER_HPP diff --git a/include/boost/integer_traits.hpp b/include/boost/integer_traits.hpp new file mode 100644 index 0000000..8cc89d0 --- /dev/null +++ b/include/boost/integer_traits.hpp @@ -0,0 +1,147 @@ +/* boost integer_traits.hpp header file + * + * Copyright Jens Maurer 2000 + * Permission to use, copy, modify, sell, and distribute this software + * is hereby granted without free provided that the above copyright notice + * appears in all copies and that both that copyright notice and this + * permission notice appear in supporting documentation, + * + * Jens Maurer makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * $Id$ + * + * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers + */ + +#ifndef BOOST_INTEGER_TRAITS_HPP +#define BOOST_INTEGER_TRAITS_HPP + +#include +#include + +// This is an implementation detail and not part of the interface +#include + + +namespace boost { +template +class integer_traits : public std::numeric_limits +{ +public: +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool is_integral = false; +#else + enum { is_integral = false }; +#endif +}; + +namespace detail { +template +class integer_traits_base +{ +public: +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION + static const bool is_integral = true; + static const T const_min = min_val; + static const T const_max = max_val; +#else + enum { + is_integral = true, + const_min = min_val, + const_max = max_val + }; +#endif +}; +} // namespace detail + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +// What about wchar_t ? + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; + +#ifdef ULLONG_MAX +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; +#elif defined(ULONG_LONG_MAX) +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; +template<> +class integer_traits + : public std::numeric_limits, + public detail::integer_traits_base +{ }; +#endif + +} // namespace boost + +#endif /* BOOST_INTEGER_TRAITS_HPP */ diff --git a/include/boost/stdint.h b/include/boost/stdint.h new file mode 100644 index 0000000..b9c2ff0 --- /dev/null +++ b/include/boost/stdint.h @@ -0,0 +1,119 @@ + // boost stdint.h header file ---------------------------------------------// + +// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// NOTE WELL: C++ programs are advised to use rather than +// this header. + +// Revision History +// 8 Aug 99 Initial version + +#ifndef BOOST_STDINT_H +#define BOOST_STDINT_H + +#include + +#ifdef BOOST_SYSTEM_HAS_STDINT_H +#include + +#else + +// This is not a complete implementation of the 1999 C Standard stdint.h +// header; it doesn't supply various macros which are not advisable for use in +// C++ programs. + +#include // implementation artifact; not part of interface + +// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit +// platforms. For other systems, they will have to be hand tailored. +// Because the fast types are assumed to be the same as the undecorated types, +// it may be possible to hand tailor a more efficient implementation. + +// 8-bit types -------------------------------------------------------------// + +# if UCHAR_MAX == 0xff + typedef signed char int8_t; + typedef signed char int_least8_t; + typedef signed char int_fast8_t; + typedef unsigned char uint8_t; + typedef unsigned char uint_least8_t; + typedef unsigned char uint_fast8_t; +# else +# error defaults not correct; you must hand modify boost/stdint.hpp +# endif + +// 16-bit types ------------------------------------------------------------// + +# if USHRT_MAX == 0xffff + typedef short int16_t; + typedef short int_least16_t; + typedef short int_fast16_t; + typedef unsigned short uint16_t; + typedef unsigned short uint_least16_t; + typedef unsigned short uint_fast16_t; +# else +# error defaults not correct; you must hand modify boost/stdint.hpp +# endif + +// 32-bit types ------------------------------------------------------------// + +# if UINT_MAX == 0xffffffff + typedef int int32_t; + typedef int int_least32_t; + typedef int int_fast32_t; + typedef unsigned int uint32_t; + typedef unsigned int uint_least32_t; + typedef unsigned int uint_fast32_t; +# elif ULONG_MAX == 0xffffffff + typedef long int32_t; + typedef long int_least32_t; + typedef long int_fast32_t; + typedef unsigned long uint32_t; + typedef unsigned long uint_least32_t; + typedef unsigned long uint_fast32_t; +# else +# error defaults not correct; you must hand modify boost/stdint.hpp +# endif + +// 64-bit types + intmax_t and uintmax_t -----------------------------------// + +# ifdef ULLONG_MAX +# if ULLONG_MAX == 18446744073709551615 // 2**64 - 1 + typedef long long intmax_t; + typedef unsigned long long uintmax_t; + typedef long long int64_t; + typedef long long int_least64_t; + typedef long long int_fast64_t; + typedef unsigned long long uint64_t; + typedef unsigned long long uint_least64_t; + typedef unsigned long long uint_fast64_t; +# else +# error defaults not correct; you must hand modify boost/stdint.hpp +# endif +# elif ULONG_MAX != 0xffffffff + +# if ULONG_MAX == 18446744073709551615 // 2**64 - 1 + typedef long intmax_t; + typedef unsigned long uintmax_t; + typedef long int64_t; + typedef long int_least64_t; + typedef long int_fast64_t; + typedef unsigned long uint64_t; + typedef unsigned long uint_least64_t; + typedef unsigned long uint_fast64_t; +# else +# error defaults not correct; you must hand modify boost/stdint.hpp +# endif +# else // assume no 64-bit integers + typedef int32_t intmax_t; + typedef uint32_t uintmax_t; +# endif + +#endif // BOOST_SYSTEM_HAS_STDINT_H not defined +#endif // BOOST_STDINT_H diff --git a/integer_test.cpp b/integer_test.cpp new file mode 100644 index 0000000..d7e06fb --- /dev/null +++ b/integer_test.cpp @@ -0,0 +1,176 @@ +// boost integer.hpp test program ------------------------------------------// + +// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell +// and distribute this software is granted provided this copyright +// notice appears in all copies. This software is provided "as is" without +// express or implied warranty, and with no claim as to its suitability for +// any purpose. + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 31 Aug 99 Initial version + +// This program is misnamed in that it is really a demonstration rather than +// a test. It doesn't detect failure, so isn't worthy of the name "test". + +#include +#include + +using namespace boost; // not the best practice, but useful for testing + +namespace +{ + void test( long ) { std::cout << "long\n"; } + void test( int ) { std::cout << "int\n"; } + void test( short ) { std::cout << "short\n"; } + void test( signed char ) { std::cout << "signed char\n"; } + void test( unsigned long ) { std::cout << "unsigned long\n"; } + void test( unsigned int ) { std::cout << "unsigned int\n"; } + void test( unsigned short ) { std::cout << "unsigned short\n"; } + void test( unsigned char ) { std::cout << "unsigned char\n"; } +} // unnamed namespace + +// just to prove it works, specialize int_fast_t to yield long +namespace boost +{ + template<> struct int_fast_t { typedef long fast; }; +} + +int main() +{ + std::cout << 32 << ' '; test( int_t<32>::least() ); + std::cout << 31 << ' '; test( int_t<31>::least() ); + std::cout << 30 << ' '; test( int_t<30>::least() ); + std::cout << 29 << ' '; test( int_t<29>::least() ); + std::cout << 28 << ' '; test( int_t<28>::least() ); + std::cout << 27 << ' '; test( int_t<27>::least() ); + std::cout << 26 << ' '; test( int_t<26>::least() ); + std::cout << 25 << ' '; test( int_t<25>::least() ); + std::cout << 24 << ' '; test( int_t<24>::least() ); + std::cout << 23 << ' '; test( int_t<23>::least() ); + std::cout << 22 << ' '; test( int_t<22>::least() ); + std::cout << 21 << ' '; test( int_t<21>::least() ); + std::cout << 20 << ' '; test( int_t<20>::least() ); + std::cout << 19 << ' '; test( int_t<19>::least() ); + std::cout << 18 << ' '; test( int_t<18>::least() ); + std::cout << 17 << ' '; test( int_t<17>::least() ); + std::cout << 16 << ' '; test( int_t<16>::least() ); + std::cout << 15 << ' '; test( int_t<15>::least() ); + std::cout << 14 << ' '; test( int_t<14>::least() ); + std::cout << 13 << ' '; test( int_t<13>::least() ); + std::cout << 12 << ' '; test( int_t<12>::least() ); + std::cout << 11 << ' '; test( int_t<11>::least() ); + std::cout << 10 << ' '; test( int_t<10>::least() ); + std::cout << 9 << ' '; test( int_t<9>::least() ); + std::cout << 8 << ' '; test( int_t<8>::least() ); + std::cout << 7 << ' '; test( int_t<7>::least() ); + std::cout << 6 << ' '; test( int_t<6>::least() ); + std::cout << 5 << ' '; test( int_t<5>::least() ); + std::cout << 4 << ' '; test( int_t<4>::least() ); + std::cout << 3 << ' '; test( int_t<3>::least() ); + std::cout << 2 << ' '; test( int_t<2>::least() ); + std::cout << 1 << ' '; test( int_t<1>::least() ); + std::cout << 0 << ' '; test( int_t<0>::least() ); + std::cout << 32 << ' '; test( int_t<32>::fast() ); + std::cout << 31 << ' '; test( int_t<31>::fast() ); + std::cout << 30 << ' '; test( int_t<30>::fast() ); + std::cout << 29 << ' '; test( int_t<29>::fast() ); + std::cout << 28 << ' '; test( int_t<28>::fast() ); + std::cout << 27 << ' '; test( int_t<27>::fast() ); + std::cout << 26 << ' '; test( int_t<26>::fast() ); + std::cout << 25 << ' '; test( int_t<25>::fast() ); + std::cout << 24 << ' '; test( int_t<24>::fast() ); + std::cout << 23 << ' '; test( int_t<23>::fast() ); + std::cout << 22 << ' '; test( int_t<22>::fast() ); + std::cout << 21 << ' '; test( int_t<21>::fast() ); + std::cout << 20 << ' '; test( int_t<20>::fast() ); + std::cout << 19 << ' '; test( int_t<19>::fast() ); + std::cout << 18 << ' '; test( int_t<18>::fast() ); + std::cout << 17 << ' '; test( int_t<17>::fast() ); + std::cout << 16 << ' '; test( int_t<16>::fast() ); + std::cout << 15 << ' '; test( int_t<15>::fast() ); + std::cout << 14 << ' '; test( int_t<14>::fast() ); + std::cout << 13 << ' '; test( int_t<13>::fast() ); + std::cout << 12 << ' '; test( int_t<12>::fast() ); + std::cout << 11 << ' '; test( int_t<11>::fast() ); + std::cout << 10 << ' '; test( int_t<10>::fast() ); + std::cout << 9 << ' '; test( int_t<9>::fast() ); + std::cout << 8 << ' '; test( int_t<8>::fast() ); + std::cout << 7 << ' '; test( int_t<7>::fast() ); + std::cout << 6 << ' '; test( int_t<6>::fast() ); + std::cout << 5 << ' '; test( int_t<5>::fast() ); + std::cout << 4 << ' '; test( int_t<4>::fast() ); + std::cout << 3 << ' '; test( int_t<3>::fast() ); + std::cout << 2 << ' '; test( int_t<2>::fast() ); + std::cout << 1 << ' '; test( int_t<1>::fast() ); + std::cout << 0 << ' '; test( int_t<0>::fast() ); + std::cout << 32 << ' '; test( uint_t<32>::least() ); + std::cout << 31 << ' '; test( uint_t<31>::least() ); + std::cout << 30 << ' '; test( uint_t<30>::least() ); + std::cout << 29 << ' '; test( uint_t<29>::least() ); + std::cout << 28 << ' '; test( uint_t<28>::least() ); + std::cout << 27 << ' '; test( uint_t<27>::least() ); + std::cout << 26 << ' '; test( uint_t<26>::least() ); + std::cout << 25 << ' '; test( uint_t<25>::least() ); + std::cout << 24 << ' '; test( uint_t<24>::least() ); + std::cout << 23 << ' '; test( uint_t<23>::least() ); + std::cout << 22 << ' '; test( uint_t<22>::least() ); + std::cout << 21 << ' '; test( uint_t<21>::least() ); + std::cout << 20 << ' '; test( uint_t<20>::least() ); + std::cout << 19 << ' '; test( uint_t<19>::least() ); + std::cout << 18 << ' '; test( uint_t<18>::least() ); + std::cout << 17 << ' '; test( uint_t<17>::least() ); + std::cout << 16 << ' '; test( uint_t<16>::least() ); + std::cout << 15 << ' '; test( uint_t<15>::least() ); + std::cout << 14 << ' '; test( uint_t<14>::least() ); + std::cout << 13 << ' '; test( uint_t<13>::least() ); + std::cout << 12 << ' '; test( uint_t<12>::least() ); + std::cout << 11 << ' '; test( uint_t<11>::least() ); + std::cout << 10 << ' '; test( uint_t<10>::least() ); + std::cout << 9 << ' '; test( uint_t<9>::least() ); + std::cout << 8 << ' '; test( uint_t<8>::least() ); + std::cout << 7 << ' '; test( uint_t<7>::least() ); + std::cout << 6 << ' '; test( uint_t<6>::least() ); + std::cout << 5 << ' '; test( uint_t<5>::least() ); + std::cout << 4 << ' '; test( uint_t<4>::least() ); + std::cout << 3 << ' '; test( uint_t<3>::least() ); + std::cout << 2 << ' '; test( uint_t<2>::least() ); + std::cout << 1 << ' '; test( uint_t<1>::least() ); + std::cout << 0 << ' '; test( uint_t<0>::least() ); + std::cout << 32 << ' '; test( uint_t<32>::fast() ); + std::cout << 31 << ' '; test( uint_t<31>::fast() ); + std::cout << 30 << ' '; test( uint_t<30>::fast() ); + std::cout << 29 << ' '; test( uint_t<29>::fast() ); + std::cout << 28 << ' '; test( uint_t<28>::fast() ); + std::cout << 27 << ' '; test( uint_t<27>::fast() ); + std::cout << 26 << ' '; test( uint_t<26>::fast() ); + std::cout << 25 << ' '; test( uint_t<25>::fast() ); + std::cout << 24 << ' '; test( uint_t<24>::fast() ); + std::cout << 23 << ' '; test( uint_t<23>::fast() ); + std::cout << 22 << ' '; test( uint_t<22>::fast() ); + std::cout << 21 << ' '; test( uint_t<21>::fast() ); + std::cout << 20 << ' '; test( uint_t<20>::fast() ); + std::cout << 19 << ' '; test( uint_t<19>::fast() ); + std::cout << 18 << ' '; test( uint_t<18>::fast() ); + std::cout << 17 << ' '; test( uint_t<17>::fast() ); + std::cout << 16 << ' '; test( uint_t<16>::fast() ); + std::cout << 15 << ' '; test( uint_t<15>::fast() ); + std::cout << 14 << ' '; test( uint_t<14>::fast() ); + std::cout << 13 << ' '; test( uint_t<13>::fast() ); + std::cout << 12 << ' '; test( uint_t<12>::fast() ); + std::cout << 11 << ' '; test( uint_t<11>::fast() ); + std::cout << 10 << ' '; test( uint_t<10>::fast() ); + std::cout << 9 << ' '; test( uint_t<9>::fast() ); + std::cout << 8 << ' '; test( uint_t<8>::fast() ); + std::cout << 7 << ' '; test( uint_t<7>::fast() ); + std::cout << 6 << ' '; test( uint_t<6>::fast() ); + std::cout << 5 << ' '; test( uint_t<5>::fast() ); + std::cout << 4 << ' '; test( uint_t<4>::fast() ); + std::cout << 3 << ' '; test( uint_t<3>::fast() ); + std::cout << 2 << ' '; test( uint_t<2>::fast() ); + std::cout << 1 << ' '; test( uint_t<1>::fast() ); + std::cout << 0 << ' '; test( uint_t<0>::fast() ); + + return 0; +} \ No newline at end of file diff --git a/integer_traits_test.cpp b/integer_traits_test.cpp new file mode 100644 index 0000000..e5d3124 --- /dev/null +++ b/integer_traits_test.cpp @@ -0,0 +1,83 @@ +/* boost integer_traits.hpp tests + * + * Copyright Jens Maurer 2000 + * Permission to use, copy, modify, sell, and distribute this software + * is hereby granted without free provided that the above copyright notice + * appears in all copies and that both that copyright notice and this + * permission notice appear in supporting documentation, + * + * Jens Maurer makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * $Id$ + * + * Revision history + * 2000-02-22 Small improvements by Beman Dawes + * 2000-06-27 Rework for better MSVC and BCC co-operation + */ + +#include +#include +#include + +#ifdef NDEBUG +#error This test relies on assert() and thus makes no sense with NDEBUG defined +#endif + +// enable if you have "long long" and the proper macros in +#undef HAVE_LONG_LONG + + +/* + * General portability note: + * MSVC mis-compiles explicit function template instantiations. + * For example, f() and f() are both compiled to call f(). + * BCC is unable to implicitly convert a "const char *" to a std::string + * when using explicit function template instantiations. + * + * Therefore, avoid explicit function template instantiations. + */ + +template +void runtest(const char * type, T) +{ + typedef boost::integer_traits traits; + std::cout << "Checking " << type + << "; min is " << traits::min() + << ", max is " << traits::max() + << std::endl; + assert(traits::is_specialized); + assert(traits::is_integer); + assert(traits::is_integral); + assert(traits::const_min == traits::min()); + assert(traits::const_max == traits::max()); +} + +int main() +{ + runtest("bool", bool()); + runtest("char", char()); + typedef signed char signed_char; + runtest("signed char", signed_char()); + typedef unsigned char unsigned_char; + runtest("unsigned char", unsigned_char()); + runtest("short", short()); + typedef unsigned short unsigned_short; + runtest("unsigned short", unsigned_short()); + runtest("int", int()); + typedef unsigned int unsigned_int; + runtest("unsigned int", unsigned_int()); + runtest("long", long()); + typedef unsigned long unsigned_long; + runtest("unsigned long", unsigned_long()); +#ifdef HAVE_LONG_LONG + typedef long long long_long; + runtest("long long", long_long()); + typedef unsigned long long unsigned_long_long; + runtest("unsigned long long", unsigned_long_long()); +#endif + // Some compilers don't pay attention to std:3.6.1/5 and issue a + // warning here if "return 0;" is omitted. + return 0; +}