Compare commits

...

37 Commits

Author SHA1 Message Date
47ef0218de Create branches/filesystem-v3 for v2 removal
[SVN r77385]
2012-03-18 20:54:17 +00:00
992299f2bf Use BOOST_ASSERT_MSG instead of naked BOOST_ASSERT
[SVN r77135]
2012-02-28 18:47:28 +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
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
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
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
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
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
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
7fb9412ea8 removed warning on vc++ for using std::equal
[SVN r54541]
2009-06-30 20:04:45 +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
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
9804292dad Move array test into canonical test subdir structure.
[SVN r44376]
2008-04-13 22:12:12 +00:00
069b5e2ca1 Throw out_of_range rather than range_error. See 21.1.1 paragraph 13.
[SVN r36304]
2006-12-08 16:54:30 +00:00
526953fc5e Test for out_of_range rather than range_error. See 21.1.1 paragraph 13.
[SVN r36303]
2006-12-08 16:53:49 +00:00
b06f12b0b7 Fixed license & copyright issues.
[SVN r36224]
2006-12-01 10:29:49 +00:00
f0bbb8b211 Add copyright, license
[SVN r35905]
2006-11-07 19:11:57 +00:00
d7a5408143 http://www.josuttis.com/ hasn't the latest version any more
[SVN r34855]
2006-08-08 18:49:30 +00:00
564e4029d0 Simplified code.
[SVN r34384]
2006-06-24 11:31:19 +00:00
0dc11c2f23 Fix compiler errors resulting from missing return values.
[SVN r34259]
2006-06-09 11:40:07 +00:00
7da1c4b310 Remove size zero support for old compilers that do not support partial template specialization
[SVN r34161]
2006-06-04 11:01:59 +00:00
8f10fdf27e Support for zero length arrays
[SVN r34154]
2006-06-03 12:51:13 +00:00
12 changed files with 458 additions and 26 deletions

View File

@ -17,11 +17,11 @@
</copyright>
<legalnotice>
<para>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.</para>
<para>Distributed under the Boost Software License, Version 1.0.
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
<ulink
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
</para>
</legalnotice>
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>

View File

@ -2,17 +2,22 @@
* an STL container (as wrapper) for arrays of constant size.
*
* See
* http://www.josuttis.com/cppcode
* for details and the latest version.
* See
* http://www.boost.org/libs/array for Documentation.
* http://www.boost.org/libs/array/
* for documentation.
*
* The original author site is at: http://www.josuttis.com/
*
* (C) Copyright Nicolai M. Josuttis 2001.
*
* 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)
*
* 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,12 +29,23 @@
#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/swap.hpp>
// Handles broken standard libraries better than <iterator>
#include <boost/detail/iterator.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm>
// FIXES for broken compilers
@ -52,12 +68,15 @@ namespace boost {
typedef const T& const_reference;
typedef std::size_t size_type;
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)
@ -69,6 +88,11 @@ namespace boost {
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;
@ -79,21 +103,28 @@ 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" );
BOOST_ASSERT_MSG( i < N, "out of range" );
return elems[i];
}
const_reference operator[](size_type i) const
{
BOOST_ASSERT( i < N && "out of range" );
BOOST_ASSERT_MSG( i < N, "out of range" );
return elems[i];
}
@ -130,11 +161,13 @@ namespace boost {
// 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)
const T* data() const { return elems; }
T* data() { return elems; }
// use array as C array (direct read/write access to data)
T* c_array() { return elems; }
@ -147,20 +180,161 @@ 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::range_error("array<>: index out of range");
if (i >= size()) {
std::out_of_range e("array<>: index out of range");
boost::throw_exception(e);
}
}
};
#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 ) ); }
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)
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;
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());
}
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*/)
{
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& 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
// actually get here....
//
static T placeholder;
return placeholder;
#endif
}
};
#endif
// comparisons
template<class T, std::size_t N>
bool operator== (const array<T,N>& x, const array<T,N>& y) {
@ -193,6 +367,71 @@ 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 const detail::c_array<T,N>::type& 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
} /* namespace boost */
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(pop)
#endif
#endif /*BOOST_ARRAY_HPP*/

View File

@ -4,6 +4,10 @@
</head>
<body>
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>
</html>
</html>

15
test/Jamfile.v2 Normal file
View File

@ -0,0 +1,15 @@
#~ 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 ]
[ run array6.cpp ]
;

115
test/array0.cpp Normal file
View File

@ -0,0 +1,115 @@
/* 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.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() );
}
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( test_case.cbegin() != test_case.cend() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.begin() != const_test_case.end() ) {
fail_test( "Not an empty range" );
}
if( const_test_case.cbegin() != const_test_case.cend() ) {
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( 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
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

@ -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;

48
test/array6.cpp Normal file
View File

@ -0,0 +1,48 @@
/* 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>
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 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 );
if ( &*test_case.begin () != &aRef[0] )
fail_test ( "Array6: Same thing not equal?(1)" );
const arr &caRef = get_c_array ( test_case );
typename test_type::const_iterator iter = test_case.begin ();
if ( &*iter != &caRef[0] )
fail_test ( "Array6: Same thing not equal?(2)" );
}
}
int main()
{
RunTests< bool >();
RunTests< void * >();
RunTests< long double >();
RunTests< std::string >();
return failed_tests;
}