| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | /* boost integer_traits.hpp header file
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright Jens Maurer 2000 | 
					
						
							|  |  |  |  * Permission to use, copy, modify, sell, and distribute this software | 
					
						
							| 
									
										
										
										
											2001-03-01 18:54:36 +00:00
										 |  |  |  * is hereby granted without fee provided that the above copyright notice | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  |  * 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 <boost/config.hpp>
 | 
					
						
							| 
									
										
										
										
											2001-04-01 11:59:18 +00:00
										 |  |  | #include <boost/limits.hpp>
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | // These are an implementation detail and not part of the interface
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | #include <limits.h>
 | 
					
						
							| 
									
										
										
										
											2001-09-24 18:43:20 +00:00
										 |  |  | #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | #include <wchar.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace boost { | 
					
						
							|  |  |  | template<class T> | 
					
						
							|  |  |  | class integer_traits : public std::numeric_limits<T> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  |   BOOST_STATIC_CONSTANT(bool, is_integral = false); | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace detail { | 
					
						
							|  |  |  | template<class T, T min_val, T max_val> | 
					
						
							|  |  |  | class integer_traits_base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  |   BOOST_STATIC_CONSTANT(bool, is_integral = true); | 
					
						
							|  |  |  |   BOOST_STATIC_CONSTANT(T, const_min = min_val); | 
					
						
							|  |  |  |   BOOST_STATIC_CONSTANT(T, const_max = max_val); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
 | 
					
						
							| 
									
										
										
										
											2001-11-18 17:37:21 +00:00
										 |  |  | //  A definition is required even for integral static constants
 | 
					
						
							|  |  |  | template<class T, T min_val, T max_val> | 
					
						
							|  |  |  | const bool integer_traits_base<T, min_val, max_val>::is_integral; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | template<class T, T min_val, T max_val> | 
					
						
							|  |  |  | const T integer_traits_base<T, min_val, max_val>::const_min; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<class T, T min_val, T max_val> | 
					
						
							|  |  |  | const T integer_traits_base<T, min_val, max_val>::const_max; | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | } // namespace detail
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<bool> | 
					
						
							|  |  |  |   : public std::numeric_limits<bool>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<bool, false, true> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<char> | 
					
						
							|  |  |  |   : public std::numeric_limits<char>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<char, CHAR_MIN, CHAR_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<signed char> | 
					
						
							|  |  |  |   : public std::numeric_limits<signed char>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<signed char, SCHAR_MIN, SCHAR_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned char> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned char>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned char, 0, UCHAR_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | #ifndef BOOST_NO_INTRINSIC_WCHAR_T
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<wchar_t> | 
					
						
							|  |  |  |   : public std::numeric_limits<wchar_t>, | 
					
						
							| 
									
										
										
										
											2001-09-24 18:43:20 +00:00
										 |  |  | #if defined(WCHAR_MIN) && defined(WCHAR_MAX)
 | 
					
						
							|  |  |  |     public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX> | 
					
						
							|  |  |  | #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
 | 
					
						
							| 
									
										
										
										
											2001-05-08 11:11:30 +00:00
										 |  |  |     // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
 | 
					
						
							| 
									
										
										
										
											2001-05-02 15:44:02 +00:00
										 |  |  |     public detail::integer_traits_base<wchar_t, 0, 0xffff> | 
					
						
							| 
									
										
										
										
											2001-10-30 20:55:18 +00:00
										 |  |  | #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) || (defined __APPLE__) || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
 | 
					
						
							| 
									
										
										
										
											2001-09-24 23:45:49 +00:00
										 |  |  |     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
 | 
					
						
							| 
									
										
										
										
											2001-10-30 20:55:18 +00:00
										 |  |  |     //  - SGI MIPSpro with native library
 | 
					
						
							|  |  |  |     //  - gcc 3.x on HP-UX
 | 
					
						
							|  |  |  |     //  - Mac OS X with native library
 | 
					
						
							| 
									
										
										
										
											2001-05-02 16:18:08 +00:00
										 |  |  |     public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX> | 
					
						
							| 
									
										
										
										
											2001-10-30 20:55:18 +00:00
										 |  |  | #elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
 | 
					
						
							| 
									
										
										
										
											2001-09-24 23:45:49 +00:00
										 |  |  |     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
 | 
					
						
							| 
									
										
										
										
											2001-10-30 20:55:18 +00:00
										 |  |  |     //  - gcc 2.95.x on HP-UX
 | 
					
						
							| 
									
										
										
										
											2001-09-24 23:45:49 +00:00
										 |  |  |     // (also, std::numeric_limits<wchar_t> appears to return the wrong values).
 | 
					
						
							| 
									
										
										
										
											2001-05-08 18:15:32 +00:00
										 |  |  |     public detail::integer_traits_base<wchar_t, 0, UINT_MAX> | 
					
						
							| 
									
										
										
										
											2001-05-02 16:18:08 +00:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2001-09-24 18:43:20 +00:00
										 |  |  | #error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
 | 
					
						
							| 
									
										
										
										
											2001-05-02 15:44:02 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2001-04-30 13:36:05 +00:00
										 |  |  | { }; | 
					
						
							|  |  |  | #endif // BOOST_NO_INTRINSIC_WCHAR_T
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<short> | 
					
						
							|  |  |  |   : public std::numeric_limits<short>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<short, SHRT_MIN, SHRT_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned short> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned short>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned short, 0, USHRT_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<int> | 
					
						
							|  |  |  |   : public std::numeric_limits<int>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<int, INT_MIN, INT_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned int> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned int>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned int, 0, UINT_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<long> | 
					
						
							|  |  |  |   : public std::numeric_limits<long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<long, LONG_MIN, LONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned long> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned long, 0, ULONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-07 18:49:12 +00:00
										 |  |  | #if defined(ULLONG_MAX) && !defined(__SUNPRO_CC)
 | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | #elif defined(ULONG_LONG_MAX)
 | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							| 
									
										
										
										
											2001-06-20 11:42:44 +00:00
										 |  |  | #elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
 | 
					
						
							| 
									
										
										
										
											2001-04-16 13:32:54 +00:00
										 |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							|  |  |  | template<> | 
					
						
							|  |  |  | class integer_traits<unsigned long long> | 
					
						
							|  |  |  |   : public std::numeric_limits<unsigned long long>, | 
					
						
							|  |  |  |     public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX> | 
					
						
							|  |  |  | { }; | 
					
						
							| 
									
										
										
										
											2000-07-07 16:04:40 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace boost
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* BOOST_INTEGER_TRAITS_HPP */
 | 
					
						
							| 
									
										
										
										
											2001-05-08 11:11:30 +00:00
										 |  |  | 
 |