Compare commits

...

18 Commits

Author SHA1 Message Date
975e8a2a45 Release 1.41.0
[SVN r57747]
2009-11-18 14:58:26 +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
5661b8cd63 Add basic copyright/license to keep cmake out of the inspection report
[SVN r55095]
2009-07-22 21:51:01 +00:00
86b069ad0e Merge [53104] and [53105] from the trunk
[SVN r53198]
2009-05-23 06:00:42 +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
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
11 changed files with 267 additions and 17 deletions

View File

@ -17,11 +17,11 @@
</copyright> </copyright>
<legalnotice> <legalnotice>
<para>Permission to copy, use, modify, sell and distribute this <para>Distributed under the Boost Software License, Version 1.0.
software is granted provided this copyright notice appears in (See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
all copies. This software is provided "as is" without express or <ulink
implied warranty, and with no claim as to its suitability for url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
any purpose.</para> </para>
</legalnotice> </legalnotice>
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose> <librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>

View File

@ -2,13 +2,13 @@
* an STL container (as wrapper) for arrays of constant size. * an STL container (as wrapper) for arrays of constant size.
* *
* See * See
* http://www.josuttis.com/cppcode * http://www.boost.org/libs/array/
* for details and the latest version.
* See
* http://www.boost.org/libs/array for Documentation.
* for documentation. * for documentation.
* *
* The original author site is at: http://www.josuttis.com/
*
* (C) Copyright Nicolai M. Josuttis 2001. * (C) Copyright Nicolai M. Josuttis 2001.
*
* Distributed under the Boost Software License, Version 1.0. (See * Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at * accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
@ -27,9 +27,11 @@
#include <cstddef> #include <cstddef>
#include <stdexcept> #include <stdexcept>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/swap.hpp>
// Handles broken standard libraries better than <iterator> // Handles broken standard libraries better than <iterator>
#include <boost/detail/iterator.hpp> #include <boost/detail/iterator.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
// FIXES for broken compilers // FIXES for broken compilers
@ -130,11 +132,13 @@ namespace boost {
// swap (note: linear complexity) // swap (note: linear complexity)
void swap (array<T,N>& y) { 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) // direct access to data (read-only)
const T* data() const { return elems; } const T* data() const { return elems; }
T* data() { return elems; }
// use array as C array (direct read/write access to data) // use array as C array (direct read/write access to data)
T* c_array() { return elems; } T* c_array() { return elems; }
@ -155,12 +159,133 @@ namespace boost {
// check range (may be private because it is static) // check range (may be private because it is static)
static void rangecheck (size_type i) { static void rangecheck (size_type i) {
if (i >= size()) { if (i >= size()) {
throw std::range_error("array<>: index out of range"); throw std::out_of_range("array<>: index out of range");
} }
} }
}; };
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template< class T >
class array< T, 0 > {
public:
// type definitions
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
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(); }
// reverse iterator support
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !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;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
#endif
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
// operator[]
reference operator[](size_type /*i*/)
{
return failed_rangecheck();
}
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(); }
// front() and back()
reference front()
{
return failed_rangecheck();
}
const_reference front() const
{
return failed_rangecheck();
}
reference back()
{
return failed_rangecheck();
}
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; }
enum { static_size = 0 };
void swap (array<T,0>& /*y*/) {
}
// direct access to data (read-only)
const T* data() const { return 0; }
T* data() { return 0; }
// use array as C array (direct read/write access to data)
T* c_array() { return 0; }
// assignment with type conversion
template <typename T2>
array<T,0>& operator= (const array<T2,0>& ) {
return *this;
}
// assign one value to all elements
void assign (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);
//
// We need to return something here to keep
// some compilers happy: however we will never
// actually get here....
//
static T placeholder;
return placeholder;
}
};
#endif
// comparisons // comparisons
template<class T, std::size_t N> template<class T, std::size_t N>
bool operator== (const array<T,N>& x, const array<T,N>& y) { bool operator== (const array<T,N>& x, const array<T,N>& y) {

View File

@ -4,6 +4,10 @@
</head> </head>
<body> <body>
Automatic redirection failed, please go to Automatic redirection failed, please go to
<a href="../../doc/html/array.html">../../doc/html/array.html</a> <a href="../../doc/html/array.html">../../doc/html/array.html</a> &nbsp;<hr>
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body> </body>
</html> </html>

14
test/Jamfile.v2 Normal file
View File

@ -0,0 +1,14 @@
#~ 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 array :
[ run array0.cpp ]
[ run array1.cpp ]
[ run array2.cpp ]
[ run array3.cpp ]
[ run array4.cpp ]
[ run array5.cpp ]
;

107
test/array0.cpp Normal file
View File

@ -0,0 +1,107 @@
/* 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>
namespace {
unsigned int failed_tests = 0;
void fail_test( const char * reason ) {
++failed_tests;
std::cerr << "Test failure " << failed_tests << ": " << reason << std::endl;
}
template< class T >
void BadValue( const T & )
{
fail_test( "Unexpected value" );
}
template< class T >
void RunTests()
{
typedef boost::array< T, 0 > test_type;
// Test value and aggegrate initialization
test_type test_case = {};
const boost::array< T, 0 > const_test_case = test_type();
test_case.assign( 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() );
}
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 ] );
}
// 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" );
}
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( const_test_case.begin(), const_test_case.end(), BadValue< T > );
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
// Check swap is well formed
std::swap( test_case, test_case );
// Check assigment 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 ) );
} catch ( const std::out_of_range & ) {
}
try {
BadValue( const_test_case.at( 0 ) );
} catch ( const std::out_of_range & ) {
}
}
}
int main()
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
return failed_tests;
}

View File

@ -21,7 +21,7 @@ int main()
// copy and change order // copy and change order
boost::array<std::string,4> seasons_orig = seasons; 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())); std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
} }

View File

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