williamr@2: /* boost integer_traits.hpp header file williamr@2: * williamr@2: * Copyright Jens Maurer 2000 williamr@2: * Distributed under the Boost Software License, Version 1.0. (See williamr@2: * accompanying file LICENSE_1_0.txt or copy at williamr@2: * http://www.boost.org/LICENSE_1_0.txt) williamr@2: * williamr@2: * $Id: integer_traits.hpp,v 1.30 2006/02/05 10:19:42 johnmaddock Exp $ williamr@2: * williamr@2: * Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers williamr@2: */ williamr@2: williamr@2: // See http://www.boost.org/libs/integer for documentation. williamr@2: williamr@2: williamr@2: #ifndef BOOST_INTEGER_TRAITS_HPP williamr@2: #define BOOST_INTEGER_TRAITS_HPP williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: // These are an implementation detail and not part of the interface williamr@2: #include williamr@2: // we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it, williamr@2: // and some may have but not ... williamr@2: #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__)) williamr@2: #include williamr@2: #endif williamr@2: williamr@2: williamr@2: namespace boost { williamr@2: template williamr@2: class integer_traits : public std::numeric_limits williamr@2: { williamr@2: public: williamr@2: BOOST_STATIC_CONSTANT(bool, is_integral = false); williamr@2: }; williamr@2: williamr@2: namespace detail { williamr@2: template williamr@2: class integer_traits_base williamr@2: { williamr@2: public: williamr@2: BOOST_STATIC_CONSTANT(bool, is_integral = true); williamr@2: BOOST_STATIC_CONSTANT(T, const_min = min_val); williamr@2: BOOST_STATIC_CONSTANT(T, const_max = max_val); williamr@2: }; williamr@2: williamr@2: #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION williamr@2: // A definition is required even for integral static constants williamr@2: template williamr@2: const bool integer_traits_base::is_integral; williamr@2: williamr@2: template williamr@2: const T integer_traits_base::const_min; williamr@2: williamr@2: template williamr@2: const T integer_traits_base::const_max; williamr@2: #endif williamr@2: williamr@2: } // namespace detail williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: #ifndef BOOST_NO_INTRINSIC_WCHAR_T williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: // Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native williamr@2: // library: they are wrong! williamr@2: #if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__) williamr@2: public detail::integer_traits_base williamr@2: #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__)) williamr@2: // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned: williamr@2: public detail::integer_traits_base williamr@2: #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\ williamr@2: || (defined __APPLE__)\ williamr@2: || (defined(__OpenBSD__) && defined(__GNUC__))\ williamr@2: || (defined(__NetBSD__) && defined(__GNUC__))\ williamr@2: || (defined(__FreeBSD__) && defined(__GNUC__))\ williamr@2: || (defined(__DragonFly__) && defined(__GNUC__))\ williamr@2: || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT)) williamr@2: // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int. williamr@2: // - SGI MIPSpro with native library williamr@2: // - gcc 3.x on HP-UX williamr@2: // - Mac OS X with native library williamr@2: // - gcc on FreeBSD, OpenBSD and NetBSD williamr@2: public detail::integer_traits_base williamr@2: #elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT) williamr@2: // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int. williamr@2: // - gcc 2.95.x on HP-UX williamr@2: // (also, std::numeric_limits appears to return the wrong values). williamr@2: public detail::integer_traits_base williamr@2: #else williamr@2: #error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler. williamr@2: #endif williamr@2: { }; williamr@2: #endif // BOOST_NO_INTRINSIC_WCHAR_T williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits williamr@2: : public std::numeric_limits, williamr@2: public detail::integer_traits_base williamr@2: { }; williamr@2: williamr@2: #if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) williamr@2: #if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG) williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::long_long_type> williamr@2: : public std::numeric_limits< ::boost::long_long_type>, williamr@2: public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX> williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::ulong_long_type> williamr@2: : public std::numeric_limits< ::boost::ulong_long_type>, williamr@2: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX> williamr@2: { }; williamr@2: williamr@2: #elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG) williamr@2: williamr@2: template<> williamr@2: 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>{ }; williamr@2: template<> williamr@2: class integer_traits< ::boost::ulong_long_type> williamr@2: : public std::numeric_limits< ::boost::ulong_long_type>, williamr@2: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX> williamr@2: { }; williamr@2: williamr@2: #elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG) williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::long_long_type> williamr@2: : public std::numeric_limits< ::boost::long_long_type>, williamr@2: public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX> williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::ulong_long_type> williamr@2: : public std::numeric_limits< ::boost::ulong_long_type>, williamr@2: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX> williamr@2: { }; williamr@2: williamr@2: #elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG) williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::long_long_type> williamr@2: : public std::numeric_limits< ::boost::long_long_type>, williamr@2: public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX> williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::ulong_long_type> williamr@2: : public std::numeric_limits< ::boost::ulong_long_type>, williamr@2: public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX> williamr@2: { }; williamr@2: williamr@2: #elif defined(BOOST_HAS_LONG_LONG) williamr@2: // williamr@2: // we have long long but no constants, this happens for example with gcc in -ansi mode, williamr@2: // we'll just have to work out the values for ourselves (assumes 2's compliment representation): williamr@2: // williamr@2: template<> williamr@2: class integer_traits< ::boost::long_long_type> williamr@2: : public std::numeric_limits< ::boost::long_long_type>, williamr@2: public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))> williamr@2: { }; williamr@2: williamr@2: template<> williamr@2: class integer_traits< ::boost::ulong_long_type> williamr@2: : public std::numeric_limits< ::boost::ulong_long_type>, williamr@2: public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL> williamr@2: { }; williamr@2: williamr@2: #endif williamr@2: #endif williamr@2: williamr@2: } // namespace boost williamr@2: williamr@2: #endif /* BOOST_INTEGER_TRAITS_HPP */ williamr@2: williamr@2: williamr@2: