Chris@16: /* boost integer_traits.hpp header file Chris@16: * Chris@16: * Copyright Jens Maurer 2000 Chris@16: * Distributed under the Boost Software License, Version 1.0. (See Chris@16: * accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: * Chris@101: * $Id$ Chris@16: * Chris@16: * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers Chris@16: */ Chris@16: Chris@16: // See http://www.boost.org/libs/integer for documentation. Chris@16: Chris@16: Chris@16: #ifndef BOOST_INTEGER_TRAITS_HPP Chris@16: #define BOOST_INTEGER_TRAITS_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: // These are an implementation detail and not part of the interface Chris@16: #include Chris@16: // we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it, Chris@16: // and some may have but not ... Chris@16: #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__)) Chris@16: #include Chris@16: #endif Chris@16: Chris@16: // Chris@16: // We simply cannot include this header on gcc without getting copious warnings of the kind: Chris@16: // Chris@16: // ../../../boost/integer_traits.hpp:164:66: warning: use of C99 long long integer constant Chris@16: // Chris@16: // And yet there is no other reasonable implementation, so we declare this a system header Chris@16: // to suppress these warnings. Chris@16: // Chris@16: #if defined(__GNUC__) && (__GNUC__ >= 4) Chris@16: #pragma GCC system_header Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: template Chris@16: class integer_traits : public std::numeric_limits Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, is_integral = false); Chris@16: }; Chris@16: Chris@16: namespace detail { Chris@16: template Chris@16: class integer_traits_base Chris@16: { Chris@16: public: Chris@16: BOOST_STATIC_CONSTANT(bool, is_integral = true); Chris@16: BOOST_STATIC_CONSTANT(T, const_min = min_val); Chris@16: BOOST_STATIC_CONSTANT(T, const_max = max_val); Chris@16: }; Chris@16: Chris@16: #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION Chris@16: // A definition is required even for integral static constants Chris@16: template Chris@16: const bool integer_traits_base::is_integral; Chris@16: Chris@16: template Chris@16: const T integer_traits_base::const_min; Chris@16: Chris@16: template Chris@16: const T integer_traits_base::const_max; Chris@16: #endif Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: #ifndef BOOST_NO_INTRINSIC_WCHAR_T Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: // Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native Chris@16: // library: they are wrong! Chris@16: #if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__) Chris@16: public detail::integer_traits_base Chris@16: #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__)) Chris@16: // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned: Chris@16: public detail::integer_traits_base Chris@16: #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\ Chris@16: || (defined __APPLE__)\ Chris@16: || (defined(__OpenBSD__) && defined(__GNUC__))\ Chris@16: || (defined(__NetBSD__) && defined(__GNUC__))\ Chris@16: || (defined(__FreeBSD__) && defined(__GNUC__))\ Chris@16: || (defined(__DragonFly__) && defined(__GNUC__))\ Chris@16: || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT)) Chris@16: // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int. Chris@16: // - SGI MIPSpro with native library Chris@16: // - gcc 3.x on HP-UX Chris@16: // - Mac OS X with native library Chris@16: // - gcc on FreeBSD, OpenBSD and NetBSD Chris@16: public detail::integer_traits_base Chris@16: #else Chris@16: #error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler. Chris@16: #endif Chris@16: { }; Chris@16: #endif // BOOST_NO_INTRINSIC_WCHAR_T Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits Chris@16: : public std::numeric_limits, Chris@16: public detail::integer_traits_base Chris@16: { }; Chris@16: Chris@16: #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) Chris@16: #if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG) Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::long_long_type> Chris@16: : public std::numeric_limits< ::boost::long_long_type>, Chris@16: public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX> Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::ulong_long_type> Chris@16: : public std::numeric_limits< ::boost::ulong_long_type>, Chris@16: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX> Chris@16: { }; Chris@16: Chris@16: #elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG) Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::long_long_type> : public std::numeric_limits< ::boost::long_long_type>, public detail::integer_traits_base< ::boost::long_long_type, LONG_LONG_MIN, LONG_LONG_MAX>{ }; Chris@16: template<> Chris@16: class integer_traits< ::boost::ulong_long_type> Chris@16: : public std::numeric_limits< ::boost::ulong_long_type>, Chris@16: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX> Chris@16: { }; Chris@16: Chris@16: #elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG) Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::long_long_type> Chris@16: : public std::numeric_limits< ::boost::long_long_type>, Chris@16: public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX> Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::ulong_long_type> Chris@16: : public std::numeric_limits< ::boost::ulong_long_type>, Chris@16: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX> Chris@16: { }; Chris@16: Chris@16: #elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG) Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::long_long_type> Chris@16: : public std::numeric_limits< ::boost::long_long_type>, Chris@16: public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX> Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::ulong_long_type> Chris@16: : public std::numeric_limits< ::boost::ulong_long_type>, Chris@16: public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX> Chris@16: { }; Chris@16: Chris@16: #elif defined(BOOST_HAS_LONG_LONG) Chris@16: // Chris@16: // we have long long but no constants, this happens for example with gcc in -ansi mode, Chris@16: // we'll just have to work out the values for ourselves (assumes 2's compliment representation): Chris@16: // Chris@16: template<> Chris@16: class integer_traits< ::boost::long_long_type> Chris@16: : public std::numeric_limits< ::boost::long_long_type>, Chris@16: public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1)), ~(1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))> Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits< ::boost::ulong_long_type> Chris@16: : public std::numeric_limits< ::boost::ulong_long_type>, Chris@16: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL> Chris@16: { }; Chris@16: Chris@16: #elif defined(BOOST_HAS_MS_INT64) Chris@16: Chris@16: template<> Chris@16: class integer_traits< __int64> Chris@16: : public std::numeric_limits< __int64>, Chris@16: public detail::integer_traits_base< __int64, _I64_MIN, _I64_MAX> Chris@16: { }; Chris@16: Chris@16: template<> Chris@16: class integer_traits< unsigned __int64> Chris@16: : public std::numeric_limits< unsigned __int64>, Chris@16: public detail::integer_traits_base< unsigned __int64, 0, _UI64_MAX> Chris@16: { }; Chris@16: Chris@16: #endif Chris@16: #endif Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif /* BOOST_INTEGER_TRAITS_HPP */ Chris@16: Chris@16: Chris@16: