mirror of
https://github.com/boostorg/integer.git
synced 2025-06-26 20:41:33 +02:00
Compare commits
76 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
229056d7bc | |||
648ff2fe0c | |||
2d259a4f3e | |||
2fd0675a21 | |||
f041dc0f0a | |||
188cef05a9 | |||
2ae867bcf8 | |||
2fcbc31b77 | |||
4af7660410 | |||
2b7ed6ebf7 | |||
203705fea6 | |||
ed80575830 | |||
f27ad7b337 | |||
55e1796c7a | |||
053be71261 | |||
10e5587b9e | |||
2f91e69629 | |||
422ef1ebe6 | |||
edfaeb6c0e | |||
3c7910fad3 | |||
600801670e | |||
85e4d3e23d | |||
4e2c8440b5 | |||
94ace80618 | |||
550fe9d89f | |||
cd6a9565ff | |||
19ed0e48e0 | |||
559b44c259 | |||
0d058f42cc | |||
b162db6b72 | |||
f17447cd24 | |||
7d8e93a6ac | |||
4935afbcd4 | |||
167961aba1 | |||
a1cc143de7 | |||
7ce7ba6bfd | |||
cd99f24a87 | |||
c8cb2b24a1 | |||
93612e6c0b | |||
d9f5b1bbf9 | |||
37d7590f2f | |||
cb9a7792cc | |||
291bb8c525 | |||
8602a17a10 | |||
29275d71aa | |||
9df9a90217 | |||
65607e3b82 | |||
39399de102 | |||
27aae3b3cb | |||
21fe6251ab | |||
07019a8801 | |||
3892592661 | |||
0935f20c69 | |||
7197caf500 | |||
92a46aac83 | |||
c32a045fa4 | |||
0c31aa03f0 | |||
bfc384a435 | |||
198530a48d | |||
91f511cab4 | |||
0f84fe35da | |||
fa5aba353f | |||
170a352574 | |||
4862574bb1 | |||
f2d22d091f | |||
1e6ab2dc10 | |||
a656e7744f | |||
46fdbba4b8 | |||
f2ea03679b | |||
890e28ab67 | |||
1252426554 | |||
19fb03cefe | |||
a9b35df2f8 | |||
49a8d69fe3 | |||
9cc587a7f2 | |||
2de1422682 |
11
cstdint.htm
11
cstdint.htm
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
||||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||||
<title>Header boost/cstdint.hpp</title>
|
<title>Header boost/cstdint.hpp</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body bgcolor="#FFFFFF" text="#000000">
|
<body bgcolor="#FFFFFF" text="#000000">
|
||||||
|
|
||||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
|
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Header
|
||||||
boost/cstdint.hpp </h1>
|
boost/cstdint.hpp </h1>
|
||||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||||
provides the typedef's useful for
|
provides the typedef's useful for
|
||||||
@ -69,9 +69,12 @@ representing any value of any signed integer type.</p>
|
|||||||
capable of representing any value of any unsigned integer type.</p>
|
capable of representing any value of any unsigned integer type.</p>
|
||||||
<p>These types are required.</p>
|
<p>These types are required.</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->19 Aug 2001<!--webbot bot="Timestamp" endspan i-checksum="14767" -->
|
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||||
</p>
|
</p>
|
||||||
<p> </p>
|
<p><EFBFBD> Copyright Beman Dawes 2000</p>
|
||||||
|
|
||||||
|
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||||
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -1,26 +1,29 @@
|
|||||||
// boost cstdint.hpp test program ------------------------------------------//
|
// boost cstdint.hpp test program ------------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Beman Dawes 2000. Permission to copy, use, modify, sell
|
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||||
// and distribute this software is granted provided this copyright
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// 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.
|
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
||||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||||
// 28 Jun 00 Initial version
|
// 28 Jun 00 Initial version
|
||||||
|
#define __STDC_CONSTANT_MACROS
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#define __STDC_CONSTANT_MACROS
|
|
||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
#error This test makes no sense with NDEBUG defined
|
int main()
|
||||||
#endif
|
{
|
||||||
|
std::cout << "This test makes no sense with NDEBUG defined.\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
//
|
//
|
||||||
@ -110,10 +113,24 @@ void integral_constant_type_check(T1, T2)
|
|||||||
assert(sizeof(T1) == sizeof(T2));
|
assert(sizeof(T1) == sizeof(T2));
|
||||||
assert(t1 == t2);
|
assert(t1 == t2);
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(BOOST_HAS_STDINT_H)
|
||||||
|
// native headers are permitted to promote small
|
||||||
|
// unsigned types to type int:
|
||||||
|
if(sizeof(T1) >= sizeof(int))
|
||||||
|
{
|
||||||
if(t1 > 0)
|
if(t1 > 0)
|
||||||
assert(t2 > 0);
|
assert(t2 > 0);
|
||||||
else
|
else
|
||||||
assert(!(t2 > 0));
|
assert(!(t2 > 0));
|
||||||
|
}
|
||||||
|
else if(t1 < 0)
|
||||||
|
assert(!(t2 > 0));
|
||||||
|
#else
|
||||||
|
if(t1 > 0)
|
||||||
|
assert(t2 > 0);
|
||||||
|
else
|
||||||
|
assert(!(t2 > 0));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,5 +230,4 @@ int main()
|
|||||||
std::cout << "OK\n";
|
std::cout << "OK\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||||
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
|
||||||
|
|
||||||
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a></cite> provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. The types of the masking constants come from the <a href="../integer.htm">integer type selection templates</a> header.</p>
|
<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp"><boost/integer/integer_mask.hpp></a></cite> provide bit masks for a certain bit position or a contiguous-bit pack of a certain size. The types of the masking constants come from the <a href="../integer.htm">integer type selection templates</a> header.</p>
|
||||||
@ -196,16 +196,15 @@ contaimination of values by the higher, unused bits.</p>
|
|||||||
<h2><a name="credits">Credits</a></h2>
|
<h2><a name="credits">Credits</a></h2>
|
||||||
|
|
||||||
<p>The author of the Boost bit mask class templates is <a
|
<p>The author of the Boost bit mask class templates is <a
|
||||||
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
|
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised September 23, 2001</p>
|
<p>Revised September 23, 2001</p>
|
||||||
|
|
||||||
<p>© Copyright Daryle Walker 2001. Permission to copy, use,
|
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||||
modify, sell and distribute this document is granted provided this
|
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||||
copyright notice appears in all copies. This document is provided
|
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||||
"as is" without express or implied warranty, and with no claim
|
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||||
as to its suitability for any purpose.</p>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,73 +1,125 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
|
||||||
<title>Binary Logarithm Template</title>
|
<title>Binary Logarithm Template</title>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<body bgcolor="white" text="black">
|
<body bgcolor="white" text="black">
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
|
||||||
|
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||||
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
align="middle" width="277" height="86">Binary Logarithm Template</h1>
|
||||||
|
|
||||||
|
|
||||||
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a></cite> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.</p>
|
<p>The class template in <cite><a href="../../../boost/integer/static_log2.hpp"><boost/integer/static_log2.hpp></a></cite> determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="contents">Contents</a></h2>
|
<h2><a name="contents">Contents</a></h2>
|
||||||
|
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
<li><a href="#contents">Contents</a></li>
|
<li><a href="#contents">Contents</a></li>
|
||||||
|
|
||||||
<li><a href="#synopsis">Synopsis</a></li>
|
<li><a href="#synopsis">Synopsis</a></li>
|
||||||
|
|
||||||
<li><a href="#usage">Usage</a></li>
|
<li><a href="#usage">Usage</a></li>
|
||||||
|
|
||||||
<li><a href="#example">Example</a></li>
|
<li><a href="#example">Example</a></li>
|
||||||
|
|
||||||
<li><a href="#demo">Demonstration Program</a></li>
|
<li><a href="#demo">Demonstration Program</a></li>
|
||||||
|
|
||||||
<li><a href="#rationale">Rationale</a></li>
|
<li><a href="#rationale">Rationale</a></li>
|
||||||
|
|
||||||
<li><a href="#credits">Credits</a></li>
|
<li><a href="#credits">Credits</a></li>
|
||||||
|
|
||||||
|
<li><a href="#whatsnew"><b>What's new</b></a></li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="synopsis">Synopsis</a></h2>
|
<h2><a name="synopsis">Synopsis</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<blockquote><pre>
|
<blockquote><pre>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
template < unsigned long Value >
|
typedef <em>implementation-defined</em> static_log2_argument_type;
|
||||||
struct static_log2
|
typedef <em>implementation-defined</em> static_log2_result_type;
|
||||||
{
|
|
||||||
static const int value = <em>implementation_defined</em>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template < >
|
template < static_log2_argument_type arg >
|
||||||
struct static_log2< 0ul >
|
struct static_log2
|
||||||
{
|
{
|
||||||
|
static const static_log2_result_type value = <em>implementation-defined</em>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template < >
|
||||||
|
struct static_log2< 0 >
|
||||||
|
{
|
||||||
// The logarithm of zero is undefined.
|
// The logarithm of zero is undefined.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="usage">Usage</a></h2>
|
<h2><a name="usage">Usage</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>The <code>boost::static_log2</code> class template takes one template
|
<p>The <code>boost::static_log2</code> class template takes one template
|
||||||
parameter, a value of type <code>unsigned long</code>. The template
|
parameter, a value of type <code>static_log2_argument_type</code>. The template
|
||||||
only defines one member, <code>value</code>, that returns the truncated
|
only defines one member, <code>value</code>, which gives the truncated
|
||||||
base-two logarithm of the template parameter.</p>
|
base-two logarithm of the template argument.</p>
|
||||||
|
|
||||||
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
<p>Since the logarithm of zero, for any base, is undefined, there is a
|
||||||
specialization of <code>static_log2</code> for a template parameter
|
specialization of <code>static_log2</code> for a template argument
|
||||||
of zero. This specialization has no members, so an attempt to use
|
of zero. This specialization has no members, so an attempt to use
|
||||||
the base-two logarithm of zero results in a compile-time error.</p>
|
the base-two logarithm of zero results in a compile-time error.</p>
|
||||||
|
|
||||||
|
<p>Note: <ul>
|
||||||
|
|
||||||
|
<li><code>static_log2_argument_type</code> is an <i>unsigned integer
|
||||||
|
type</i> (C++ standard, 3.9.1p3).</li>
|
||||||
|
|
||||||
|
<li><code>static_log2_result_type</code> is an <i>integer type</i>
|
||||||
|
(C++ standard, 3.9.1p7).</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="example">Example</a></h2>
|
<h2><a name="example">Example</a></h2>
|
||||||
|
|
||||||
<blockquote><pre>
|
|
||||||
#include <boost/integer/static_log2.hpp>
|
|
||||||
|
|
||||||
template < unsigned long Value >
|
|
||||||
|
<blockquote><pre>
|
||||||
|
|
||||||
|
#include "boost/integer/static_log2.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
template < boost::static_log2_argument_type value >
|
||||||
bool is_it_what()
|
bool is_it_what()
|
||||||
{
|
{
|
||||||
typedef boost::static_log2<Value> lb_type;
|
typedef boost::static_log2<value> lb_type;
|
||||||
|
|
||||||
int temp = lb_type::value;
|
int temp = lb_type::value;
|
||||||
//...
|
//...
|
||||||
|
|
||||||
return (temp % 2) != 0;
|
return (temp % 2) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,25 +129,32 @@ int main()
|
|||||||
{
|
{
|
||||||
bool temp = is_it_what<2000>();
|
bool temp = is_it_what<2000>();
|
||||||
//...
|
//...
|
||||||
|
# if 0
|
||||||
#if 0
|
|
||||||
temp = is_it_what<0>(); // would give an error
|
temp = is_it_what<0>(); // would give an error
|
||||||
#endif
|
# endif
|
||||||
//...
|
//...
|
||||||
|
|
||||||
temp = is_it_what<24>();
|
temp = is_it_what<24>();
|
||||||
//...
|
//...
|
||||||
}
|
}
|
||||||
|
|
||||||
</pre></blockquote>
|
</pre></blockquote>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="demo">Demonstration Program</a></h2>
|
<h2><a name="demo">Demonstration Program</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>The program <a href="../test/static_log2_test.cpp">static_log2_test.cpp</a>
|
<p>The program <a href="../test/static_log2_test.cpp">static_log2_test.cpp</a>
|
||||||
is a simplistic demonstration of the results from instantiating various
|
is a simplistic demonstration of the results from instantiating various
|
||||||
examples of the binary logarithm class template.</p>
|
examples of the binary logarithm class template.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="rationale">Rationale</a></h2>
|
<h2><a name="rationale">Rationale</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>The base-two (binary) logarithm, abbreviated <dfn>lb</dfn>, function
|
<p>The base-two (binary) logarithm, abbreviated <dfn>lb</dfn>, function
|
||||||
is occasionally used to give order-estimates of computer algorithms.
|
is occasionally used to give order-estimates of computer algorithms.
|
||||||
The truncated logarithm can be considered the highest power-of-two in a
|
The truncated logarithm can be considered the highest power-of-two in a
|
||||||
@ -104,20 +163,53 @@ integers). Sometimes the highest-bit position could be used in generic
|
|||||||
programming, which requires the position to be statically (<i>i.e.</i>
|
programming, which requires the position to be statically (<i>i.e.</i>
|
||||||
at compile-time) available.</p>
|
at compile-time) available.</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h2><a name="whatsnew">Changes from previous versions:</a></h2>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li><i>New in version 1.32.0:</i><br><br>
|
||||||
|
|
||||||
|
The argument type and the result type of <code>boost::static_log2</code>
|
||||||
|
are now typedef'd. Formerly, they were hardcoded as <code>unsigned long</code>
|
||||||
|
and <code>int</code> respectively. Please, use the provided typedefs in new
|
||||||
|
code (and update old code as soon as possible).
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h2><a name="credits">Credits</a></h2>
|
<h2><a name="credits">Credits</a></h2>
|
||||||
|
|
||||||
<p>The author of the Boost binary logarithm class template is <a
|
|
||||||
href="../../../people/daryle_walker.html">Daryle Walker</a>. Giovanni Bajo
|
|
||||||
added support for compilers without partial template specialization.</p>
|
<p>The original version of the Boost binary logarithm class template was
|
||||||
|
written by <a href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>
|
||||||
|
and then enhanced by Giovanni Bajo with support for compilers without
|
||||||
|
partial template specialization. The current version was suggested,
|
||||||
|
together with a reference implementation, by Vesa Karvonen. Gennaro Prota
|
||||||
|
wrote the actual source file.
|
||||||
|
</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised May 14, 2002</p>
|
|
||||||
|
|
||||||
<p>© Copyright Daryle Walker 2001. Permission to copy, use,
|
|
||||||
modify, sell and distribute this document is granted provided this
|
<p>Revised July 19, 2004</p>
|
||||||
copyright notice appears in all copies. This document is provided
|
|
||||||
"as is" without express or implied warranty, and with no claim
|
<p>© Copyright Daryle Walker 2001.<br>
|
||||||
as to its suitability for any purpose.</p>
|
© Copyright Gennaro Prota 2004.</p>
|
||||||
|
|
||||||
|
Distributed under the Boost Software License, Version 1.0.
|
||||||
|
(See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||||
|
http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
<body bgcolor="white" text="black" link="blue" alink="red" vlink="purple">
|
||||||
<h1><img src="../../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
|
||||||
align="middle" width="277" height="86">Compile-Time Extrema
|
align="middle" width="277" height="86">Compile-Time Extrema
|
||||||
Templates</h1>
|
Templates</h1>
|
||||||
|
|
||||||
@ -106,16 +106,15 @@ class template.</p>
|
|||||||
<h2><a name="credits">Credits</a></h2>
|
<h2><a name="credits">Credits</a></h2>
|
||||||
|
|
||||||
<p>The author of the Boost compile-time extrema class templates is <a
|
<p>The author of the Boost compile-time extrema class templates is <a
|
||||||
href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
|
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a>.</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised October 12, 2001</p>
|
<p>Revised October 12, 2001</p>
|
||||||
|
|
||||||
<p>© Copyright Daryle Walker 2001. Permission to copy, use,
|
<p>© Copyright Daryle Walker 2001. Use, modification, and distribution are
|
||||||
modify, sell and distribute this document is granted provided this
|
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||||
copyright notice appears in all copies. This document is provided
|
href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||||
"as is" without express or implied warranty, and with no claim
|
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||||
as to its suitability for any purpose.</p>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
// boost cstdint.hpp header file ------------------------------------------//
|
// boost cstdint.hpp header file ------------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
// (C) Copyright Beman Dawes 1999.
|
||||||
// and distribute this software is granted provided this copyright
|
// (C) Copyright Jens Mauer 2001
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// (C) Copyright John Maddock 2001
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// Distributed under the Boost
|
||||||
// any purpose.
|
// Software License, Version 1.0. (See accompanying file
|
||||||
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
|
// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
|
||||||
@ -35,12 +36,52 @@
|
|||||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||||
# define BOOST_NO_INT64_T
|
# define BOOST_NO_INT64_T
|
||||||
# endif
|
# endif
|
||||||
# elif defined(__FreeBSD__)
|
# elif defined(__FreeBSD__) || defined(__IBMCPP__)
|
||||||
# include <inttypes.h>
|
# include <inttypes.h>
|
||||||
# else
|
# else
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
|
|
||||||
|
// There is a bug in Cygwin two _C macros
|
||||||
|
# if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
|
||||||
|
# undef INTMAX_C
|
||||||
|
# undef UINTMAX_C
|
||||||
|
# define INTMAX_C(c) c##LL
|
||||||
|
# define UINTMAX_C(c) c##ULL
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#ifdef __QNX__
|
||||||
|
|
||||||
|
// QNX (Dinkumware stdlib) defines these as non-standard names.
|
||||||
|
// Reflect to the standard names.
|
||||||
|
|
||||||
|
typedef ::intleast8_t int_least8_t;
|
||||||
|
typedef ::intfast8_t int_fast8_t;
|
||||||
|
typedef ::uintleast8_t uint_least8_t;
|
||||||
|
typedef ::uintfast8_t uint_fast8_t;
|
||||||
|
|
||||||
|
typedef ::intleast16_t int_least16_t;
|
||||||
|
typedef ::intfast16_t int_fast16_t;
|
||||||
|
typedef ::uintleast16_t uint_least16_t;
|
||||||
|
typedef ::uintfast16_t uint_fast16_t;
|
||||||
|
|
||||||
|
typedef ::intleast32_t int_least32_t;
|
||||||
|
typedef ::intfast32_t int_fast32_t;
|
||||||
|
typedef ::uintleast32_t uint_least32_t;
|
||||||
|
typedef ::uintfast32_t uint_fast32_t;
|
||||||
|
|
||||||
|
# ifndef BOOST_NO_INT64_T
|
||||||
|
|
||||||
|
typedef ::intleast64_t int_least64_t;
|
||||||
|
typedef ::intfast64_t int_fast64_t;
|
||||||
|
typedef ::uintleast64_t uint_least64_t;
|
||||||
|
typedef ::uintfast64_t uint_fast64_t;
|
||||||
|
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -81,8 +122,8 @@ namespace boost
|
|||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
|
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__)
|
||||||
// FreeBSD has an <inttypes.h> that contains much of what we need
|
// FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
|
||||||
# include <inttypes.h>
|
# include <inttypes.h>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
@ -131,7 +172,8 @@ namespace boost {
|
|||||||
|
|
||||||
#else // BOOST_HAS_STDINT_H
|
#else // BOOST_HAS_STDINT_H
|
||||||
|
|
||||||
# include <limits.h> // implementation artifact; not part of interface
|
# include <boost/limits.hpp> // implementation artifact; not part of interface
|
||||||
|
# include <limits.h> // needed for limits macros
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@ -161,12 +203,29 @@ namespace boost
|
|||||||
// 16-bit types -----------------------------------------------------------//
|
// 16-bit types -----------------------------------------------------------//
|
||||||
|
|
||||||
# if USHRT_MAX == 0xffff
|
# if USHRT_MAX == 0xffff
|
||||||
|
# if defined(__crayx1)
|
||||||
|
// The Cray X1 has a 16-bit short, however it is not recommend
|
||||||
|
// for use in performance critical code.
|
||||||
|
typedef short int16_t;
|
||||||
|
typedef short int_least16_t;
|
||||||
|
typedef int int_fast16_t;
|
||||||
|
typedef unsigned short uint16_t;
|
||||||
|
typedef unsigned short uint_least16_t;
|
||||||
|
typedef unsigned int uint_fast16_t;
|
||||||
|
# else
|
||||||
typedef short int16_t;
|
typedef short int16_t;
|
||||||
typedef short int_least16_t;
|
typedef short int_least16_t;
|
||||||
typedef short int_fast16_t;
|
typedef short int_fast16_t;
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
typedef unsigned short uint_least16_t;
|
typedef unsigned short uint_least16_t;
|
||||||
typedef unsigned short uint_fast16_t;
|
typedef unsigned short uint_fast16_t;
|
||||||
|
# endif
|
||||||
|
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
|
||||||
|
// no 16-bit types on Cray:
|
||||||
|
typedef short int_least16_t;
|
||||||
|
typedef short int_fast16_t;
|
||||||
|
typedef unsigned short uint_least16_t;
|
||||||
|
typedef unsigned short uint_fast16_t;
|
||||||
# else
|
# else
|
||||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||||
# endif
|
# endif
|
||||||
@ -205,14 +264,14 @@ namespace boost
|
|||||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
typedef long long intmax_t;
|
typedef ::boost::long_long_type intmax_t;
|
||||||
typedef unsigned long long uintmax_t;
|
typedef ::boost::ulong_long_type uintmax_t;
|
||||||
typedef long long int64_t;
|
typedef ::boost::long_long_type int64_t;
|
||||||
typedef long long int_least64_t;
|
typedef ::boost::long_long_type int_least64_t;
|
||||||
typedef long long int_fast64_t;
|
typedef ::boost::long_long_type int_fast64_t;
|
||||||
typedef unsigned long long uint64_t;
|
typedef ::boost::ulong_long_type uint64_t;
|
||||||
typedef unsigned long long uint_least64_t;
|
typedef ::boost::ulong_long_type uint_least64_t;
|
||||||
typedef unsigned long long uint_fast64_t;
|
typedef ::boost::ulong_long_type uint_fast64_t;
|
||||||
|
|
||||||
# elif ULONG_MAX != 0xffffffff
|
# elif ULONG_MAX != 0xffffffff
|
||||||
|
|
||||||
@ -228,6 +287,15 @@ namespace boost
|
|||||||
# else
|
# else
|
||||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||||
# endif
|
# endif
|
||||||
|
# elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
|
||||||
|
__extension__ typedef long long intmax_t;
|
||||||
|
__extension__ typedef unsigned long long uintmax_t;
|
||||||
|
__extension__ typedef long long int64_t;
|
||||||
|
__extension__ typedef long long int_least64_t;
|
||||||
|
__extension__ typedef long long int_fast64_t;
|
||||||
|
__extension__ typedef unsigned long long uint64_t;
|
||||||
|
__extension__ typedef unsigned long long uint_least64_t;
|
||||||
|
__extension__ typedef unsigned long long uint_fast64_t;
|
||||||
# elif defined(BOOST_HAS_MS_INT64)
|
# elif defined(BOOST_HAS_MS_INT64)
|
||||||
//
|
//
|
||||||
// we have Borland/Intel/Microsoft __int64:
|
// we have Borland/Intel/Microsoft __int64:
|
||||||
@ -374,3 +442,5 @@ BOOST_HAS_STDINT_H is defined (John Maddock).
|
|||||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
177
include/boost/detail/extended_integer.hpp
Normal file
177
include/boost/detail/extended_integer.hpp
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
// Boost detail/extended_integer.hpp header file ----------------------------//
|
||||||
|
|
||||||
|
// (C) Copyright Daryle Walker 2008. Distributed under the Boost Software
|
||||||
|
// License, Version 1.0. (See the accompanying file LICENSE_1_0.txt or a copy
|
||||||
|
// at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||||
|
|
||||||
|
// Encapsulates the double-long and __int64 type families as a single family,
|
||||||
|
// as they are mutually exclusive.
|
||||||
|
|
||||||
|
/** \file
|
||||||
|
\brief Common definition of extended integer types.
|
||||||
|
|
||||||
|
Instead of other Boost headers making separate \#defines for the double-long
|
||||||
|
and __int64 type families, since they're mutually exclusive, make a single
|
||||||
|
set of types and macros for the family that exists (if either).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
||||||
|
#define BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp> // for BOOST_HAS_LONG_LONG and BOOST_HAS_MS_INT64
|
||||||
|
|
||||||
|
#include <climits> // for CHAR_BIT, etc.
|
||||||
|
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
// Extended integer type macro and alias definitions -----------------------//
|
||||||
|
|
||||||
|
// (Unsigned) long long family
|
||||||
|
#ifdef BOOST_HAS_LONG_LONG
|
||||||
|
|
||||||
|
// Existence
|
||||||
|
#define BOOST_HAS_XINT 1
|
||||||
|
|
||||||
|
// Extents
|
||||||
|
#ifdef ULLONG_MAX
|
||||||
|
#define BOOST_XINT_MAX LLONG_MAX
|
||||||
|
#define BOOST_XINT_MIN LLONG_MIN
|
||||||
|
#define BOOST_UXINT_MAX ULLONG_MAX
|
||||||
|
#elif defined(ULONG_LONG_MAX)
|
||||||
|
#define BOOST_XINT_MAX LONG_LONG_MAX
|
||||||
|
#define BOOST_XINT_MIN LONG_LONG_MIN
|
||||||
|
#define BOOST_UXINT_MAX ULONG_LONG_MAX
|
||||||
|
#elif defined(ULONGLONG_MAX)
|
||||||
|
#define BOOST_XINT_MAX LONGLONG_MAX
|
||||||
|
#define BOOST_XINT_MIN LONGLONG_MIN
|
||||||
|
#define BOOST_UXINT_MAX ULONGLONG_MAX
|
||||||
|
#elif defined(_LLONG_MAX) && defined(_C2)
|
||||||
|
#define BOOST_XINT_MAX _LLONG_MAX
|
||||||
|
#define BOOST_XINT_MIN (-_LLONG_MAX - _C2)
|
||||||
|
#define BOOST_UXINT_MAX _ULLONG_MAX
|
||||||
|
#else // guess
|
||||||
|
// Sometimes we get the double-long types without the corresponding constants,
|
||||||
|
// e.g. GCC in "-ansi" mode. In this case, we'll just have to work out the
|
||||||
|
// values ourselves. (Here we assume a two's complement representation.)
|
||||||
|
#define BOOST_XINT_MIN (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))
|
||||||
|
#define BOOST_XINT_MAX (~ BOOST_XINT_MIN)
|
||||||
|
#define BOOST_UXINT_MAX (~ 0uLL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Types
|
||||||
|
typedef ::boost:: long_long_type xint_t;
|
||||||
|
typedef ::boost::ulong_long_type uxint_t;
|
||||||
|
|
||||||
|
// (Unsigned) __int64 family
|
||||||
|
#elif defined(BOOST_HAS_MS_INT64)
|
||||||
|
|
||||||
|
// Existence
|
||||||
|
#define BOOST_HAS_XINT 1
|
||||||
|
|
||||||
|
// Extents
|
||||||
|
#ifdef _UI64_MAX
|
||||||
|
#define BOOST_XINT_MAX _I64_MAX
|
||||||
|
#define BOOST_XINT_MIN _I64_MIN
|
||||||
|
#define BOOST_UXINT_MAX _UI64_MAX
|
||||||
|
#else // guess
|
||||||
|
// The types are exactly 2's-compl. 64-bit, so we'll enter the values directly.
|
||||||
|
#define BOOST_XINT_MAX 0x7FFFFFFFFFFFFFFFi64
|
||||||
|
#define BOOST_XINT_MIN 0x8000000000000000i64
|
||||||
|
#define BOOST_UXINT_MAX 0xFFFFFFFFFFFFFFFFui64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Types
|
||||||
|
typedef __int64 xint_t;
|
||||||
|
typedef unsigned __int64 uxint_t;
|
||||||
|
|
||||||
|
// Neither
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Non-existence
|
||||||
|
#define BOOST_HAS_XINT 0
|
||||||
|
|
||||||
|
// Dummy extents
|
||||||
|
#define BOOST_XINT_MAX LONG_MAX
|
||||||
|
#define BOOST_XINT_MIN LONG_MIN
|
||||||
|
#define BOOST_UXINT_MAX ULONG_MAX
|
||||||
|
|
||||||
|
// Dummy types
|
||||||
|
typedef signed long xint_t;
|
||||||
|
typedef unsigned long uxint_t;
|
||||||
|
|
||||||
|
#endif // defined(BOOST_HAS_LONG_LONG)/defined(BOOST_HAS_MS_INT64)/else
|
||||||
|
|
||||||
|
/** \def BOOST_HAS_XINT
|
||||||
|
|
||||||
|
\brief Flag for extended integer types.
|
||||||
|
|
||||||
|
Indicates the presence of one of the two common extended integer type
|
||||||
|
families, either (<code>unsigned</code>) <code>long long</code> or
|
||||||
|
(<code>unsigned</code>) <code>__int64</code>. \c BOOST_HAS_XINT is \c 1 if
|
||||||
|
either type family is defined, and \c 0 if neither is.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \def BOOST_XINT_MAX
|
||||||
|
|
||||||
|
\brief Maximum value for the signed extended integer type.
|
||||||
|
|
||||||
|
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||||
|
|
||||||
|
Macro constant representing the largest value the signed extended integer
|
||||||
|
type supports. Its composition may be another macro, an expression, or a
|
||||||
|
literal. Defaulted to \c LONG_MAX if \c BOOST_HAS_XINT is zero.
|
||||||
|
*/
|
||||||
|
/** \def BOOST_XINT_MIN
|
||||||
|
|
||||||
|
\brief Minimum value for the signed extended integer type.
|
||||||
|
|
||||||
|
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||||
|
|
||||||
|
Macro constant representing the smallest value the signed extended integer
|
||||||
|
type supports. Its composition may be another macro, an expression, or a
|
||||||
|
literal. Defaulted to \c LONG_MIN if \c BOOST_HAS_XINT is zero.
|
||||||
|
*/
|
||||||
|
/** \def BOOST_UXINT_MAX
|
||||||
|
|
||||||
|
\brief Maximum value for the unsigned extended integer type.
|
||||||
|
|
||||||
|
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||||
|
|
||||||
|
Macro constant representing the largest value the unsigned extended integer
|
||||||
|
type supports. Its composition may be another macro, an expression, or a
|
||||||
|
literal. Defaulted to \c ULONG_MAX if \c BOOST_HAS_XINT is zero. (Use
|
||||||
|
\c 0u for the type's minimum value.)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** \typedef signed long boost::detail::xint_t
|
||||||
|
|
||||||
|
\brief Alias for the signed extended integer type.
|
||||||
|
|
||||||
|
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||||
|
|
||||||
|
Alias representing the signed extended integer type, no matter which type
|
||||||
|
family it came from. Defaulted to <code>signed long</code> if
|
||||||
|
\c BOOST_HAS_XINT is zero.
|
||||||
|
*/
|
||||||
|
/** \typedef unsigned long ::boost::detail::uxint_t
|
||||||
|
|
||||||
|
\brief Alias for the signed extended integer type.
|
||||||
|
|
||||||
|
\pre \c BOOST_HAS_XINT is \c \#defined to be \c 1.
|
||||||
|
|
||||||
|
Alias representing the unsigned extended integer type, no matter which type
|
||||||
|
family it came from. Defaulted to <code>unsigned long</code> if
|
||||||
|
\c BOOST_HAS_XINT is zero.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
|
||||||
|
#endif // BOOST_DETAIL_EXTENDED_INTEGER_HPP
|
@ -1,12 +1,10 @@
|
|||||||
// boost integer.hpp header file -------------------------------------------//
|
// boost integer.hpp header file -------------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
// Copyright Beman Dawes and Daryle Walker 1999. Distributed under the Boost
|
||||||
// and distribute this software is granted provided this copyright
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// 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.
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
|
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
|
||||||
@ -36,7 +34,7 @@ namespace boost
|
|||||||
template< int Category > struct int_least_helper {}; // default is empty
|
template< int Category > struct int_least_helper {}; // default is empty
|
||||||
|
|
||||||
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
|
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
|
||||||
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
|
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
|
||||||
// no specializations for 0 and 5: requests for a type > long are in error
|
// no specializations for 0 and 5: requests for a type > long are in error
|
||||||
template<> struct int_least_helper<1> { typedef long least; };
|
template<> struct int_least_helper<1> { typedef long least; };
|
||||||
template<> struct int_least_helper<2> { typedef int least; };
|
template<> struct int_least_helper<2> { typedef int least; };
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
// Boost integer/integer_mask.hpp header file ------------------------------//
|
// Boost integer/integer_mask.hpp header file ------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell and
|
// (C) Copyright Daryle Walker 2001.
|
||||||
// distribute this software is granted provided this copyright notice appears
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// in all copies. This software is provided "as is" without express or
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// implied warranty, and with no claim as to its suitability for any purpose.
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
|
||||||
|
@ -1,141 +1,132 @@
|
|||||||
// Boost integer/static_log2.hpp header file -------------------------------//
|
// -------------- Boost static_log2.hpp header file ----------------------- //
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001 Daryle Walker.
|
||||||
|
// Copyright (C) 2003 Vesa Karvonen.
|
||||||
|
// Copyright (C) 2003 Gennaro Prota.
|
||||||
|
//
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
//
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
// ------------------------------------------------------------------------- //
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. 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 updates, documentation, and revision history.
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
#ifndef BOOST_INTEGER_STATIC_LOG2_HPP
|
||||||
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
#define BOOST_INTEGER_STATIC_LOG2_HPP
|
||||||
|
|
||||||
#include <boost/integer_fwd.hpp> // self include
|
#include "boost/config.hpp" // for BOOST_STATIC_CONSTANT
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
|
namespace boost {
|
||||||
#include <boost/limits.hpp> // for std::numeric_limits
|
|
||||||
|
|
||||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
namespace detail {
|
||||||
#include <boost/pending/ct_if.hpp> // for boost::ct_if<>
|
|
||||||
#endif
|
namespace static_log2_impl {
|
||||||
|
|
||||||
|
// choose_initial_n<>
|
||||||
|
//
|
||||||
|
// Recursively doubles its integer argument, until it
|
||||||
|
// becomes >= of the "width" (C99, 6.2.6.2p4) of
|
||||||
|
// static_log2_argument_type.
|
||||||
|
//
|
||||||
|
// Used to get the maximum power of two less then the width.
|
||||||
|
//
|
||||||
|
// Example: if on your platform argument_type has 48 value
|
||||||
|
// bits it yields n=32.
|
||||||
|
//
|
||||||
|
// It's easy to prove that, starting from such a value
|
||||||
|
// of n, the core algorithm works correctly for any width
|
||||||
|
// of static_log2_argument_type and that recursion always
|
||||||
|
// terminates with x = 1 and n = 0 (see the algorithm's
|
||||||
|
// invariant).
|
||||||
|
|
||||||
|
typedef unsigned long argument_type;
|
||||||
|
typedef int result_type;
|
||||||
|
|
||||||
|
|
||||||
namespace boost
|
template <result_type n>
|
||||||
{
|
struct choose_initial_n {
|
||||||
|
|
||||||
|
enum { c = (argument_type(1) << n << n) != 0 };
|
||||||
|
BOOST_STATIC_CONSTANT(
|
||||||
|
result_type,
|
||||||
|
value = !c*n + choose_initial_n<2*c*n>::value
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct choose_initial_n<0> {
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Implementation details --------------------------------------------------//
|
|
||||||
|
|
||||||
namespace detail
|
// start computing from n_zero - must be a power of two
|
||||||
{
|
const result_type n_zero = 16;
|
||||||
|
const result_type initial_n = choose_initial_n<n_zero>::value;
|
||||||
|
|
||||||
// Forward declarations
|
// static_log2_impl<>
|
||||||
template < unsigned long Val, int Place = 0, int Index
|
//
|
||||||
= std::numeric_limits<unsigned long>::digits >
|
// * Invariant:
|
||||||
struct static_log2_helper_t;
|
// 2n
|
||||||
|
// 1 <= x && x < 2 at the start of each recursion
|
||||||
|
// (see also choose_initial_n<>)
|
||||||
|
//
|
||||||
|
// * Type requirements:
|
||||||
|
//
|
||||||
|
// argument_type maybe any unsigned type with at least n_zero + 1
|
||||||
|
// value bits. (Note: If larger types will be standardized -e.g.
|
||||||
|
// unsigned long long- then the argument_type typedef can be
|
||||||
|
// changed without affecting the rest of the code.)
|
||||||
|
//
|
||||||
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
template <argument_type x, result_type n = initial_n>
|
||||||
|
struct static_log2_impl {
|
||||||
|
|
||||||
template < unsigned long Val, int Place >
|
enum { c = (x >> n) > 0 }; // x >= 2**n ?
|
||||||
struct static_log2_helper_t< Val, Place, 1 >;
|
BOOST_STATIC_CONSTANT(
|
||||||
|
result_type,
|
||||||
|
value = c*n + (static_log2_impl< (x>>c*n), n/2 >::value)
|
||||||
|
);
|
||||||
|
|
||||||
#else
|
};
|
||||||
|
|
||||||
template < int Place >
|
template <>
|
||||||
struct static_log2_helper_final_step;
|
struct static_log2_impl<1, 0> {
|
||||||
|
BOOST_STATIC_CONSTANT(result_type, value = 0);
|
||||||
|
};
|
||||||
|
|
||||||
template < unsigned long Val, int Place = 0, int Index
|
}
|
||||||
= std::numeric_limits<unsigned long>::digits >
|
} // detail
|
||||||
struct static_log2_helper_nopts_t;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Recursively build the logarithm by examining the upper bits
|
|
||||||
template < unsigned long Val, int Place, int Index >
|
|
||||||
struct static_log2_helper_t
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
BOOST_STATIC_CONSTANT( int, half_place = Index / 2 );
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, lower_mask = (1ul << half_place)
|
|
||||||
- 1ul );
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, upper_mask = ~lower_mask );
|
|
||||||
BOOST_STATIC_CONSTANT( bool, do_shift = (Val & upper_mask) != 0ul );
|
|
||||||
|
|
||||||
BOOST_STATIC_CONSTANT( unsigned long, new_val = do_shift ? (Val
|
|
||||||
>> half_place) : Val );
|
|
||||||
BOOST_STATIC_CONSTANT( int, new_place = do_shift ? (Place + half_place)
|
|
||||||
: Place );
|
|
||||||
BOOST_STATIC_CONSTANT( int, new_index = Index - half_place );
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
typedef static_log2_helper_t<new_val, new_place, new_index> next_step_type;
|
|
||||||
#else
|
|
||||||
typedef static_log2_helper_nopts_t<new_val, new_place, new_index> next_step_type;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_t
|
|
||||||
|
|
||||||
// Non-recursive case
|
|
||||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place >
|
|
||||||
struct static_log2_helper_t< Val, Place, 1 >
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = Place );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_t
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
template < int Place >
|
|
||||||
struct static_log2_helper_final_step
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = Place );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_final_step
|
|
||||||
|
|
||||||
template < unsigned long Val, int Place, int Index >
|
|
||||||
struct static_log2_helper_nopts_t
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
typedef static_log2_helper_t<Val, Place, Index> recursive_step_type;
|
|
||||||
typedef static_log2_helper_final_step<Place> final_step_type;
|
|
||||||
|
|
||||||
typedef typename ct_if<( Index != 1 ), recursive_step_type,
|
|
||||||
final_step_type>::type next_step_type;
|
|
||||||
|
|
||||||
public:
|
|
||||||
BOOST_STATIC_CONSTANT( int, value = next_step_type::value );
|
|
||||||
|
|
||||||
}; // boost::detail::static_log2_helper_nopts_t
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
|
|
||||||
// Compile-time log-base-2 evaluator class declaration ---------------------//
|
|
||||||
|
|
||||||
template < unsigned long Value >
|
// --------------------------------------
|
||||||
struct static_log2
|
// static_log2<x>
|
||||||
{
|
// ----------------------------------------
|
||||||
BOOST_STATIC_CONSTANT( int, value
|
|
||||||
= detail::static_log2_helper_t<Value>::value );
|
|
||||||
};
|
|
||||||
|
|
||||||
template < >
|
typedef detail::static_log2_impl::argument_type static_log2_argument_type;
|
||||||
struct static_log2< 0ul >
|
typedef detail::static_log2_impl::result_type static_log2_result_type;
|
||||||
{
|
|
||||||
// The logarithm of zero is undefined.
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace boost
|
template <static_log2_argument_type x>
|
||||||
|
struct static_log2 {
|
||||||
|
|
||||||
|
BOOST_STATIC_CONSTANT(
|
||||||
|
static_log2_result_type,
|
||||||
|
value = detail::static_log2_impl::static_log2_impl<x>::value
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // BOOST_INTEGER_STATIC_LOG2_HPP
|
template <>
|
||||||
|
struct static_log2<0> { };
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // include guard
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
// Boost integer/static_min_max.hpp header file ----------------------------//
|
// Boost integer/static_min_max.hpp header file ----------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001.
|
||||||
// and distribute this software is granted provided this copyright notice
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// appears in all copies. This software is provided "as is" without
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// express or implied warranty, and with no claim as to its suitability
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// for any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for updates, documentation, and revision history.
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
// Boost integer_fwd.hpp header file ---------------------------------------//
|
// Boost integer_fwd.hpp header file ---------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright boost.org 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Dave Abrahams and Daryle Walker 2001. Distributed under the Boost
|
||||||
// and distribute this software is granted provided this copyright
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// 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.
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_FWD_HPP
|
#ifndef BOOST_INTEGER_FWD_HPP
|
||||||
#define BOOST_INTEGER_FWD_HPP
|
#define BOOST_INTEGER_FWD_HPP
|
||||||
@ -69,10 +67,10 @@ template < >
|
|||||||
|
|
||||||
#ifdef ULLONG_MAX
|
#ifdef ULLONG_MAX
|
||||||
template < >
|
template < >
|
||||||
class integer_traits< long long >;
|
class integer_traits< ::boost::long_long_type>;
|
||||||
|
|
||||||
template < >
|
template < >
|
||||||
class integer_traits< unsigned long long >;
|
class integer_traits< ::boost::ulong_long_type >;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
/* boost integer_traits.hpp header file
|
/* boost integer_traits.hpp header file
|
||||||
*
|
*
|
||||||
* Copyright Jens Maurer 2000
|
* Copyright Jens Maurer 2000
|
||||||
* Permission to use, copy, modify, sell, and distribute this software
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
* is hereby granted without fee provided that the above copyright notice
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
* appears in all copies and that both that copyright notice and this
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
* 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$
|
* $Id$
|
||||||
*
|
*
|
||||||
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
|
|
||||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||||
#define BOOST_INTEGER_TRAITS_HPP
|
#define BOOST_INTEGER_TRAITS_HPP
|
||||||
|
|
||||||
@ -23,7 +21,9 @@
|
|||||||
|
|
||||||
// These are an implementation detail and not part of the interface
|
// These are an implementation detail and not part of the interface
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && !defined(BOOST_NO_CWCHAR)
|
// we need wchar.h for WCHAR_MAX/MIN but not all platforms provide it,
|
||||||
|
// and some may have <wchar.h> but not <cwchar> ...
|
||||||
|
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && (!defined(BOOST_NO_CWCHAR) || defined(sun) || defined(__sun) || defined(__QNX__))
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -88,17 +88,25 @@ class integer_traits<unsigned char>
|
|||||||
template<>
|
template<>
|
||||||
class integer_traits<wchar_t>
|
class integer_traits<wchar_t>
|
||||||
: public std::numeric_limits<wchar_t>,
|
: public std::numeric_limits<wchar_t>,
|
||||||
#if defined(WCHAR_MIN) && defined(WCHAR_MAX)
|
// Don't trust WCHAR_MIN and WCHAR_MAX with Mac OS X's native
|
||||||
|
// library: they are wrong!
|
||||||
|
#if defined(WCHAR_MIN) && defined(WCHAR_MAX) && !defined(__APPLE__)
|
||||||
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
public detail::integer_traits_base<wchar_t, WCHAR_MIN, WCHAR_MAX>
|
||||||
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
#elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
|
||||||
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
// No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
|
||||||
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
public detail::integer_traits_base<wchar_t, 0, 0xffff>
|
||||||
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400)) || (defined __APPLE__) || (defined(__FreeBSD__) && defined(__GNUC__)) || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
#elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\
|
||||||
|
|| (defined __APPLE__)\
|
||||||
|
|| (defined(__OpenBSD__) && defined(__GNUC__))\
|
||||||
|
|| (defined(__NetBSD__) && defined(__GNUC__))\
|
||||||
|
|| (defined(__FreeBSD__) && defined(__GNUC__))\
|
||||||
|
|| (defined(__DragonFly__) && defined(__GNUC__))\
|
||||||
|
|| (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
|
||||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
|
||||||
// - SGI MIPSpro with native library
|
// - SGI MIPSpro with native library
|
||||||
// - gcc 3.x on HP-UX
|
// - gcc 3.x on HP-UX
|
||||||
// - Mac OS X with native library
|
// - Mac OS X with native library
|
||||||
// - gcc on FreeBSD
|
// - gcc on FreeBSD, OpenBSD and NetBSD
|
||||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||||
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
||||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
||||||
@ -147,42 +155,82 @@ class integer_traits<unsigned long>
|
|||||||
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
public detail::integer_traits_base<unsigned long, 0, ULONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
#if defined(ULLONG_MAX) && !defined(__SUNPRO_CC)
|
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T)
|
||||||
|
#if defined(ULLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<long long>
|
class integer_traits< ::boost::long_long_type>
|
||||||
: public std::numeric_limits<long long>,
|
: public std::numeric_limits< ::boost::long_long_type>,
|
||||||
public detail::integer_traits_base<long long, LLONG_MIN, LLONG_MAX>
|
public detail::integer_traits_base< ::boost::long_long_type, LLONG_MIN, LLONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<unsigned long long>
|
class integer_traits< ::boost::ulong_long_type>
|
||||||
: public std::numeric_limits<unsigned long long>,
|
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||||
public detail::integer_traits_base<unsigned long long, 0, ULLONG_MAX>
|
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULLONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
#elif defined(ULONG_LONG_MAX)
|
|
||||||
|
#elif defined(ULONG_LONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<long long>
|
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>{ };
|
||||||
: public std::numeric_limits<long long>,
|
|
||||||
public detail::integer_traits_base<long long, LONG_LONG_MIN, LONG_LONG_MAX>
|
|
||||||
{ };
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<unsigned long long>
|
class integer_traits< ::boost::ulong_long_type>
|
||||||
: public std::numeric_limits<unsigned long long>,
|
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||||
public detail::integer_traits_base<unsigned long long, 0, ULONG_LONG_MAX>
|
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONG_LONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
#elif defined(ULONGLONG_MAX) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
|
||||||
|
#elif defined(ULONGLONG_MAX) && defined(BOOST_HAS_LONG_LONG)
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<long long>
|
class integer_traits< ::boost::long_long_type>
|
||||||
: public std::numeric_limits<long long>,
|
: public std::numeric_limits< ::boost::long_long_type>,
|
||||||
public detail::integer_traits_base<long long, LONGLONG_MIN, LONGLONG_MAX>
|
public detail::integer_traits_base< ::boost::long_long_type, LONGLONG_MIN, LONGLONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
class integer_traits<unsigned long long>
|
class integer_traits< ::boost::ulong_long_type>
|
||||||
: public std::numeric_limits<unsigned long long>,
|
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||||
public detail::integer_traits_base<unsigned long long, 0, ULONGLONG_MAX>
|
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ULONGLONG_MAX>
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
|
#elif defined(_LLONG_MAX) && defined(_C2) && defined(BOOST_HAS_LONG_LONG)
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class integer_traits< ::boost::long_long_type>
|
||||||
|
: public std::numeric_limits< ::boost::long_long_type>,
|
||||||
|
public detail::integer_traits_base< ::boost::long_long_type, -_LLONG_MAX - _C2, _LLONG_MAX>
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class integer_traits< ::boost::ulong_long_type>
|
||||||
|
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||||
|
public detail::integer_traits_base< ::boost::ulong_long_type, 0, _ULLONG_MAX>
|
||||||
|
{ };
|
||||||
|
|
||||||
|
#elif defined(BOOST_HAS_LONG_LONG)
|
||||||
|
//
|
||||||
|
// we have long long but no constants, this happens for example with gcc in -ansi mode,
|
||||||
|
// we'll just have to work out the values for ourselves (assumes 2's compliment representation):
|
||||||
|
//
|
||||||
|
template<>
|
||||||
|
class integer_traits< ::boost::long_long_type>
|
||||||
|
: public std::numeric_limits< ::boost::long_long_type>,
|
||||||
|
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
|
||||||
|
{ };
|
||||||
|
|
||||||
|
template<>
|
||||||
|
class integer_traits< ::boost::ulong_long_type>
|
||||||
|
: public std::numeric_limits< ::boost::ulong_long_type>,
|
||||||
|
public detail::integer_traits_base< ::boost::ulong_long_type, 0, ~0uLL>
|
||||||
|
{ };
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
#endif /* BOOST_INTEGER_TRAITS_HPP */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@
|
|||||||
<body bgcolor="white" text="black">
|
<body bgcolor="white" text="black">
|
||||||
<table border="1" bgcolor="teal" cellpadding="2">
|
<table border="1" bgcolor="teal" cellpadding="2">
|
||||||
<tr>
|
<tr>
|
||||||
<td bgcolor="white"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
<td bgcolor="white"><img src="../../boost.png" alt="boost.png (6897 bytes)" width="277" height="86"></td>
|
||||||
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
|
<td><a href="../../index.htm"><font face="Arial" color="white"><big>Home</big></font></a></td>
|
||||||
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
|
<td><a href="../libraries.htm"><font face="Arial" color="white"><big>Libraries</big></font></a></td>
|
||||||
<td><a href="../../people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
|
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="white"><big>People</big></font></a></td>
|
||||||
<td><a href="../../more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
|
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="white"><big>FAQ</big></font></a></td>
|
||||||
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
|
<td><a href="../../more/index.htm"><font face="Arial" color="white"><big>More</big></font></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -121,8 +121,13 @@ instead.</p>
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->03 Oct 2001<!--webbot bot="Timestamp" endspan i-checksum="14373" -->
|
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->06 Nov 2007<!--webbot bot="Timestamp" endspan i-checksum="15272" -->
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>© Copyright Beman Dawes 2003</p>
|
||||||
|
|
||||||
|
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||||
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
17
integer.htm
17
integer.htm
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<body bgcolor="white" text="black">
|
<body bgcolor="white" text="black">
|
||||||
<h1>
|
<h1>
|
||||||
<img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)"
|
<img src="../../boost.png" alt="boost.png (6897 bytes)"
|
||||||
align="middle" width="277" height="86">Integer Type Selection
|
align="middle" width="277" height="86">Integer Type Selection
|
||||||
Templates</h1>
|
Templates</h1>
|
||||||
|
|
||||||
@ -193,21 +193,20 @@ href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></cite>.</p>
|
|||||||
<h2><a name="credits">Credits</a></h2>
|
<h2><a name="credits">Credits</a></h2>
|
||||||
|
|
||||||
<p>The author of most of the Boost integer type choosing templates is <a
|
<p>The author of most of the Boost integer type choosing templates is <a
|
||||||
href="../../people/beman_dawes.html">Beman Dawes</a>. He gives thanks
|
href="http://www.boost.org/people/beman_dawes.html">Beman Dawes</a>. He gives thanks
|
||||||
to Valentin Bonnard and
|
to Valentin Bonnard and
|
||||||
<a href="../../people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
|
<a href="http://www.boost.org/people/kevlin_henney.htm"> Kevlin Henney</a> for sharing
|
||||||
their designs for similar templates. <a
|
their designs for similar templates. <a
|
||||||
href="../../people/daryle_walker.html">Daryle Walker</a> designed the
|
href="http://www.boost.org/people/daryle_walker.html">Daryle Walker</a> designed the
|
||||||
value-based sized templates.</p>
|
value-based sized templates.</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>Revised May 20, 2001</p>
|
<p>Revised May 20, 2001</p>
|
||||||
|
|
||||||
<p>© Copyright Beman Dawes 1999. Permission to copy, use, modify,
|
<p>© Copyright Beman Dawes 1999. Use, modification, and distribution are
|
||||||
sell and distribute this document is granted provided this copyright
|
subject to the Boost Software License, Version 1.0. (See accompanying file <a
|
||||||
notice appears in all copies. This document is provided "as
|
href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or a copy at <<a
|
||||||
is" without express or implied warranty, and with no claim as to
|
href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>>.)</p>
|
||||||
its suitability for any purpose.</p>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -1,20 +1,18 @@
|
|||||||
// boost integer.hpp test program ------------------------------------------//
|
// boost integer.hpp test program ------------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
|
// Copyright Beman Dawes 1999. Distributed under the Boost
|
||||||
// and distribute this software is granted provided this copyright
|
// Software License, Version 1.0. (See accompanying file
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// 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.
|
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
|
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
|
||||||
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||||
// 31 Aug 99 Initial version
|
// 31 Aug 99 Initial version
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
#include <boost/test/minimal.hpp> // for main, BOOST_CHECK
|
||||||
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
|
|
||||||
|
|
||||||
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
|
#include <boost/config.hpp> // for BOOST_NO_USING_TEMPLATE
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
@ -130,9 +128,27 @@ namespace boost
|
|||||||
|
|
||||||
|
|
||||||
// Test if a constant can fit within a certain type
|
// Test if a constant can fit within a certain type
|
||||||
#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < Number > :: Type ( Value ) == Value )
|
#define PRIVATE_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < Number > :: Type ( Value ) == Value )
|
||||||
|
|
||||||
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
#if ULONG_MAX > 0xFFFFFFFFL
|
||||||
|
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 64, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 63, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 62, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 61, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 60, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 59, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 58, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 57, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 56, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 55, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 54, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 53, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 52, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 51, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 50, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 49, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 48, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 47, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 46, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 45, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 44, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 43, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 42, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 41, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 40, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 39, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 38, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 37, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 36, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 35, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 34, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 33, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
||||||
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
||||||
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
||||||
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
||||||
@ -149,8 +165,28 @@ namespace boost
|
|||||||
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
||||||
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
||||||
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
||||||
|
#else
|
||||||
|
#define PRIVATE_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 32, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 31, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 30, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 29, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 28, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 27, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 26, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 25, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 24, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 23, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 22, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 21, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 20, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 19, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 18, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 17, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 16, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 15, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 14, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 13, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 12, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 11, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 10, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 9, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 8, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 7, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 6, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 5, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 4, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 3, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 2, Type, v); v >>= 1; \
|
||||||
|
PRIVATE_FIT_TEST(Template, 1, Type, v); v >>= 1; PRIVATE_FIT_TEST(Template, 0, Type, v); } while ( false )
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (ULONG_MAX >> Number) > :: Type ( Value ) == Value )
|
#define PRIVATE_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (ULONG_MAX >> Number) > :: Type ( Value ) == Value )
|
||||||
|
|
||||||
#define PRIVATE_SHIFTED_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
#define PRIVATE_SHIFTED_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
PRIVATE_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||||
@ -170,7 +206,7 @@ namespace boost
|
|||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
PRIVATE_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
||||||
PRIVATE_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
PRIVATE_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
||||||
|
|
||||||
#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MAX >> Number) > :: Type ( Value ) == Value )
|
#define PRIVATE_POS_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (LONG_MAX >> Number) > :: Type ( Value ) == Value )
|
||||||
|
|
||||||
#define PRIVATE_POS_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
#define PRIVATE_POS_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||||
@ -190,7 +226,7 @@ namespace boost
|
|||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 28, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 29, Type, v); v >>= 1; \
|
||||||
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
PRIVATE_POS_SHIFTED_FIT_TEST(Template, 30, Type, v); v >>= 1; PRIVATE_POS_SHIFTED_FIT_TEST(Template, 31, Type, v); } while ( false )
|
||||||
|
|
||||||
#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_TEST( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value )
|
#define PRIVATE_NEG_SHIFTED_FIT_TEST(Template, Number, Type, Value) BOOST_CHECK( Template < (LONG_MIN >> Number) > :: Type ( Value ) == Value )
|
||||||
|
|
||||||
#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
#define PRIVATE_NEG_FIT_TESTS(Template, Type, ValType, InitVal) do { ValType v = InitVal ; \
|
||||||
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 0, Type, v); v >>= 1; PRIVATE_NEG_SHIFTED_FIT_TEST(Template, 1, Type, v); v >>= 1; \
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<body bgcolor="#FFFFFF" text="#000000">
|
<body bgcolor="#FFFFFF" text="#000000">
|
||||||
|
|
||||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" width="277" height="86">Compile-Time Integral
|
||||||
Type Limits</h1>
|
Type Limits</h1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
@ -85,5 +85,10 @@ exercises the <code>integer_traits</code> class.
|
|||||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||||
traits idea on the boost mailing list in August 1999.
|
traits idea on the boost mailing list in August 1999.
|
||||||
<hr>
|
<hr>
|
||||||
<a href="../../people/jens_maurer.htm">
|
<p>Revised
|
||||||
Jens Maurer</a>, 2000-02-20
|
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->06 November 2007<!--webbot bot="Timestamp" endspan i-checksum="40336" --></p>
|
||||||
|
<p><EFBFBD> Copyright Beman Dawes 2000</p>
|
||||||
|
|
||||||
|
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||||
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||||
|
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
/* boost integer_traits.hpp tests
|
/* boost integer_traits.hpp tests
|
||||||
*
|
*
|
||||||
* Copyright Jens Maurer 2000
|
* Copyright Jens Maurer 2000
|
||||||
* Permission to use, copy, modify, sell, and distribute this software
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
* is hereby granted without fee provided that the above copyright notice
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
* appears in all copies and that both that copyright notice and this
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
* 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$
|
* $Id$
|
||||||
*
|
*
|
||||||
@ -55,14 +50,22 @@ void runtest(const char * type, T)
|
|||||||
{
|
{
|
||||||
typedef boost::integer_traits<T> traits;
|
typedef boost::integer_traits<T> traits;
|
||||||
std::cout << "Checking " << type
|
std::cout << "Checking " << type
|
||||||
<< "; min is " << make_char_numeric_for_streaming(traits::min())
|
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
|
||||||
<< ", max is " << make_char_numeric_for_streaming(traits::max())
|
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
BOOST_TEST(traits::is_specialized);
|
BOOST_CHECK(traits::is_specialized);
|
||||||
BOOST_TEST(traits::is_integer);
|
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
|
||||||
BOOST_TEST(traits::is_integral);
|
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
|
||||||
BOOST_TEST(traits::const_min == traits::min());
|
// generates different symbol names with a very long common prefix:
|
||||||
BOOST_TEST(traits::const_max == traits::max());
|
// the dummy "&& true" disambiguates between the symbols generated by this
|
||||||
|
// BOOST_CHECK instantiation and the preceding one.
|
||||||
|
BOOST_CHECK(traits::is_integer && true);
|
||||||
|
#else
|
||||||
|
BOOST_CHECK(traits::is_integer);
|
||||||
|
#endif
|
||||||
|
BOOST_CHECK(traits::is_integral == true);
|
||||||
|
BOOST_CHECK(traits::const_min == (traits::min)());
|
||||||
|
BOOST_CHECK(traits::const_max == (traits::max)());
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_main(int, char*[])
|
int test_main(int, char*[])
|
||||||
|
20
test/Jamfile.v2
Normal file
20
test/Jamfile.v2
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#~ Copyright Rene Rivera 2008
|
||||||
|
#~ Distributed under the Boost Software License, Version 1.0.
|
||||||
|
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
import testing ;
|
||||||
|
|
||||||
|
test-suite integer
|
||||||
|
: [ run cstdint_test.cpp ]
|
||||||
|
[ run integer_test.cpp
|
||||||
|
/boost/test//boost_unit_test_framework ]
|
||||||
|
[ run integer_traits_test.cpp
|
||||||
|
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run integer_mask_test.cpp
|
||||||
|
/boost/test//boost_unit_test_framework ]
|
||||||
|
[ run static_log2_test.cpp
|
||||||
|
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ run static_min_max_test.cpp
|
||||||
|
/boost/test//boost_test_exec_monitor/<link>static ]
|
||||||
|
[ compile issue_2134.cpp ]
|
||||||
|
;
|
233
test/cstdint_test.cpp
Normal file
233
test/cstdint_test.cpp
Normal file
@ -0,0 +1,233 @@
|
|||||||
|
// boost cstdint.hpp test program ------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||||
|
// Software License, Version 1.0. (See accompanying file
|
||||||
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
||||||
|
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||||
|
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||||
|
// 28 Jun 00 Initial version
|
||||||
|
#define __STDC_CONSTANT_MACROS
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "This test makes no sense with NDEBUG defined.\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
//
|
||||||
|
// the following class is designed to verify
|
||||||
|
// that the various INTXX_C macros can be used
|
||||||
|
// in integral constant expressions:
|
||||||
|
//
|
||||||
|
struct integral_constant_checker
|
||||||
|
{
|
||||||
|
static const boost::int8_t int8 = INT8_C(-127);
|
||||||
|
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||||
|
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||||
|
|
||||||
|
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||||
|
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||||
|
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||||
|
|
||||||
|
static const boost::int16_t int16 = INT16_C(-32767);
|
||||||
|
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||||
|
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||||
|
|
||||||
|
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||||
|
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||||
|
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||||
|
|
||||||
|
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||||
|
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||||
|
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||||
|
|
||||||
|
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||||
|
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||||
|
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||||
|
|
||||||
|
static void check();
|
||||||
|
};
|
||||||
|
|
||||||
|
void integral_constant_checker::check()
|
||||||
|
{
|
||||||
|
assert( int8 == -127 );
|
||||||
|
assert( int_least8 == -127 );
|
||||||
|
assert( int_fast8 == -127 );
|
||||||
|
assert( uint8 == 255u );
|
||||||
|
assert( uint_least8 == 255u );
|
||||||
|
assert( uint_fast8 == 255u );
|
||||||
|
assert( int16 == -32767 );
|
||||||
|
assert( int_least16 == -32767 );
|
||||||
|
assert( int_fast16 == -32767 );
|
||||||
|
assert( uint16 == 65535u );
|
||||||
|
assert( uint_least16 == 65535u );
|
||||||
|
assert( uint_fast16 == 65535u );
|
||||||
|
assert( int32 == -2147483647 );
|
||||||
|
assert( int_least32 == -2147483647 );
|
||||||
|
assert( int_fast32 == -2147483647 );
|
||||||
|
assert( uint32 == 4294967295u );
|
||||||
|
assert( uint_least32 == 4294967295u );
|
||||||
|
assert( uint_fast32 == 4294967295u );
|
||||||
|
}
|
||||||
|
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
|
||||||
|
//
|
||||||
|
// the following function simply verifies that the type
|
||||||
|
// of an integral constant is correctly defined:
|
||||||
|
//
|
||||||
|
#ifdef __BORLANDC__
|
||||||
|
#pragma option -w-8008
|
||||||
|
#pragma option -w-8066
|
||||||
|
#endif
|
||||||
|
template <class T1, class T2>
|
||||||
|
void integral_constant_type_check(T1, T2)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// the types T1 and T2 may not be exactly
|
||||||
|
// the same type, but they should be the
|
||||||
|
// same size and signedness. We could use
|
||||||
|
// numeric_limits to verify this, but
|
||||||
|
// numeric_limits implementations currently
|
||||||
|
// vary too much, or are incomplete or missing.
|
||||||
|
//
|
||||||
|
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
|
||||||
|
T2 t2 = static_cast<T2>(-1); // ditto
|
||||||
|
#if defined(BOOST_HAS_STDINT_H)
|
||||||
|
// if we have a native stdint.h
|
||||||
|
// then the INTXX_C macros may define
|
||||||
|
// a type that's wider than required:
|
||||||
|
assert(sizeof(T1) <= sizeof(T2));
|
||||||
|
#else
|
||||||
|
assert(sizeof(T1) == sizeof(T2));
|
||||||
|
assert(t1 == t2);
|
||||||
|
#endif
|
||||||
|
#if defined(BOOST_HAS_STDINT_H)
|
||||||
|
// native headers are permitted to promote small
|
||||||
|
// unsigned types to type int:
|
||||||
|
if(sizeof(T1) >= sizeof(int))
|
||||||
|
{
|
||||||
|
if(t1 > 0)
|
||||||
|
assert(t2 > 0);
|
||||||
|
else
|
||||||
|
assert(!(t2 > 0));
|
||||||
|
}
|
||||||
|
else if(t1 < 0)
|
||||||
|
assert(!(t2 > 0));
|
||||||
|
#else
|
||||||
|
if(t1 > 0)
|
||||||
|
assert(t2 > 0);
|
||||||
|
else
|
||||||
|
assert(!(t2 > 0));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||||
|
integral_constant_checker::check();
|
||||||
|
#endif
|
||||||
|
//
|
||||||
|
// verify the types of the integral constants:
|
||||||
|
//
|
||||||
|
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||||
|
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||||
|
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||||
|
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||||
|
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||||
|
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||||
|
#ifndef BOOST_NO_INT64_T
|
||||||
|
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||||
|
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||||
|
#endif
|
||||||
|
//
|
||||||
|
boost::int8_t int8 = INT8_C(-127);
|
||||||
|
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||||
|
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||||
|
|
||||||
|
boost::uint8_t uint8 = UINT8_C(255);
|
||||||
|
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||||
|
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||||
|
|
||||||
|
boost::int16_t int16 = INT16_C(-32767);
|
||||||
|
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||||
|
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||||
|
|
||||||
|
boost::uint16_t uint16 = UINT16_C(65535);
|
||||||
|
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||||
|
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||||
|
|
||||||
|
boost::int32_t int32 = INT32_C(-2147483647);
|
||||||
|
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||||
|
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||||
|
|
||||||
|
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||||
|
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||||
|
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INT64_T
|
||||||
|
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||||
|
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||||
|
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||||
|
|
||||||
|
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||||
|
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||||
|
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||||
|
|
||||||
|
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||||
|
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||||
|
#else
|
||||||
|
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||||
|
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
assert( int8 == -127 );
|
||||||
|
assert( int_least8 == -127 );
|
||||||
|
assert( int_fast8 == -127 );
|
||||||
|
assert( uint8 == 255u );
|
||||||
|
assert( uint_least8 == 255u );
|
||||||
|
assert( uint_fast8 == 255u );
|
||||||
|
assert( int16 == -32767 );
|
||||||
|
assert( int_least16 == -32767 );
|
||||||
|
assert( int_fast16 == -32767 );
|
||||||
|
assert( uint16 == 65535u );
|
||||||
|
assert( uint_least16 == 65535u );
|
||||||
|
assert( uint_fast16 == 65535u );
|
||||||
|
assert( int32 == -2147483647 );
|
||||||
|
assert( int_least32 == -2147483647 );
|
||||||
|
assert( int_fast32 == -2147483647 );
|
||||||
|
assert( uint32 == 4294967295u );
|
||||||
|
assert( uint_least32 == 4294967295u );
|
||||||
|
assert( uint_fast32 == 4294967295u );
|
||||||
|
|
||||||
|
#ifndef BOOST_NO_INT64_T
|
||||||
|
assert( int64 == INT64_C(-9223372036854775807) );
|
||||||
|
assert( int_least64 == INT64_C(-9223372036854775807) );
|
||||||
|
assert( int_fast64 == INT64_C(-9223372036854775807) );
|
||||||
|
assert( uint64 == UINT64_C(18446744073709551615) );
|
||||||
|
assert( uint_least64 == UINT64_C(18446744073709551615) );
|
||||||
|
assert( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||||
|
assert( intmax == INT64_C(-9223372036854775807) );
|
||||||
|
assert( uintmax == UINT64_C(18446744073709551615) );
|
||||||
|
#else
|
||||||
|
assert( intmax == -2147483647 );
|
||||||
|
assert( uintmax == 4294967295u );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "OK\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,10 +1,9 @@
|
|||||||
// boost integer_mask.hpp test program -------------------------------------//
|
// boost integer_mask.hpp test program -------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001.
|
||||||
// and distribute this software is granted provided this copyright
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
@ -20,16 +19,16 @@
|
|||||||
#include <iostream> // for std::cout (std::endl indirectly)
|
#include <iostream> // for std::cout (std::endl indirectly)
|
||||||
|
|
||||||
|
|
||||||
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
|
||||||
(v) >::high_bit == (1ul << (v)) );
|
(v) >::high_bit == (1ul << (v)) );
|
||||||
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \
|
#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_CHECK( ::boost::high_bit_mask_t< \
|
||||||
(v) >::high_bit_fast == (1ul << (v)) );
|
(v) >::high_bit_fast == (1ul << (v)) );
|
||||||
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
|
#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \
|
||||||
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
|
PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false)
|
||||||
|
|
||||||
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
#define PRIVATE_LOW_BITS_SLOW_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
|
||||||
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
(v) >::sig_bits == ((1ul << (v)) - 1) );
|
||||||
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_TEST( ::boost::low_bits_mask_t< \
|
#define PRIVATE_LOW_BITS_FAST_TEST(v) BOOST_CHECK( ::boost::low_bits_mask_t< \
|
||||||
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
|
(v) >::sig_bits_fast == ((1ul << (v)) - 1) );
|
||||||
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
|
#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \
|
||||||
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
|
PRIVATE_LOW_BITS_FAST_TEST(v); } while (false)
|
||||||
|
685
test/integer_test.cpp
Normal file
685
test/integer_test.cpp
Normal file
@ -0,0 +1,685 @@
|
|||||||
|
// boost integer.hpp test program ------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright Beman Dawes 1999. Distributed under the Boost
|
||||||
|
// Software License, Version 1.0. (See accompanying file
|
||||||
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
|
// See http://www.boost.org/libs/integer for documentation.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 16 Jul 08 Added MPL-compatible variants of the minimum-size and value-
|
||||||
|
// based integer templates. (Daryle Walker)
|
||||||
|
// 15 Jul 08 Added exact-integer templates; added MPL-compatible variant of
|
||||||
|
// processor-optimized integer template. (Daryle Walker)
|
||||||
|
// 14 Jul 08 Improved testing of processor-optimized integer template; added
|
||||||
|
// extended-integer support. (Daryle Walker)
|
||||||
|
// 13 Jul 08 Modernized tests w/ MPL instead of giant macros (Daryle Walker)
|
||||||
|
// 07 Jul 08 Changed tests to use the unit-test system (Daryle Walker)
|
||||||
|
// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker)
|
||||||
|
// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes)
|
||||||
|
// 31 Aug 99 Initial version
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE "Integer size-selection tests"
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp> // unit testing framework
|
||||||
|
|
||||||
|
#include <boost/config.hpp> // for BOOST_NO_SFINAE
|
||||||
|
#include <boost/cstdint.hpp> // for boost::uintmax_t, intmax_t
|
||||||
|
#include <boost/integer.hpp> // for boost::int_t, boost::uint_t, etc.
|
||||||
|
#include <boost/integer_traits.hpp> // for boost::integer_traits
|
||||||
|
#include <boost/limits.hpp> // for std::numeric_limits
|
||||||
|
|
||||||
|
#include <boost/detail/extended_integer.hpp> // BOOST_HAS_XINT, BOOST_UXINT_MAX
|
||||||
|
|
||||||
|
#include <boost/mpl/arithmetic.hpp> // for boost::mpl::plus, divides
|
||||||
|
#include <boost/mpl/assert.hpp> // for BOOST_MPL_ASSERT_RELATION, etc.
|
||||||
|
#include <boost/mpl/back.hpp> // for boost::mpl::back
|
||||||
|
#include <boost/mpl/copy.hpp> // for boost::mpl::copy
|
||||||
|
#include <boost/mpl/equal.hpp> // for boost::mpl::equal
|
||||||
|
#include <boost/mpl/front_inserter.hpp> // for boost::mpl::front_inserter
|
||||||
|
#include <boost/mpl/int.hpp> // for boost::mpl::int_
|
||||||
|
#include <boost/mpl/integral_c.hpp> // for boost::mpl::integral_c
|
||||||
|
#include <boost/mpl/joint_view.hpp> // for boost::mpl::joint_view
|
||||||
|
#include <boost/mpl/pop_back.hpp> // for boost::mpl::pop_back
|
||||||
|
#include <boost/mpl/push_back.hpp> // for boost::mpl::push_back
|
||||||
|
#include <boost/mpl/push_front.hpp> // for boost::mpl::push_front
|
||||||
|
#include <boost/mpl/range_c.hpp> // for boost::mpl::range_c
|
||||||
|
#include <boost/mpl/shift_right.hpp> // for boost::mpl::shift_right
|
||||||
|
#include <boost/mpl/sort.hpp> // for boost::mpl::sort
|
||||||
|
#include <boost/mpl/transform.hpp> // for boost::mpl::transform
|
||||||
|
#include <boost/mpl/transform_view.hpp> // for boost::mpl::transform_view
|
||||||
|
#include <boost/mpl/unpack_args.hpp> // for boost::mpl::unpack_args
|
||||||
|
#include <boost/mpl/vector.hpp> // for boost::mpl::vector
|
||||||
|
#include <boost/mpl/zip_view.hpp> // for boost::mpl::zip_view
|
||||||
|
|
||||||
|
#include <boost/type_traits/is_same.hpp> // for boost::is_same
|
||||||
|
#include <boost/type_traits/make_signed.hpp> // for boost::make_signed
|
||||||
|
|
||||||
|
#include <algorithm> // for std::binary_search
|
||||||
|
#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN, etc.
|
||||||
|
#include <cstddef> // for std::size_t
|
||||||
|
#include <iostream> // for std::cout
|
||||||
|
#include <ostream> // for std::endl
|
||||||
|
#include <typeinfo> // for std::type_info
|
||||||
|
|
||||||
|
|
||||||
|
// Control what the "fast" specialization of "short" is
|
||||||
|
#ifndef CONTROL_FAST_SHORT
|
||||||
|
#define CONTROL_FAST_SHORT long
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Control if the names of the types for each version
|
||||||
|
// of the integer templates will be printed.
|
||||||
|
#ifndef CONTROL_SHOW_TYPES
|
||||||
|
#define CONTROL_SHOW_TYPES 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Control if every potential bit-count is used, or only a selection
|
||||||
|
// For me, full counts increase compile time from 90 seconds to 20 minutes!
|
||||||
|
#ifndef CONTROL_FULL_COUNTS
|
||||||
|
#define CONTROL_FULL_COUNTS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// If specializations have not already been done, then we can confirm
|
||||||
|
// the effects of the fast types by making a specialization. If there
|
||||||
|
// is a specialization for "short," make sure that CONTROL_FAST_SHORT
|
||||||
|
// is set to a type distinct from "short" and the default implementation.
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
template < >
|
||||||
|
struct fast_integral< short >
|
||||||
|
{
|
||||||
|
typedef CONTROL_FAST_SHORT type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Logging
|
||||||
|
#if CONTROL_SHOW_TYPES
|
||||||
|
#define PRIVATE_SHOW_MESSAGE( m ) std::cout << m << std::endl
|
||||||
|
#else
|
||||||
|
#define PRIVATE_SHOW_MESSAGE( m ) BOOST_TEST_MESSAGE( m )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Custom types/templates, helper functions, and objects
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// List the built-in integral types, excluding the ones that are strong-typedefs
|
||||||
|
// of a lower type.
|
||||||
|
typedef boost::mpl::vector<
|
||||||
|
unsigned char
|
||||||
|
#if USHRT_MAX > UCHAR_MAX
|
||||||
|
, unsigned short
|
||||||
|
#endif
|
||||||
|
#if UINT_MAX > USHRT_MAX
|
||||||
|
, unsigned int
|
||||||
|
#endif
|
||||||
|
#if ULONG_MAX > UINT_MAX
|
||||||
|
, unsigned long
|
||||||
|
#endif
|
||||||
|
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
|
||||||
|
, boost::detail::uxint_t
|
||||||
|
#endif
|
||||||
|
> distinct_unsigned_types;
|
||||||
|
|
||||||
|
typedef boost::mpl::transform<
|
||||||
|
distinct_unsigned_types,
|
||||||
|
boost::make_signed< boost::mpl::_1 >
|
||||||
|
>::type distinct_signed_types;
|
||||||
|
|
||||||
|
// List the digit counts for each integral type
|
||||||
|
template < typename T >
|
||||||
|
struct digits_of
|
||||||
|
: boost::mpl::int_< std::numeric_limits<T>::digits >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::mpl::transform<
|
||||||
|
distinct_unsigned_types,
|
||||||
|
digits_of< boost::mpl::_1 >
|
||||||
|
>::type distinct_integral_bit_counts;
|
||||||
|
|
||||||
|
// Make list of bit counts between each offical point, plus CHAR_BIT/2
|
||||||
|
typedef boost::mpl::transform_view<
|
||||||
|
boost::mpl::zip_view<
|
||||||
|
boost::mpl::vector<
|
||||||
|
boost::mpl::push_front<
|
||||||
|
boost::mpl::pop_back< distinct_integral_bit_counts >::type,
|
||||||
|
boost::mpl::integral_c< int, 0 >
|
||||||
|
>::type,
|
||||||
|
distinct_integral_bit_counts
|
||||||
|
>
|
||||||
|
>,
|
||||||
|
boost::mpl::unpack_args<
|
||||||
|
boost::mpl::divides<
|
||||||
|
boost::mpl::plus< boost::mpl::_1, boost::mpl::_2 >,
|
||||||
|
boost::mpl::integral_c< int, 2 >
|
||||||
|
>
|
||||||
|
>
|
||||||
|
> median_bit_counts;
|
||||||
|
|
||||||
|
// Maximum number of bits allowed
|
||||||
|
typedef std::numeric_limits<boost:: intmax_t> intmax_limits;
|
||||||
|
typedef std::numeric_limits<boost::uintmax_t> uintmax_limits;
|
||||||
|
|
||||||
|
int const intmax_bits = intmax_limits::digits + 1;
|
||||||
|
int const uintmax_bits = uintmax_limits::digits;
|
||||||
|
|
||||||
|
// Make master lists including an outlier beyond all valid bit counts
|
||||||
|
#if CONTROL_FULL_COUNTS
|
||||||
|
typedef boost::mpl::range_c<int, 0, uintmax_bits + 2> bits_list;
|
||||||
|
#else
|
||||||
|
typedef boost::mpl::sort<
|
||||||
|
boost::mpl::copy<
|
||||||
|
boost::mpl::joint_view<
|
||||||
|
distinct_integral_bit_counts,
|
||||||
|
median_bit_counts
|
||||||
|
>,
|
||||||
|
boost::mpl::front_inserter<
|
||||||
|
boost::mpl::vector<
|
||||||
|
boost::mpl::integral_c<int, uintmax_bits + 1>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>::type
|
||||||
|
>::type bits_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Remove the outlier when all bits counts must be valid
|
||||||
|
#if CONTROL_FULL_COUNTS
|
||||||
|
typedef boost::mpl::range_c<int, 0, uintmax_bits + 1> valid_bits_list;
|
||||||
|
#else
|
||||||
|
typedef boost::mpl::pop_back<bits_list>::type valid_bits_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Replace the minimum bit count with one more, so right-shifting by a stored
|
||||||
|
// value doesn't give an invalid result
|
||||||
|
#if CONTROL_FULL_COUNTS
|
||||||
|
typedef boost::mpl::range_c<int, 1, uintmax_bits + 1>
|
||||||
|
valid_to_decrease_bits_list;
|
||||||
|
#else
|
||||||
|
typedef valid_bits_list valid_to_decrease_bits_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Replace the maximum bit count with one less, so left-shifting by a stored
|
||||||
|
// value doesn't give an invalid result
|
||||||
|
#if CONTROL_FULL_COUNTS
|
||||||
|
typedef boost::mpl::range_c<int, 0, uintmax_bits> valid_to_increase_ubits_list;
|
||||||
|
#else
|
||||||
|
typedef boost::mpl::push_back<
|
||||||
|
boost::mpl::pop_back< valid_bits_list >::type,
|
||||||
|
boost::mpl::integral_c< int, uintmax_bits - 1 >
|
||||||
|
>::type valid_to_increase_ubits_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Do it again for signed types since they have one-less bit to use for the
|
||||||
|
// mantissa (don't want to shift into the sign bit)
|
||||||
|
#if CONTROL_FULL_COUNTS
|
||||||
|
typedef boost::mpl::range_c<int, 0, intmax_bits - 2>
|
||||||
|
valid_to_increase_sbits_list;
|
||||||
|
#else
|
||||||
|
typedef boost::mpl::push_back<
|
||||||
|
boost::mpl::pop_back< valid_bits_list >::type,
|
||||||
|
boost::mpl::integral_c< int, intmax_bits - 3 >
|
||||||
|
>::type valid_to_increase_sbits_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// List the digit counts for each integral type, this time as an object, an
|
||||||
|
// array working as a sorted list
|
||||||
|
int const integral_bit_lengths[] = {
|
||||||
|
std::numeric_limits< unsigned char >::digits
|
||||||
|
#if USHRT_MAX > UCHAR_MAX
|
||||||
|
, std::numeric_limits< unsigned short >::digits
|
||||||
|
#endif
|
||||||
|
#if UINT_MAX > USHRT_MAX
|
||||||
|
, std::numeric_limits< unsigned int >::digits
|
||||||
|
#endif
|
||||||
|
#if ULONG_MAX > UINT_MAX
|
||||||
|
, std::numeric_limits< unsigned long >::digits
|
||||||
|
#endif
|
||||||
|
#if BOOST_HAS_XINT && (BOOST_UXINT_MAX > ULONG_MAX)
|
||||||
|
, std::numeric_limits< boost::detail::uxint_t >::digits
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
std::size_t const integral_type_count = sizeof(integral_bit_lengths) /
|
||||||
|
sizeof(integral_bit_lengths[0]);
|
||||||
|
|
||||||
|
// "Template-typedefs" to reduce two-argument templates to single-argument.
|
||||||
|
// This way, all the MPL-compatible templates have the same form, for below.
|
||||||
|
template < int Bits >
|
||||||
|
struct signed_sized_integral : boost::sized_integral<Bits, signed> {};
|
||||||
|
|
||||||
|
template < int Bits >
|
||||||
|
struct unsigned_sized_integral : boost::sized_integral<Bits, unsigned> {};
|
||||||
|
|
||||||
|
template < int Bits >
|
||||||
|
struct signed_exact_integral : boost::exact_integral<Bits, signed> {};
|
||||||
|
|
||||||
|
template < int Bits >
|
||||||
|
struct unsigned_exact_integral : boost::exact_integral<Bits, unsigned> {};
|
||||||
|
|
||||||
|
// Use SFINAE to check if a particular parameter is supported
|
||||||
|
#ifndef BOOST_NO_SFINAE
|
||||||
|
template < typename ValueT, template<ValueT> class Tmpl, ValueT Value >
|
||||||
|
bool
|
||||||
|
print_out_template( Tmpl<Value> const &, ValueT setting, char const
|
||||||
|
*template_pre_name, char const *template_post_name, typename Tmpl<Value>::type
|
||||||
|
*unused = 0 )
|
||||||
|
{
|
||||||
|
// Too bad the type-id expression couldn't use the compact form "*unused",
|
||||||
|
// but type-ids of dereferenced null pointers throw by order of C++ 2003,
|
||||||
|
// sect. 5.2.8, para. 2 (although the result is not conceptually needed).
|
||||||
|
PRIVATE_SHOW_MESSAGE( "This is " << template_pre_name << setting
|
||||||
|
<< template_post_name << " specialization, with type '" << typeid(typename
|
||||||
|
Tmpl<Value>::type).name() << "'." );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template < typename ValueT, typename T >
|
||||||
|
bool
|
||||||
|
print_out_template( T const &, ValueT setting, char const *template_pre_name,
|
||||||
|
char const *template_post_name )
|
||||||
|
{
|
||||||
|
PRIVATE_SHOW_MESSAGE( "Looking for " << template_pre_name << setting
|
||||||
|
<< template_post_name << " specialization? It doesn't exist." );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#error "These tests cannot work without Substitution-Failure-Is-Not-An-Error"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Get the extreme values for each integral type
|
||||||
|
template < typename T >
|
||||||
|
struct minimum_of
|
||||||
|
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_min >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
struct maximum_of
|
||||||
|
: boost::mpl::integral_c< T, boost::integer_traits<T>::const_max >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
|
|
||||||
|
// Check the processor-optimzed type system
|
||||||
|
BOOST_AUTO_TEST_SUITE( optimized_type_tests )
|
||||||
|
|
||||||
|
// Check the optimzed type override of a given type
|
||||||
|
BOOST_AUTO_TEST_CASE( fast_type_test )
|
||||||
|
{
|
||||||
|
typedef short least_type;
|
||||||
|
typedef boost::int_fast_t<least_type>::fast fast_type;
|
||||||
|
typedef std::numeric_limits<least_type> least_limits;
|
||||||
|
typedef std::numeric_limits<fast_type> fast_limits;
|
||||||
|
|
||||||
|
typedef boost::fast_integral<least_type>::type real_fast_type;
|
||||||
|
|
||||||
|
BOOST_MPL_ASSERT_RELATION( (boost::is_same<least_type, fast_type>::value),
|
||||||
|
==, false );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( (boost::is_same<fast_type,
|
||||||
|
real_fast_type>::value), ==, true );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( fast_limits::is_specialized, ==, true );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( fast_limits::is_signed &&
|
||||||
|
fast_limits::is_bounded, ==, true );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( fast_limits::radix, ==, 2 );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( fast_limits::digits, >=, least_limits::digits );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
// Check if given types can support given size parameters
|
||||||
|
BOOST_AUTO_TEST_SUITE( show_type_tests )
|
||||||
|
|
||||||
|
// Check the specialization type status of given bit lengths, minimum
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_lengths_test, T, bits_list )
|
||||||
|
{
|
||||||
|
BOOST_CHECK_EQUAL( print_out_template(signed_sized_integral<T::value>(),
|
||||||
|
T::value, "a sized_integral<", ", signed>"), T::value && (T::value <=
|
||||||
|
intmax_bits) );
|
||||||
|
BOOST_CHECK_EQUAL( print_out_template(unsigned_sized_integral<T::value>(),
|
||||||
|
T::value, "a sized_integral<", ", unsigned>"), T::value <= uintmax_bits );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the classic specialization type status of given bit lengths, minimum,
|
||||||
|
// unsigned
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_unsigned_test, T,
|
||||||
|
valid_bits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following printouts given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Template, Type
|
||||||
|
// for N := 32 downto 0
|
||||||
|
// cout << "Type '" << Template << "<" N << ">::" << Type << "' is '"
|
||||||
|
// << typeid(Template<N>::Type).name << ".'\n"
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Template = {int_t, uint_t}; Type = {least, fast}
|
||||||
|
// But now we'll use template meta-programming instead of macros. The limit
|
||||||
|
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||||
|
// have to take selected values. The only interesting part is if the bit
|
||||||
|
// count is too large, and we can't check that yet.
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::uint_t<T::value>::least>::digits, >=, T::value );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::uint_t<T::value>::fast>::digits, >=, T::value );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the classic specialization type status of given bit lengths, minimum,
|
||||||
|
// signed
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_lengths_signed_test, T,
|
||||||
|
valid_to_decrease_bits_list )
|
||||||
|
{
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::int_t<T::value>::least>::digits, >=, T::value - 1 );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::int_t<T::value>::fast>::digits, >=, T::value - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check size comparisons of given value support, unsigned
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_unsigned_values_test, T,
|
||||||
|
valid_to_increase_ubits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following printouts given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Type
|
||||||
|
// for N := 30 downto 0
|
||||||
|
// cout << "Type '" << uint_value_t << "<" (1ul << N) << ">::" << Type
|
||||||
|
// << "' is '"<< typeid(uint_value_t<(1ul << N)>::Type).name << ".'\n"
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Type = {least, fast}
|
||||||
|
// But now we'll use template meta-programming instead of macros. The limit
|
||||||
|
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||||
|
// have to take selected values. The interesting parts are where N is the
|
||||||
|
// length of a integral type, so 1 << N would have to fit in the next larger
|
||||||
|
// type. (This is why N can't be more than bitlength(uintmax_t) - 1.)
|
||||||
|
boost::uintmax_t const one = 1u;
|
||||||
|
|
||||||
|
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_unsigned_integral<(one
|
||||||
|
<< T::value)>, unsigned_sized_integral<T::value + 1> >) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check size comparisons of given value support, signed
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_shifted_signed_values_test, T,
|
||||||
|
valid_to_increase_sbits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following printouts given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Type
|
||||||
|
// for N := 30 downto 0
|
||||||
|
// cout << "Type '" << int_max_value_t << "<" +(1ul << N) << ">::" <<
|
||||||
|
// Type << "' is '" << typeid(int_max_value_t<+(1ul << N)>::Type).name
|
||||||
|
// << ".'\n"
|
||||||
|
// cout << "Type '" << int_min_value_t << "<" -(1ul << N) << ">::" <<
|
||||||
|
// Type << "' is '" << typeid(int_min_value_t<-(1ul << N)>::Type).name
|
||||||
|
// << ".'\n"
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Type = {least, fast}
|
||||||
|
// But now we'll use template meta-programming instead of macros. The limit
|
||||||
|
// of type-lists is usually less than 32 (not to mention 64) elements, so we
|
||||||
|
// have to take selected values. The interesting parts are where N is the
|
||||||
|
// length of a integral type, so 1 << N would have to fit in the next larger
|
||||||
|
// type. (This is why N can't be more than bitlength(intmax_t) - 1. Note
|
||||||
|
// that bitlength(intmax_t) + 1 == bitlength(uintmax_t).)
|
||||||
|
static boost::intmax_t const one = 1;
|
||||||
|
|
||||||
|
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::maximum_signed_integral<+(one
|
||||||
|
<< T::value)>, signed_sized_integral<T::value + 1> >) );
|
||||||
|
BOOST_MPL_ASSERT( (boost::mpl::equal< boost::minimum_signed_integral<-(one
|
||||||
|
<< T::value)>, signed_sized_integral<T::value + 1> >) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the specialization type status of given bit lengths, exact only
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_exact_lengths_test, T, bits_list )
|
||||||
|
{
|
||||||
|
bool const is_exact_length = std::binary_search( integral_bit_lengths,
|
||||||
|
integral_bit_lengths + integral_type_count, T::value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( print_out_template(signed_exact_integral<T::value>(),
|
||||||
|
T::value, "an exact_integral<", ", signed>"), is_exact_length );
|
||||||
|
BOOST_CHECK_EQUAL( print_out_template(unsigned_exact_integral<T::value>(),
|
||||||
|
T::value, "an exact_integral<", ", unsigned>"), is_exact_length );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the classic specialization type status of given bit lengths, exact only
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( show_types_for_classic_exact_lengths_test, T,
|
||||||
|
distinct_integral_bit_counts )
|
||||||
|
{
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::int_exact_t<T::value>::exact>::digits, ==, T::value - 1 );
|
||||||
|
BOOST_MPL_ASSERT_RELATION( std::numeric_limits<typename
|
||||||
|
boost::uint_exact_t<T::value>::exact>::digits, ==, T::value );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if MPL-compatible templates give bad returns for out-of-range values
|
||||||
|
BOOST_AUTO_TEST_CASE( show_not_type_for_parameter_test )
|
||||||
|
{
|
||||||
|
typedef signed_sized_integral< 3> ssz3_type;
|
||||||
|
typedef signed_sized_integral< 0> ssz0_type;
|
||||||
|
typedef signed_sized_integral<-3> ssz3n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(ssz3_type(), ssz3_type::bit_count,
|
||||||
|
"a sized_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ssz0_type(), ssz0_type::bit_count,
|
||||||
|
"a sized_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ssz3n_type(), ssz3n_type::bit_count,
|
||||||
|
"a sized_integral<", ", signed>") );
|
||||||
|
|
||||||
|
typedef unsigned_sized_integral< 3> usz3_type;
|
||||||
|
typedef unsigned_sized_integral< 0> usz0_type;
|
||||||
|
typedef unsigned_sized_integral<-3> usz3n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(usz3_type(), usz3_type::bit_count,
|
||||||
|
"a sized_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( print_out_template(usz0_type(), usz0_type::bit_count,
|
||||||
|
"a sized_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( !print_out_template(usz3n_type(), usz3n_type::bit_count,
|
||||||
|
"a sized_integral<", ", unsigned>") );
|
||||||
|
|
||||||
|
typedef signed_exact_integral< CHAR_BIT > se8_type;
|
||||||
|
typedef signed_exact_integral< 3> se3_type;
|
||||||
|
typedef signed_exact_integral< 0> se0_type;
|
||||||
|
typedef signed_exact_integral<-3> se3n_type;
|
||||||
|
typedef signed_exact_integral< - CHAR_BIT > se8n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(se8_type(), se8_type::bit_count,
|
||||||
|
"an exact_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(se3_type(), se3_type::bit_count,
|
||||||
|
"an exact_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(se0_type(), se0_type::bit_count,
|
||||||
|
"an exact_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(se3n_type(), se3n_type::bit_count,
|
||||||
|
"an exact_integral<", ", signed>") );
|
||||||
|
BOOST_CHECK( !print_out_template(se8n_type(), se8n_type::bit_count,
|
||||||
|
"an exact_integral<", ", signed>") );
|
||||||
|
|
||||||
|
typedef unsigned_exact_integral< CHAR_BIT > ue8_type;
|
||||||
|
typedef unsigned_exact_integral< 3> ue3_type;
|
||||||
|
typedef unsigned_exact_integral< 0> ue0_type;
|
||||||
|
typedef unsigned_exact_integral<-3> ue3n_type;
|
||||||
|
typedef unsigned_exact_integral< - CHAR_BIT > ue8n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(ue8_type(), ue8_type::bit_count,
|
||||||
|
"an exact_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ue3_type(), ue3_type::bit_count,
|
||||||
|
"an exact_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ue0_type(), ue0_type::bit_count,
|
||||||
|
"an exact_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ue3n_type(), ue3n_type::bit_count,
|
||||||
|
"an exact_integral<", ", unsigned>") );
|
||||||
|
BOOST_CHECK( !print_out_template(ue8n_type(), ue8n_type::bit_count,
|
||||||
|
"an exact_integral<", ", unsigned>") );
|
||||||
|
|
||||||
|
typedef boost::maximum_signed_integral< 15> max15_type;
|
||||||
|
typedef boost::maximum_signed_integral< 0> max0_type;
|
||||||
|
typedef boost::maximum_signed_integral<-15> max15n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(max15_type(), max15_type::bound,
|
||||||
|
"a maximum_signed_integral<", ">") );
|
||||||
|
BOOST_CHECK( !print_out_template(max0_type(), max0_type::bound,
|
||||||
|
"a maximum_signed_integral<", ">") );
|
||||||
|
BOOST_CHECK( !print_out_template(max15n_type(), max15n_type::bound,
|
||||||
|
"a maximum_signed_integral<", ">") );
|
||||||
|
|
||||||
|
typedef boost::minimum_signed_integral< 15> min15_type;
|
||||||
|
typedef boost::minimum_signed_integral< 0> min0_type;
|
||||||
|
typedef boost::minimum_signed_integral<-15> min15n_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( !print_out_template(min15_type(), min15_type::bound,
|
||||||
|
"a minimum_signed_integral<", ">") );
|
||||||
|
BOOST_CHECK( !print_out_template(min0_type(), min0_type::bound,
|
||||||
|
"a minimum_signed_integral<", ">") );
|
||||||
|
BOOST_CHECK( print_out_template(min15n_type(), min15n_type::bound,
|
||||||
|
"a minimum_signed_integral<", ">") );
|
||||||
|
|
||||||
|
typedef boost::maximum_unsigned_integral<15> umax15_type;
|
||||||
|
typedef boost::maximum_unsigned_integral< 0> umax0_type;
|
||||||
|
|
||||||
|
BOOST_CHECK( print_out_template(umax15_type(), umax15_type::bound,
|
||||||
|
"a maximum_unsigned_integral<", ">") );
|
||||||
|
BOOST_CHECK( print_out_template(umax0_type(), umax0_type::bound,
|
||||||
|
"a maximum_unsigned_integral<", ">") );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
// Check if given constants can fit in given types
|
||||||
|
BOOST_AUTO_TEST_SUITE( fit_type_tests )
|
||||||
|
|
||||||
|
// Check if large value can fit its minimum required size, by size
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_masked_values_test, T,
|
||||||
|
valid_to_decrease_bits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following checks given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Template, Type
|
||||||
|
// for ( N = 32, V = Template:Max ; N >= 0 ; --N, V >>= 1 )
|
||||||
|
// Confirm( static_cast<typename Template<N>::Type>(V) == V );
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Template = {int_t, uint_t}; Type = {least, fast};
|
||||||
|
// Template:Max = { intmax_t.Max for int_t, uintmax_t.Max for uint_t }
|
||||||
|
// In other words, the selected type doesn't mask out any bits it's not
|
||||||
|
// supposed to. But now we'll use template meta-programming instead of
|
||||||
|
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||||
|
// 64) elements, so we have to take selected values.
|
||||||
|
static int const count = T::value;
|
||||||
|
int const shift = uintmax_bits - count;
|
||||||
|
boost::uintmax_t const value_u = uintmax_limits::max
|
||||||
|
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
|
||||||
|
boost::intmax_t const value_s = intmax_limits::max
|
||||||
|
BOOST_PREVENT_MACRO_SUBSTITUTION () >> shift;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
unsigned_sized_integral<count>::type>(value_u), value_u );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::uint_t<count>::least>(value_u), value_u );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::uint_t<count>::fast>(value_u), value_u );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
signed_sized_integral<count>::type>(value_s), value_s );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_t<count>::least>(value_s), value_s );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_t<count>::fast>(value_s), value_s );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a large value can only fit of its exact bit length
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_exact_lengths_test, T,
|
||||||
|
distinct_integral_bit_counts )
|
||||||
|
{
|
||||||
|
typename boost::exact_integral<T::value, unsigned>::type const one_u( 1u ),
|
||||||
|
high_bit_u( one_u << (T::value - 1) ), repeated_bits_u( (high_bit_u << 1) |
|
||||||
|
high_bit_u );
|
||||||
|
|
||||||
|
BOOST_CHECK( high_bit_u );
|
||||||
|
BOOST_CHECK_EQUAL( repeated_bits_u, high_bit_u );
|
||||||
|
|
||||||
|
typename boost::exact_integral<T::value, signed>::type const one_s( 1 ),
|
||||||
|
high_bit_s( one_s << (T::value - 2) ), repeated_bits_s( (high_bit_s << 1) |
|
||||||
|
high_bit_s ), repeated_2bits_s( (repeated_bits_s << 1) | high_bit_s );
|
||||||
|
|
||||||
|
BOOST_CHECK( high_bit_s > 0 );
|
||||||
|
BOOST_CHECK( repeated_bits_s < 0 );
|
||||||
|
BOOST_CHECK_EQUAL( repeated_bits_s, repeated_2bits_s );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if large value can fit its minimum required size, by value, unsigned
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_unsigned_values_test, T,
|
||||||
|
valid_to_increase_ubits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following checks given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Template, Type
|
||||||
|
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
|
||||||
|
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Template = {uint_value_t}; Type = {least, fast}; Template:Extreme =
|
||||||
|
// {uintmax_t.Max for uint_value_t}
|
||||||
|
// In other words, the selected type doesn't mask out any bits it's not
|
||||||
|
// supposed to. But now we'll use template meta-programming instead of
|
||||||
|
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||||
|
// 64) elements, so we have to take selected values.
|
||||||
|
using boost::uintmax_t;
|
||||||
|
|
||||||
|
typedef boost::mpl::shift_right<maximum_of<uintmax_t>, T> maxi_type;
|
||||||
|
|
||||||
|
uintmax_t const maxi = maxi_type::value;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::uint_value_t<maxi_type::value>::least>(maxi), maxi );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::uint_value_t<maxi_type::value>::fast>(maxi), maxi );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if large value can fit its minimum required size, by value, signed
|
||||||
|
BOOST_AUTO_TEST_CASE_TEMPLATE( fit_for_shifted_signed_values_test, T,
|
||||||
|
valid_to_increase_sbits_list )
|
||||||
|
{
|
||||||
|
// This test is supposed to replace the following checks given in
|
||||||
|
// puesdo-code by:
|
||||||
|
// Routine: Template, Type
|
||||||
|
// for ( N = 0, V = Template:Extreme ; N < 32 ; ++N, V >>= 1 )
|
||||||
|
// Confirm( static_cast<typename Template<V>::Type>(V) == V );
|
||||||
|
// end for
|
||||||
|
// end Routine
|
||||||
|
// with Template = {int_max_value_t, int_min_value_t}; Type = {least, fast};
|
||||||
|
// Template:Extreme = {intmax_t.Min for int_min_value_t, intmax_t.Max
|
||||||
|
// for int_max_value_t}
|
||||||
|
// In other words, the selected type doesn't mask out any bits it's not
|
||||||
|
// supposed to. But now we'll use template meta-programming instead of
|
||||||
|
// macros. The limit of type-lists is usually less than 32 (not to mention
|
||||||
|
// 64) elements, so we have to take selected values.
|
||||||
|
using boost::intmax_t;
|
||||||
|
|
||||||
|
typedef boost::mpl::shift_right<minimum_of<intmax_t>, T> mini_type;
|
||||||
|
typedef boost::mpl::shift_right<maximum_of<intmax_t>, T> maxi_type;
|
||||||
|
|
||||||
|
intmax_t const maxi = maxi_type::value, mini = mini_type::value;
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_max_value_t<maxi_type::value>::least>(maxi), maxi );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_max_value_t<maxi_type::value>::fast>(maxi), maxi );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_min_value_t<mini_type::value>::least>(mini), mini );
|
||||||
|
BOOST_CHECK_EQUAL( static_cast<typename
|
||||||
|
boost::int_min_value_t<mini_type::value>::fast>(mini), mini );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
// Verification of bugs and their fixes
|
||||||
|
BOOST_AUTO_TEST_SUITE( bug_fix_tests )
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
102
test/integer_traits_test.cpp
Normal file
102
test/integer_traits_test.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* boost integer_traits.hpp tests
|
||||||
|
*
|
||||||
|
* Copyright Jens Maurer 2000
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See
|
||||||
|
* accompanying file LICENSE_1_0.txt or copy at
|
||||||
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* Revision history
|
||||||
|
* 2000-02-22 Small improvements by Beman Dawes
|
||||||
|
* 2000-06-27 Rework for better MSVC and BCC co-operation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <boost/integer_traits.hpp>
|
||||||
|
// use int64_t instead of long long for better portability
|
||||||
|
#include <boost/cstdint.hpp>
|
||||||
|
|
||||||
|
#define BOOST_INCLUDE_MAIN
|
||||||
|
#include <boost/test/test_tools.hpp>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* General portability note:
|
||||||
|
* MSVC mis-compiles explicit function template instantiations.
|
||||||
|
* For example, f<A>() and f<B>() are both compiled to call f<A>().
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
|
||||||
|
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
|
||||||
|
namespace fix{
|
||||||
|
inline int make_char_numeric_for_streaming(char c) { return c; }
|
||||||
|
inline int make_char_numeric_for_streaming(signed char c) { return c; }
|
||||||
|
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
|
||||||
|
}
|
||||||
|
using namespace fix;
|
||||||
|
#else
|
||||||
|
template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
|
||||||
|
inline int make_char_numeric_for_streaming(char c) { return c; }
|
||||||
|
inline int make_char_numeric_for_streaming(signed char c) { return c; }
|
||||||
|
inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void runtest(const char * type, T)
|
||||||
|
{
|
||||||
|
typedef boost::integer_traits<T> traits;
|
||||||
|
std::cout << "Checking " << type
|
||||||
|
<< "; min is " << make_char_numeric_for_streaming((traits::min)())
|
||||||
|
<< ", max is " << make_char_numeric_for_streaming((traits::max)())
|
||||||
|
<< std::endl;
|
||||||
|
BOOST_CHECK(traits::is_specialized);
|
||||||
|
#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
|
||||||
|
// MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
|
||||||
|
// generates different symbol names with a very long common prefix:
|
||||||
|
// the dummy "&& true" disambiguates between the symbols generated by this
|
||||||
|
// BOOST_CHECK instantiation and the preceding one.
|
||||||
|
BOOST_CHECK(traits::is_integer && true);
|
||||||
|
#else
|
||||||
|
BOOST_CHECK(traits::is_integer);
|
||||||
|
#endif
|
||||||
|
BOOST_CHECK(traits::is_integral == true);
|
||||||
|
BOOST_CHECK(traits::const_min == (traits::min)());
|
||||||
|
BOOST_CHECK(traits::const_max == (traits::max)());
|
||||||
|
}
|
||||||
|
|
||||||
|
int test_main(int, char*[])
|
||||||
|
{
|
||||||
|
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("wchar_t", wchar_t());
|
||||||
|
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());
|
||||||
|
#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
|
||||||
|
//
|
||||||
|
// MS/Borland compilers can't support 64-bit member constants
|
||||||
|
// BeOS doesn't have specialisations for long long in SGI's <limits> header.
|
||||||
|
runtest("int64_t (possibly long long)", boost::int64_t());
|
||||||
|
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
|
||||||
|
#else
|
||||||
|
std::cout << "Skipped int64_t and uint64_t" << std::endl;
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
33
test/issue_2134.cpp
Normal file
33
test/issue_2134.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// boost Issue #2134 test program ------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright Daryle Walker 2008. Distributed under the Boost
|
||||||
|
// Software License, Version 1.0. (See the accompanying file
|
||||||
|
// LICENSE_1_0.txt or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
|
||||||
|
|
||||||
|
// See <http://www.boost.org/libs/integer> for documentation.
|
||||||
|
// See <http://svn.boost.org/trac/boost/ticket/2134> for the issue involved.
|
||||||
|
|
||||||
|
// Revision History
|
||||||
|
// 23 Jul 2008 Initial version
|
||||||
|
|
||||||
|
// Control if the inclusion error is triggered
|
||||||
|
#ifndef CONTROL_INCLUDE_TRAITS
|
||||||
|
#define CONTROL_INCLUDE_TRAITS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONTROL_INCLUDE_TRAITS
|
||||||
|
// This file defines boost::detail::integer_traits.
|
||||||
|
#include <boost/detail/numeric_traits.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// This is the file with the issue. It has items within the boost::detail
|
||||||
|
// namespace that referenced an unadorned "integer_traits". This was meant to
|
||||||
|
// refer to boost::integer_traits. However, <boost/detail/numeric_traits.hpp>
|
||||||
|
// defines a boost::detail::integer_traits. If that header is #included before
|
||||||
|
// this one, then b.d.integer_traits (rightfully) took priority, which lead to a
|
||||||
|
// syntax error.
|
||||||
|
#include <boost/integer.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
// Main program, minimal (since this is a compile test)
|
||||||
|
int main() { return 0; }
|
@ -1,10 +1,9 @@
|
|||||||
// Boost static_log2.hpp test program --------------------------------------//
|
// Boost static_log2.hpp test program --------------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001.
|
||||||
// and distribute this software is granted provided this copyright
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
@ -21,7 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
// Macros to compact code
|
// Macros to compact code
|
||||||
#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e )
|
#define PRIVATE_LB_TEST( v, e ) BOOST_CHECK( ::boost::static_log2<v>::value == e )
|
||||||
|
|
||||||
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
|
#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \
|
||||||
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
|
<< "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
// Boost static_min_max.hpp test program -----------------------------------//
|
// Boost static_min_max.hpp test program -----------------------------------//
|
||||||
|
|
||||||
// (C) Copyright Daryle Walker 2001. Permission to copy, use, modify, sell
|
// (C) Copyright Daryle Walker 2001.
|
||||||
// and distribute this software is granted provided this copyright
|
// Distributed under the Boost Software License, Version 1.0. (See
|
||||||
// notice appears in all copies. This software is provided "as is" without
|
// accompanying file LICENSE_1_0.txt or copy at
|
||||||
// express or implied warranty, and with no claim as to its suitability for
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// any purpose.
|
|
||||||
|
|
||||||
// See http://www.boost.org for most recent version including documentation.
|
// See http://www.boost.org for most recent version including documentation.
|
||||||
|
|
||||||
@ -12,7 +11,7 @@
|
|||||||
// 23 Sep 2001 Initial version (Daryle Walker)
|
// 23 Sep 2001 Initial version (Daryle Walker)
|
||||||
|
|
||||||
#define BOOST_INCLUDE_MAIN
|
#define BOOST_INCLUDE_MAIN
|
||||||
#include <boost/test/test_tools.hpp> // for main, BOOST_TEST
|
#include <boost/test/test_tools.hpp> // for main, BOOST_CHECK
|
||||||
|
|
||||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||||
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
|
#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc.
|
||||||
@ -38,57 +37,57 @@ test_main
|
|||||||
// Two positives
|
// Two positives
|
||||||
cout << "Doing tests with two positive values." << endl;
|
cout << "Doing tests with two positive values." << endl;
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 );
|
BOOST_CHECK( (static_signed_min< 9, 14>::value) == 9 );
|
||||||
BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 );
|
BOOST_CHECK( (static_signed_max< 9, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_signed_min<14, 9>::value) == 9 );
|
BOOST_CHECK( (static_signed_min<14, 9>::value) == 9 );
|
||||||
BOOST_TEST( (static_signed_max<14, 9>::value) == 14 );
|
BOOST_CHECK( (static_signed_max<14, 9>::value) == 14 );
|
||||||
|
|
||||||
BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 );
|
BOOST_CHECK( (static_unsigned_min< 9, 14>::value) == 9 );
|
||||||
BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_max< 9, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 );
|
BOOST_CHECK( (static_unsigned_min<14, 9>::value) == 9 );
|
||||||
BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_max<14, 9>::value) == 14 );
|
||||||
|
|
||||||
// Two negatives
|
// Two negatives
|
||||||
cout << "Doing tests with two negative values." << endl;
|
cout << "Doing tests with two negative values." << endl;
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 );
|
BOOST_CHECK( (static_signed_min< -8, -101>::value) == -101 );
|
||||||
BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 );
|
BOOST_CHECK( (static_signed_max< -8, -101>::value) == -8 );
|
||||||
BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 );
|
BOOST_CHECK( (static_signed_min<-101, -8>::value) == -101 );
|
||||||
BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 );
|
BOOST_CHECK( (static_signed_max<-101, -8>::value) == -8 );
|
||||||
|
|
||||||
// With zero
|
// With zero
|
||||||
cout << "Doing tests with zero and a positive or negative value." << endl;
|
cout << "Doing tests with zero and a positive or negative value." << endl;
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 );
|
BOOST_CHECK( (static_signed_min< 0, 14>::value) == 0 );
|
||||||
BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 );
|
BOOST_CHECK( (static_signed_max< 0, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_signed_min<14, 0>::value) == 0 );
|
BOOST_CHECK( (static_signed_min<14, 0>::value) == 0 );
|
||||||
BOOST_TEST( (static_signed_max<14, 0>::value) == 14 );
|
BOOST_CHECK( (static_signed_max<14, 0>::value) == 14 );
|
||||||
|
|
||||||
BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 );
|
BOOST_CHECK( (static_unsigned_min< 0, 14>::value) == 0 );
|
||||||
BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_max< 0, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 );
|
BOOST_CHECK( (static_unsigned_min<14, 0>::value) == 0 );
|
||||||
BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_max<14, 0>::value) == 14 );
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 );
|
BOOST_CHECK( (static_signed_min< 0, -101>::value) == -101 );
|
||||||
BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 );
|
BOOST_CHECK( (static_signed_max< 0, -101>::value) == 0 );
|
||||||
BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 );
|
BOOST_CHECK( (static_signed_min<-101, 0>::value) == -101 );
|
||||||
BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 );
|
BOOST_CHECK( (static_signed_max<-101, 0>::value) == 0 );
|
||||||
|
|
||||||
// With identical
|
// With identical
|
||||||
cout << "Doing tests with two identical values." << endl;
|
cout << "Doing tests with two identical values." << endl;
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min<0, 0>::value) == 0 );
|
BOOST_CHECK( (static_signed_min<0, 0>::value) == 0 );
|
||||||
BOOST_TEST( (static_signed_max<0, 0>::value) == 0 );
|
BOOST_CHECK( (static_signed_max<0, 0>::value) == 0 );
|
||||||
BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 );
|
BOOST_CHECK( (static_unsigned_min<0, 0>::value) == 0 );
|
||||||
BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 );
|
BOOST_CHECK( (static_unsigned_max<0, 0>::value) == 0 );
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min<14, 14>::value) == 14 );
|
BOOST_CHECK( (static_signed_min<14, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_signed_max<14, 14>::value) == 14 );
|
BOOST_CHECK( (static_signed_max<14, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_min<14, 14>::value) == 14 );
|
||||||
BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 );
|
BOOST_CHECK( (static_unsigned_max<14, 14>::value) == 14 );
|
||||||
|
|
||||||
BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 );
|
BOOST_CHECK( (static_signed_min< -101, -101>::value) == -101 );
|
||||||
BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 );
|
BOOST_CHECK( (static_signed_max< -101, -101>::value) == -101 );
|
||||||
|
|
||||||
return boost::exit_success;
|
return boost::exit_success;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user