Compare commits

..

80 Commits

Author SHA1 Message Date
8f3aea2200 Merge array bug fixes to master 2017-01-31 08:00:48 -08:00
cef221d8b4 Merge pull request #5 from Lastique/patch-1
Fix compilation for Oracle Studio 12.5
2017-01-23 20:00:25 -08:00
5d06f1074a Fix compilation for Oracle Studio 12.5
The compiler expects a qualified dependent name after `typename`, so move `const` after the name.
2017-01-24 02:31:27 +04:00
4c27456a43 Copy doc jamfile from develop
It's need to build the documentation now.
2016-10-27 20:12:38 +01:00
16824fe0f1 Add, and update, documentation build targets. 2016-10-07 23:03:40 -05:00
0d4fa276f4 Merge pull request #3 from boostorg/pull_request/remove_hash_fwd
Replace inclusion of hash_fwd.hpp with a declaration of hash_range. Patch from Peter Dimov.
2015-01-08 14:10:08 -08:00
cb4df41bd6 Replace inclusion of hash_fwd.hpp with a declaration of hash_range 2015-01-09 00:01:41 +02:00
cd9888316a Merge pull request #2 from danieljames/metadata
Create metadata file.
2014-08-18 09:16:48 -07:00
ce71078681 Add metadata file. 2014-08-18 14:57:18 +01:00
9678f6aa3b Create merge base for git. 2014-04-06 13:53:46 +01:00
c0b1609ddb Merge r86524 (Correct broken links to C++ standard papers); fixes #9212
[SVN r86673]
2013-11-13 03:22:55 +00:00
dfeb6bd0a5 Correct broken links to C++ standard papers. Refs #9212.
[SVN r86524]
2013-10-30 12:51:24 +00:00
1966dd034b Updated license and copyright
[SVN r86311]
2013-10-14 21:35:20 +00:00
40c5dae84c Remove tabs
[SVN r86310]
2013-10-14 21:31:19 +00:00
4584f63f01 Simplify multi-component ifdefs containing BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
[SVN r86248]
2013-10-11 23:20:59 +00:00
2e0052d49f Remove BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Process #ifndef...#endif conditions.

[SVN r86244]
2013-10-11 23:15:00 +00:00
6ad6249e1c Array: Remove obsolete MSVC version check.
[SVN r85903]
2013-09-25 13:51:37 +00:00
a73b6fb582 Merged boost::algorithm::gather and updated tests for Utility, Algorithm and Utility libraries
[SVN r83154]
2013-02-25 18:43:26 +00:00
12fcbb59c2 Back out some of the constexpr support Boost.Array; it crashes gcc
[SVN r82906]
2013-02-15 17:11:09 +00:00
4a60b8c146 Add constexpr support to Boost.Array
[SVN r82834]
2013-02-12 18:07:15 +00:00
117584a2ce Update Boost.Array tests to use newer Boost.Test features
[SVN r82822]
2013-02-11 17:16:55 +00:00
97a26a1599 Documented boost::get support in Boost.Array
[SVN r82105]
2012-12-19 20:32:34 +00:00
88abb34b4d Fix bug where failure test failed for the wrong reason on C++03
[SVN r82102]
2012-12-19 17:49:04 +00:00
e02e7dcc00 Add boost::get<> support to Boost.Array
[SVN r82089]
2012-12-19 00:53:31 +00:00
daeb19f693 Add support for std::get<> to Boost.Array
[SVN r82083]
2012-12-18 17:59:08 +00:00
ba1a2437cf Merge doc changes to release; fixes #6988
[SVN r78948]
2012-06-14 16:01:03 +00:00
f41b1d2d4c Added a note about std::array in C++11
[SVN r78947]
2012-06-14 15:52:44 +00:00
3db6930a22 Added support Boost.Hash; checked in a test yesterday, but forgot to merge the actual code
[SVN r78581]
2012-05-24 13:04:02 +00:00
859fb5aa97 Merged changes for Boost.Array to release; adds support for Boost.Hash
[SVN r78558]
2012-05-23 16:35:13 +00:00
f4a0cbd364 Added support for Boost.Hash to Boost.Array; fixes #6791
[SVN r77976]
2012-04-14 18:07:34 +00:00
992299f2bf Use BOOST_ASSERT_MSG instead of naked BOOST_ASSERT
[SVN r77135]
2012-02-28 18:47:28 +00:00
5a97de6f2e Merge changes in Boost.Array to release
[SVN r70698]
2011-03-29 14:49:32 +00:00
eea368fadf Merge changes in Boost.Array to release
[SVN r70697]
2011-03-29 14:47:50 +00:00
e6a44cf529 Removed tabs
[SVN r70442]
2011-03-22 23:55:20 +00:00
111e93aa4c qualify array to avoid conflict with std::array; Refs #5233
[SVN r69291]
2011-02-26 01:35:48 +00:00
5072c551ec Pathscale-4.0 configuration code/workarounds.
[SVN r68142]
2011-01-14 02:59:34 +00:00
26edbea113 Merging changes to release; fixes #4761
[SVN r68100]
2011-01-13 15:49:03 +00:00
97e912e82e Added crbegin and crend to Boost.Array; refs #4761. Will close ticket when merged to release branch
[SVN r67481]
2010-12-28 19:14:23 +00:00
05aa660128 Added cbegin and cend to Boost.Array; refs #4761. Will close ticket when merged to release branch
[SVN r67478]
2010-12-28 18:39:14 +00:00
9644ee6662 Merged array changes to release; fixes #4757
[SVN r67477]
2010-12-28 18:28:22 +00:00
7256882760 Fix? for borland
[SVN r66781]
2010-11-26 20:16:34 +00:00
5329bd6f1c Slight tweak of get_c_array
[SVN r66712]
2010-11-24 16:13:12 +00:00
80fa50df2e SunPro workaround; references #4757
[SVN r66651]
2010-11-20 00:48:33 +00:00
6fbc8ee741 Added a test for 'get_c_array'
[SVN r66294]
2010-10-31 02:25:04 +00:00
38217688e1 Fix elems for Sun compilers
[SVN r66154]
2010-10-23 19:11:16 +00:00
a603bffc48 Merged Array changes to release
[SVN r63410]
2010-06-28 17:59:21 +00:00
2595eda739 Removed tabs
[SVN r62803]
2010-06-11 14:46:31 +00:00
64e5394540 Added get_c_array to Boost.Array
[SVN r62487]
2010-06-06 16:05:13 +00:00
c37498364e Detab array.hpp
[SVN r61415]
2010-04-19 21:41:21 +00:00
0c8902e8c2 Merged array changes from trunk to release; Fixes #3893 and #3168
[SVN r60824]
2010-03-25 15:32:12 +00:00
5e81100035 Added support for SunCC and 'fill' operation; tickets #3893 and #3168 respectively
[SVN r60436]
2010-03-10 18:03:30 +00:00
79cadb97d7 Changed exception throwing to use boost::throw_exception
[SVN r60417]
2010-03-10 14:23:49 +00:00
9609395af0 Applied patches to fix #2886
[SVN r59476]
2010-02-04 18:22:13 +00:00
fb72e72640 MSVC warning suppression - fixes #3599.
[SVN r59439]
2010-02-03 12:10:56 +00:00
88868ba0df Merged array changes from trunk to release
[SVN r58921]
2010-01-12 05:55:52 +00:00
e875287d55 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
99631823f6 rm cmake from the release branch before it goes out broken. Policy dictates that you never commit to release, you commit to trunk and merge to release.
[SVN r56941]
2009-10-17 01:10:45 +00:00
100b5d687b Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
5661b8cd63 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
7fb9412ea8 removed warning on vc++ for using std::equal
[SVN r54541]
2009-06-30 20:04:45 +00:00
86b069ad0e Merge [53104] and [53105] from the trunk
[SVN r53198]
2009-05-23 06:00:42 +00:00
471bc9bf06 Supress warnings in array
[SVN r53105]
2009-05-19 03:00:53 +00:00
9cf5e0c9a1 Use boost::swap instead of std::swap_ranges to enable ADL. Fixes #2753.
[SVN r53104]
2009-05-19 02:37:04 +00:00
3d20bb1310 merge of cmake build files from trunk per beman
[SVN r50756]
2009-01-24 18:57:20 +00:00
e7122b3f20 merge tests and Jamfiles for 7 libraries
[SVN r50456]
2009-01-04 05:17:02 +00:00
d2910e195a Updating dependency information for modularized libraries.
[SVN r49628]
2008-11-07 17:05:27 +00:00
b3ace9fb6e Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
a6b531b5b1 Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
4dd2cf1b64 Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41370]
2007-11-25 18:38:02 +00:00
2e88dc228d Full merge from trunk at revision 41356 of entire boost-root tree.
[SVN r41369]
2007-11-25 18:07:19 +00:00
0a4d7e81ef Starting point for releases
[SVN r39706]
2007-10-05 14:25:06 +00:00
96d4c5f737 This commit was manufactured by cvs2svn to create tag
'Version_1_34_1'.

[SVN r38286]
2007-07-24 19:28:14 +00:00
5a23b06a83 Merged L & C issue fixes from trunk to branch.
[SVN r36225]
2006-12-01 11:34:43 +00:00
e85feee293 Merged copyright and license addition
[SVN r35907]
2006-11-07 19:27:00 +00:00
b6522b3f60 (merge from head)
http://www.josuttis.com/ hasn't the latest version any more


[SVN r34856]
2006-08-08 18:53:30 +00:00
3044ab376c Simplified code.
[SVN r34384]
2006-06-24 11:31:19 +00:00
69188c998f Fix compiler errors resulting from missing return values.
[SVN r34259]
2006-06-09 11:40:07 +00:00
4c5212f5e4 Remove size zero support for old compilers that do not support partial template specialization
[SVN r34162]
2006-06-04 12:10:17 +00:00
276cd991f3 Support for zero length arrays
[SVN r34156]
2006-06-03 13:04:27 +00:00
1f8298fb08 This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
15 changed files with 671 additions and 97 deletions

19
doc/Jamfile.v2 Normal file
View File

@ -0,0 +1,19 @@
#~ Copyright Marshall Clow 2013
#~ 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)
using boostbook ;
boostbook standalone
: array.xml
: <xsl:param>boost.root=../../../.. ;
###############################################################################
alias boostdoc
: array.xml
:
:
: ;
explicit boostdoc ;
alias boostrelease ;
explicit boostrelease ;

View File

@ -7,6 +7,10 @@
<firstname>Nicolai</firstname>
<surname>Josuttis</surname>
</author>
<maintainer>
<firstname>Marshall</firstname>
<surname>Clow</surname>
</maintainer>
<copyright>
<year>2001</year>
@ -16,6 +20,11 @@
<holder>Nicolai M. Josuttis</holder>
</copyright>
<copyright>
<year>2012</year>
<holder>Marshall Clow</holder>
</copyright>
<legalnotice>
<para>Distributed under the Boost Software License, Version 1.0.
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
@ -68,7 +77,12 @@
<para>Note that this class is suggested to be part of the next
Technical Report, which will extend the C++ Standard (see
<ulink url="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</ulink>).</para>
<ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</ulink>).</para>
<para>Update: <code>std::array</code> is (as of C++11) part of the C++ standard.
The differences between <code>boost::array</code> and <code>std::array</code> are minimal.
If you are using C++11, you should consider using <code>std::array</code> instead of <code>boost::array</code>.
</para>
<para>Class <code><classname>array</classname></code> fulfills most
but not all of the requirements of "reversible containers" (see
@ -171,6 +185,24 @@
<returns><simpara>iterator for position after the last element</simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</overloaded-method>
<overloaded-method name="cbegin" cv="const">
<signature>
<type>const_iterator</type>
</signature>
<returns><simpara>constant iterator for the first element</simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</overloaded-method>
<overloaded-method name="cend" cv="const">
<signature>
<type>const_iterator</type>
</signature>
<returns><simpara>constant iterator for position after the last element</simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</overloaded-method>
</method-group>
<method-group name="reverse iterator support">
@ -195,6 +227,24 @@
<returns><simpara>reverse iterator for position after the last element in reverse iteration</simpara></returns>
</overloaded-method>
<overloaded-method name="crbegin" cv="const">
<signature>
<type>const_reverse_iterator</type>
</signature>
<returns><simpara>constant reverse iterator for the first element of reverse iteration</simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</overloaded-method>
<overloaded-method name="crend" cv="const">
<signature>
<type>const_reverse_iterator</type>
</signature>
<returns><simpara>constant reverse iterator for position after the last element in reverse iteration</simpara></returns>
<throws><simpara>will not throw</simpara></throws>
</overloaded-method>
</method-group>
<method-group name="capacity">
@ -460,6 +510,49 @@
<returns><simpara><code>!(x &lt; y)</code></simpara></returns>
</function>
</free-function-group>
<free-function-group name="specializations">
<function name="boost::get">
<template>
<template-type-parameter name="T"/>
<template-nontype-parameter name="N">
<type>std::size_t</type>
</template-nontype-parameter>
<template-nontype-parameter name="Idx">
<type>std::size_t</type>
</template-nontype-parameter>
</template>
<type>T</type>
<parameter name="arr">
<paramtype><classname>array</classname>&lt;T, N&gt;&amp;</paramtype>
</parameter>
<returns><simpara>element of array with index <code>Idx</code></simpara></returns>
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
</function>
<function name="boost::get">
<template>
<template-type-parameter name="T"/>
<template-nontype-parameter name="N">
<type>std::size_t</type>
</template-nontype-parameter>
<template-nontype-parameter name="Idx">
<type>std::size_t</type>
</template-nontype-parameter>
</template>
<type>T</type>
<parameter name="arr">
<paramtype>const <classname>array</classname>&lt;T, N&gt;&amp;</paramtype>
</parameter>
<returns><simpara>const element of array with index <code>Idx</code></simpara></returns>
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
</function>
</free-function-group>
</class>
</namespace>
</header>

View File

@ -13,6 +13,13 @@
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* 9 Jan 2013 - (mtc) Added constexpr
* 14 Apr 2012 - (mtc) Added support for boost::hash
* 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility.
* 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group.
* See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
* Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow)
* 10 Mar 2010 - added workaround for SUNCC and !STLPort [trac #3893] (Marshall Clow)
* 29 Jan 2004 - c_array() added, BOOST_NO_PRIVATE_IN_AGGREGATE removed (Nico Josuttis)
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
* 05 Aug 2001 - minor update (Nico Josuttis)
@ -24,9 +31,20 @@
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(push)
# pragma warning(disable:4996) // 'std::equal': Function call with parameters that may be unsafe
# pragma warning(disable:4510) // boost::array<T,N>' : default constructor could not be generated
# pragma warning(disable:4610) // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required
#endif
#include <cstddef>
#include <stdexcept>
#include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/swap.hpp>
// Handles broken standard libraries better than <iterator>
#include <boost/detail/iterator.hpp>
@ -55,21 +73,23 @@ namespace boost {
typedef std::ptrdiff_t difference_type;
// iterator support
iterator begin() { return elems; }
const_iterator begin() const { return elems; }
iterator end() { return elems+N; }
const_iterator end() const { return elems+N; }
iterator begin() { return elems; }
const_iterator begin() const { return elems; }
const_iterator cbegin() const { return elems; }
iterator end() { return elems+N; }
const_iterator end() const { return elems+N; }
const_iterator cend() const { return elems+N; }
// reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
// workaround for broken reverse_iterator in VC7
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, iterator,
reference, iterator, reference> > reverse_iterator;
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
const_reference, iterator, reference> > const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
@ -80,27 +100,32 @@ namespace boost {
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const {
return const_reverse_iterator(begin());
}
// operator[]
reference operator[](size_type i)
{
BOOST_ASSERT( i < N && "out of range" );
return elems[i];
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
}
const_reference operator[](size_type i) const
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type i) const
{
BOOST_ASSERT( i < N && "out of range" );
return elems[i];
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
}
// at() with range check
reference at(size_type i) { rangecheck(i); return elems[i]; }
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
reference at(size_type i) { return rangecheck(i), elems[i]; }
/*BOOST_CONSTEXPR*/ const_reference at(size_type i) const { return rangecheck(i), elems[i]; }
// front() and back()
reference front()
@ -108,7 +133,7 @@ namespace boost {
return elems[0];
}
const_reference front() const
BOOST_CONSTEXPR const_reference front() const
{
return elems[0];
}
@ -118,20 +143,21 @@ namespace boost {
return elems[N-1];
}
const_reference back() const
BOOST_CONSTEXPR const_reference back() const
{
return elems[N-1];
}
// size is constant
static size_type size() { return N; }
static bool empty() { return false; }
static size_type max_size() { return N; }
static BOOST_CONSTEXPR size_type size() { return N; }
static BOOST_CONSTEXPR bool empty() { return false; }
static BOOST_CONSTEXPR size_type max_size() { return N; }
enum { static_size = N };
// swap (note: linear complexity)
void swap (array<T,N>& y) {
std::swap_ranges(begin(),end(),y.begin());
for (size_type i = 0; i < N; ++i)
boost::swap(elems[i],y.elems[i]);
}
// direct access to data (read-only)
@ -149,21 +175,19 @@ namespace boost {
}
// assign one value to all elements
void assign (const T& value)
void assign (const T& value) { fill ( value ); } // A synonym for fill
void fill (const T& value)
{
std::fill_n(begin(),size(),value);
}
// check range (may be private because it is static)
static void rangecheck (size_type i) {
if (i >= size()) {
throw std::out_of_range("array<>: index out of range");
}
static BOOST_CONSTEXPR bool rangecheck (size_type i) {
return i > size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
}
};
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template< class T >
class array< T, 0 > {
@ -178,21 +202,23 @@ namespace boost {
typedef std::ptrdiff_t difference_type;
// iterator support
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
iterator end() { return begin(); }
const_iterator end() const { return begin(); }
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
const_iterator cbegin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
iterator end() { return begin(); }
const_iterator end() const { return begin(); }
const_iterator cend() const { return cbegin(); }
// reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(_MSC_VER) && (_MSC_VER == 1300) && defined(BOOST_DINKUMWARE_STDLIB) && (BOOST_DINKUMWARE_STDLIB == 310)
// workaround for broken reverse_iterator in VC7
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, iterator,
reference, iterator, reference> > reverse_iterator;
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
const_reference, iterator, reference> > const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
@ -203,25 +229,32 @@ namespace boost {
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const {
return const_reverse_iterator(begin());
}
// operator[]
reference operator[](size_type i)
reference operator[](size_type /*i*/)
{
return failed_rangecheck();
}
const_reference operator[](size_type i) const
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type /*i*/) const
{
return failed_rangecheck();
}
// at() with range check
reference at(size_type i) { return failed_rangecheck(); }
const_reference at(size_type i) const { return failed_rangecheck(); }
reference at(size_type /*i*/) { return failed_rangecheck(); }
/*BOOST_CONSTEXPR*/ const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
// front() and back()
reference front()
@ -229,7 +262,7 @@ namespace boost {
return failed_rangecheck();
}
const_reference front() const
BOOST_CONSTEXPR const_reference front() const
{
return failed_rangecheck();
}
@ -239,18 +272,18 @@ namespace boost {
return failed_rangecheck();
}
const_reference back() const
BOOST_CONSTEXPR const_reference back() const
{
return failed_rangecheck();
}
// size is constant
static size_type size() { return 0; }
static bool empty() { return true; }
static size_type max_size() { return 0; }
static BOOST_CONSTEXPR size_type size() { return 0; }
static BOOST_CONSTEXPR bool empty() { return true; }
static BOOST_CONSTEXPR size_type max_size() { return 0; }
enum { static_size = 0 };
void swap (array<T,0>& y) {
void swap (array<T,0>& /*y*/) {
}
// direct access to data (read-only)
@ -267,12 +300,14 @@ namespace boost {
}
// assign one value to all elements
void assign (const T& ) { }
void assign (const T& value) { fill ( value ); }
void fill (const T& ) {}
// check range (may be private because it is static)
static reference failed_rangecheck () {
std::out_of_range e("attempt to access element of an empty array");
boost::throw_exception(e);
#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
//
// We need to return something here to keep
// some compilers happy: however we will never
@ -280,9 +315,9 @@ namespace boost {
//
static T placeholder;
return placeholder;
#endif
}
};
#endif
// comparisons
template<class T, std::size_t N>
@ -316,6 +351,107 @@ namespace boost {
x.swap(y);
}
#if defined(__SUNPRO_CC)
// Trac ticket #4757; the Sun Solaris compiler can't handle
// syntax like 'T(&get_c_array(boost::array<T,N>& arg))[N]'
//
// We can't just use this for all compilers, because the
// borland compilers can't handle this form.
namespace detail {
template <typename T, std::size_t N> struct c_array
{
typedef T type[N];
};
}
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
typename detail::c_array<T,N>::type& get_c_array(boost::array<T,N>& arg)
{
return arg.elems;
}
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
typename detail::c_array<T,N>::type const& get_c_array(const boost::array<T,N>& arg)
{
return arg.elems;
}
#else
// Specific for boost::array: simply returns its elems data member.
template <typename T, std::size_t N>
T(&get_c_array(boost::array<T,N>& arg))[N]
{
return arg.elems;
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const boost::array<T,N>& arg))[N]
{
return arg.elems;
}
#endif
#if 0
// Overload for std::array, assuming that std::array will have
// explicit conversion functions as discussed at the WG21 meeting
// in Summit, March 2009.
template <typename T, std::size_t N>
T(&get_c_array(std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
#endif
template <class It> std::size_t hash_range(It, It);
template<class T, std::size_t N>
std::size_t hash_value(const array<T,N>& arr)
{
return boost::hash_range(arr.begin(), arr.end());
}
template <size_t Idx, typename T, size_t N>
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" );
return arr[Idx];
}
template <size_t Idx, typename T, size_t N>
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" );
return arr[Idx];
}
} /* namespace boost */
#ifndef BOOST_NO_CXX11_HDR_ARRAY
// If we don't have std::array, I'm assuming that we don't have std::get
namespace std {
template <size_t Idx, typename T, size_t N>
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" );
return arr[Idx];
}
template <size_t Idx, typename T, size_t N>
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" );
return arr[Idx];
}
}
#endif
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#endif /*BOOST_ARRAY_HPP*/

17
meta/libraries.json Normal file
View File

@ -0,0 +1,17 @@
{
"key": "array",
"name": "Array",
"authors": [
"Nicolai Josuttis"
],
"description": "STL compliant container wrapper for arrays of constant size.",
"std": [
"tr1"
],
"category": [
"Containers"
],
"maintainers": [
"Marshall Clow <marshall -at- idio.com>"
]
}

View File

@ -4,11 +4,22 @@
import testing ;
alias unit_test_framework
: # sources
/boost//unit_test_framework
;
test-suite array :
[ run array0.cpp ]
[ run array0.cpp unit_test_framework : : : : array0 ]
[ run array1.cpp ]
[ run array2.cpp ]
[ run array3.cpp ]
[ run array4.cpp ]
[ run array5.cpp ]
[ run array6.cpp unit_test_framework : : : : array6 ]
[ run array7.cpp unit_test_framework : : : : array7 ]
# [ run array_constexpr.cpp unit_test_framework : : : : array_constexpr ]
[ compile-fail array_getfail1.cpp ]
[ compile-fail array_getfail2.cpp ]
[ run array_hash.cpp unit_test_framework : : : : array_hash ]
;

View File

@ -9,18 +9,15 @@
#include <iostream>
#include <boost/array.hpp>
namespace {
unsigned int failed_tests = 0;
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
void fail_test( const char * reason ) {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
namespace {
template< class T >
void BadValue( const T & )
{
fail_test( "Unexpected value" );
BOOST_CHECK ( false );
}
template< class T >
@ -32,59 +29,45 @@ void RunTests()
test_type test_case = {};
const boost::array< T, 0 > const_test_case = test_type();
test_case.assign( T() );
test_case.fill ( T() );
// front/back and operator[] must compile, but calling them is undefined
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
if( !test_case.empty() ) {
BadValue( test_case.front() );
}
BOOST_CHECK ( test_case.empty());
BOOST_CHECK ( const_test_case.empty());
if( !const_test_case.empty() ) {
BadValue( const_test_case.back() );
}
if( test_case.size() > 0 ) {
BadValue( test_case[ 0 ] );
}
if( const_test_case.max_size() > 0 ) {
BadValue( const_test_case[ 0 ] );
}
BOOST_CHECK ( test_case.size() == 0 );
BOOST_CHECK ( const_test_case.size() == 0 );
// Assert requirements of TR1 6.2.2.4
if( test_case.begin() != test_case.end() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.begin() != const_test_case.end() ) {
fail_test( "Not an empty range" );
}
if( test_case.begin() == const_test_case.begin() ) {
fail_test( "iterators for different containers are not distinct" );
}
BOOST_CHECK ( test_case.begin() == test_case.end());
BOOST_CHECK ( test_case.cbegin() == test_case.cend());
BOOST_CHECK ( const_test_case.begin() == const_test_case.end());
BOOST_CHECK ( const_test_case.cbegin() == const_test_case.cend());
BOOST_CHECK ( test_case.begin() != const_test_case.begin() );
if( test_case.data() == const_test_case.data() ) {
// Value of data is unspecified in TR1, so no requirement this test pass or fail
// However, it must compile!
}
// Check can safely use all iterator types with std algorithms
std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
std::for_each( test_case.cbegin(), test_case.cend(), BadValue< T > );
std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
std::for_each( const_test_case.cbegin(), const_test_case.cend(), BadValue< T > );
// Check swap is well formed
std::swap( test_case, test_case );
// Check assigment operator and overloads are well formed
// Check assignment operator and overloads are well formed
test_case = const_test_case;
// Confirm at() throws the std lib defined exception
try {
BadValue( test_case.at( 0 ) );
BadValue( test_case.at( 0 ));
} catch ( const std::out_of_range & ) {
}
@ -96,12 +79,11 @@ void RunTests()
}
int main()
BOOST_AUTO_TEST_CASE( test_main )
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
return failed_tests;
}

View File

@ -5,17 +5,21 @@
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef _SCL_SECURE_NO_WARNINGS
// Suppress warnings from the std lib:
# define _SCL_SECURE_NO_WARNINGS
#endif
#include <algorithm>
#include <functional>
#include <boost/array.hpp>
#include "print.hpp"
using namespace std;
using namespace boost;
int main()
{
// create and initialize array
array<int,10> a = { { 1, 2, 3, 4, 5 } };
boost::array<int,10> a = { { 1, 2, 3, 4, 5 } };
print_elements(a);

View File

@ -21,7 +21,7 @@ int main()
// copy and change order
boost::array<std::string,4> seasons_orig = seasons;
for (unsigned i=seasons.size()-1; i>0; --i) {
for (std::size_t i=seasons.size()-1; i>0; --i) {
std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
}
@ -39,6 +39,13 @@ int main()
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
std::cout << " " << *pos;
}
// try constant reverse iterators
std::cout << "reverse: ";
for (boost::array<std::string,4>::const_reverse_iterator pos
=seasons.crbegin(); pos<seasons.crend(); ++pos) {
std::cout << " " << *pos;
}
std::cout << std::endl;
return 0; // makes Visual-C++ compiler happy

View File

@ -27,7 +27,7 @@ int main()
typedef boost::array<float,6> Array;
// create and initialize an array
const Array a = { { 42.42 } };
const Array a = { { 42.42f } };
// use some common STL container operations
std::cout << "static_size: " << a.size() << std::endl;

40
test/array6.cpp Normal file
View File

@ -0,0 +1,40 @@
/* tests for using class array<> specialization for size 0
* (C) Copyright Alisdair Meredith 2006.
* 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)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace {
template< class T >
void RunTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
arr &aRef = get_c_array ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef[0] );
const arr &caRef = get_c_array ( test_case );
typename test_type::const_iterator iter = test_case.begin ();
BOOST_CHECK ( &*iter == &caRef[0] );
}
}
BOOST_AUTO_TEST_CASE( test_main )
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
}

67
test/array7.cpp Normal file
View File

@ -0,0 +1,67 @@
/* tests using std::get on boost:array
* (C) Copyright Marshall Clow 2012
* 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)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
#ifndef BOOST_NO_CXX11_HDR_ARRAY
#include <array>
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace {
#ifndef BOOST_NO_CXX11_HDR_ARRAY
template< class T >
void RunStdTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
const T &caRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
}
#endif
template< class T >
void RunBoostTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = boost::get<0> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
const T &caRef = boost::get<0> ( test_case );
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
}
}
BOOST_AUTO_TEST_CASE( test_main )
{
RunBoostTests< bool >();
RunBoostTests< void * >();
RunBoostTests< long double >();
RunBoostTests< std::string >();
#ifndef BOOST_NO_CXX11_HDR_ARRAY
RunStdTests< bool >();
RunStdTests< void * >();
RunStdTests< long double >();
RunStdTests< std::string >();
#endif
}

42
test/array_constexpr.cpp Normal file
View File

@ -0,0 +1,42 @@
/* tests using constexpr on boost:array
* (C) Copyright Marshall Clow 2012
* 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)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
#ifndef BOOST_NO_CXX11_HDR_ARRAY
#include <array>
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#ifndef BOOST_NO_CXX11_CONSTEXPR
constexpr boost::array<int, 10> arr {{ 0,1,2,3,4,5,6,7,8,9 }};
constexpr std::array<int, 10> arr_std {{ 0,1,2,3,4,5,6,7,8,9 }};
template <typename T>
void sink ( T t ) {}
template <typename T, size_t N>
void sink ( boost::array<T,N> &arr ) {}
BOOST_AUTO_TEST_CASE( test_main )
{
// constexpr int two = arr_std.at (2);
constexpr int three = arr.at (3);
int whatever [ arr.at(4) ];
(void)three;
(void) whatever;
}
#else // no constexpr means no constexpr tests!
BOOST_AUTO_TEST_CASE( test_main )
{
}
#endif

49
test/array_getfail1.cpp Normal file
View File

@ -0,0 +1,49 @@
/* tests using std::get on boost:array
* (C) Copyright Marshall Clow 2012
* 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)
*/
#include <boost/array.hpp>
#include <boost/static_assert.hpp>
#include <string>
#include <iostream>
#include <algorithm>
#ifndef BOOST_NO_CXX11_HDR_ARRAY
#include <array>
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace {
#ifndef BOOST_NO_CXX11_HDR_ARRAY
template< class T >
void RunStdTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = std::get<5> ( test_case ); // should fail to compile
BOOST_CHECK ( &*test_case.begin () == &aRef );
}
#endif
}
BOOST_AUTO_TEST_CASE( test_main )
{
#ifndef BOOST_NO_CXX11_HDR_ARRAY
RunStdTests< bool >();
RunStdTests< void * >();
RunStdTests< long double >();
RunStdTests< std::string >();
#else
BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems.
#endif
}

64
test/array_getfail2.cpp Normal file
View File

@ -0,0 +1,64 @@
/* tests using std::get on boost:array
* (C) Copyright Marshall Clow 2012
* 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)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
#ifndef BOOST_NO_CXX11_HDR_ARRAY
#include <array>
#endif
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace {
#ifndef BOOST_NO_CXX11_HDR_ARRAY
template< class T >
void RunStdTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
const T &caRef = std::get<0> ( test_case );
BOOST_CHECK ( &*test_case.cbegin () == &caRef );
}
#endif
template< class T >
void RunBoostTests()
{
typedef boost::array< T, 5 > test_type;
typedef T arr[5];
test_type test_case; // = { 1, 1, 2, 3, 5 };
T &aRef = boost::get<5> ( test_case );
BOOST_CHECK ( &*test_case.begin () == &aRef );
}
}
BOOST_AUTO_TEST_CASE( test_main )
{
RunBoostTests< bool >();
RunBoostTests< void * >();
RunBoostTests< long double >();
RunBoostTests< std::string >();
#ifndef BOOST_NO_CXX11_HDR_ARRAY
RunStdTests< bool >();
RunStdTests< void * >();
RunStdTests< long double >();
RunStdTests< std::string >();
#endif
}

43
test/array_hash.cpp Normal file
View File

@ -0,0 +1,43 @@
/* tests for using boost::hash with boost::array
* (C) Copyright Marshall Clow 2012
* 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)
*/
#include <string>
#include <iostream>
#include <boost/array.hpp>
#include <algorithm>
#include <boost/functional/hash.hpp>
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
namespace {
template< class T >
void RunTests()
{
// std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
// std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
typedef boost::array< T, 5 > barr;
typedef T arr[5];
barr test_barr = {{ 1, 1, 2, 3, 5 }};
arr test_arr = { 1, 1, 2, 3, 5 };
std::size_t bhash = boost::hash<barr> () ( test_barr );
std::size_t ahash = boost::hash<arr> () ( test_arr );
BOOST_CHECK ( ahash == bhash );
}
}
BOOST_AUTO_TEST_CASE( test_main )
{
RunTests< int >();
RunTests< long >();
RunTests< long double >();
}