forked from boostorg/array
Compare commits
28 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
47ef0218de | |||
992299f2bf | |||
e6a44cf529 | |||
111e93aa4c | |||
5072c551ec | |||
97e912e82e | |||
05aa660128 | |||
7256882760 | |||
5329bd6f1c | |||
80fa50df2e | |||
6fbc8ee741 | |||
38217688e1 | |||
2595eda739 | |||
64e5394540 | |||
c37498364e | |||
5e81100035 | |||
79cadb97d7 | |||
9609395af0 | |||
fb72e72640 | |||
e875287d55 | |||
100b5d687b | |||
7fb9412ea8 | |||
471bc9bf06 | |||
9cf5e0c9a1 | |||
d2910e195a | |||
b3ace9fb6e | |||
a6b531b5b1 | |||
9804292dad |
@ -13,6 +13,11 @@
|
|||||||
* 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)
|
||||||
*
|
*
|
||||||
|
* 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)
|
* 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.
|
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
|
||||||
* 05 Aug 2001 - minor update (Nico Josuttis)
|
* 05 Aug 2001 - minor update (Nico Josuttis)
|
||||||
@ -24,9 +29,19 @@
|
|||||||
#ifndef BOOST_ARRAY_HPP
|
#ifndef BOOST_ARRAY_HPP
|
||||||
#define 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 <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>
|
||||||
@ -55,10 +70,13 @@ namespace boost {
|
|||||||
typedef std::ptrdiff_t difference_type;
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
|
||||||
// iterator support
|
// iterator support
|
||||||
iterator begin() { return elems; }
|
iterator begin() { return elems; }
|
||||||
const_iterator begin() const { return elems; }
|
const_iterator begin() const { return elems; }
|
||||||
iterator end() { return elems+N; }
|
const_iterator cbegin() const { return elems; }
|
||||||
const_iterator end() const { return elems+N; }
|
|
||||||
|
iterator end() { return elems+N; }
|
||||||
|
const_iterator end() const { return elems+N; }
|
||||||
|
const_iterator cend() const { return elems+N; }
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||||
@ -70,6 +88,11 @@ namespace boost {
|
|||||||
reference, iterator, reference> > reverse_iterator;
|
reference, iterator, reference> > reverse_iterator;
|
||||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
||||||
const_reference, iterator, reference> > const_reverse_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
|
#else
|
||||||
// workaround for broken reverse_iterator implementations
|
// workaround for broken reverse_iterator implementations
|
||||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
||||||
@ -80,21 +103,28 @@ namespace boost {
|
|||||||
const_reverse_iterator rbegin() const {
|
const_reverse_iterator rbegin() const {
|
||||||
return const_reverse_iterator(end());
|
return const_reverse_iterator(end());
|
||||||
}
|
}
|
||||||
|
const_reverse_iterator crbegin() const {
|
||||||
|
return const_reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||||
const_reverse_iterator rend() const {
|
const_reverse_iterator rend() const {
|
||||||
return const_reverse_iterator(begin());
|
return const_reverse_iterator(begin());
|
||||||
}
|
}
|
||||||
|
const_reverse_iterator crend() const {
|
||||||
|
return const_reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
// operator[]
|
// operator[]
|
||||||
reference operator[](size_type i)
|
reference operator[](size_type i)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT( i < N && "out of range" );
|
BOOST_ASSERT_MSG( i < N, "out of range" );
|
||||||
return elems[i];
|
return elems[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const_reference operator[](size_type i) const
|
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];
|
return elems[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +161,8 @@ 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)
|
||||||
@ -149,7 +180,8 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assign one value to all elements
|
// 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);
|
std::fill_n(begin(),size(),value);
|
||||||
}
|
}
|
||||||
@ -157,7 +189,8 @@ 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::out_of_range("array<>: index out of range");
|
std::out_of_range e("array<>: index out of range");
|
||||||
|
boost::throw_exception(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,10 +211,13 @@ namespace boost {
|
|||||||
typedef std::ptrdiff_t difference_type;
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
|
||||||
// iterator support
|
// iterator support
|
||||||
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
||||||
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
||||||
iterator end() { return begin(); }
|
const_iterator cbegin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
||||||
const_iterator end() const { return begin(); }
|
|
||||||
|
iterator end() { return begin(); }
|
||||||
|
const_iterator end() const { return begin(); }
|
||||||
|
const_iterator cend() const { return cbegin(); }
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
||||||
@ -193,6 +229,11 @@ namespace boost {
|
|||||||
reference, iterator, reference> > reverse_iterator;
|
reference, iterator, reference> > reverse_iterator;
|
||||||
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
typedef std::reverse_iterator<std::_Ptrit<value_type, difference_type, const_iterator,
|
||||||
const_reference, iterator, reference> > const_reverse_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
|
#else
|
||||||
// workaround for broken reverse_iterator implementations
|
// workaround for broken reverse_iterator implementations
|
||||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
||||||
@ -203,25 +244,32 @@ namespace boost {
|
|||||||
const_reverse_iterator rbegin() const {
|
const_reverse_iterator rbegin() const {
|
||||||
return const_reverse_iterator(end());
|
return const_reverse_iterator(end());
|
||||||
}
|
}
|
||||||
|
const_reverse_iterator crbegin() const {
|
||||||
|
return const_reverse_iterator(end());
|
||||||
|
}
|
||||||
|
|
||||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||||
const_reverse_iterator rend() const {
|
const_reverse_iterator rend() const {
|
||||||
return const_reverse_iterator(begin());
|
return const_reverse_iterator(begin());
|
||||||
}
|
}
|
||||||
|
const_reverse_iterator crend() const {
|
||||||
|
return const_reverse_iterator(begin());
|
||||||
|
}
|
||||||
|
|
||||||
// operator[]
|
// operator[]
|
||||||
reference operator[](size_type i)
|
reference operator[](size_type /*i*/)
|
||||||
{
|
{
|
||||||
return failed_rangecheck();
|
return failed_rangecheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
const_reference operator[](size_type i) const
|
const_reference operator[](size_type /*i*/) const
|
||||||
{
|
{
|
||||||
return failed_rangecheck();
|
return failed_rangecheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
// at() with range check
|
// at() with range check
|
||||||
reference at(size_type i) { return failed_rangecheck(); }
|
reference at(size_type /*i*/) { return failed_rangecheck(); }
|
||||||
const_reference at(size_type i) const { return failed_rangecheck(); }
|
const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
|
||||||
|
|
||||||
// front() and back()
|
// front() and back()
|
||||||
reference front()
|
reference front()
|
||||||
@ -250,7 +298,7 @@ namespace boost {
|
|||||||
static size_type max_size() { return 0; }
|
static size_type max_size() { return 0; }
|
||||||
enum { static_size = 0 };
|
enum { static_size = 0 };
|
||||||
|
|
||||||
void swap (array<T,0>& y) {
|
void swap (array<T,0>& /*y*/) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// direct access to data (read-only)
|
// direct access to data (read-only)
|
||||||
@ -267,12 +315,14 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assign one value to all elements
|
// 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)
|
// check range (may be private because it is static)
|
||||||
static reference failed_rangecheck () {
|
static reference failed_rangecheck () {
|
||||||
std::out_of_range e("attempt to access element of an empty array");
|
std::out_of_range e("attempt to access element of an empty array");
|
||||||
boost::throw_exception(e);
|
boost::throw_exception(e);
|
||||||
|
#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
|
||||||
//
|
//
|
||||||
// We need to return something here to keep
|
// We need to return something here to keep
|
||||||
// some compilers happy: however we will never
|
// some compilers happy: however we will never
|
||||||
@ -280,6 +330,7 @@ namespace boost {
|
|||||||
//
|
//
|
||||||
static T placeholder;
|
static T placeholder;
|
||||||
return placeholder;
|
return placeholder;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@ -316,6 +367,71 @@ namespace boost {
|
|||||||
x.swap(y);
|
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 */
|
} /* namespace boost */
|
||||||
|
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
|
# pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /*BOOST_ARRAY_HPP*/
|
#endif /*BOOST_ARRAY_HPP*/
|
||||||
|
15
test/Jamfile.v2
Normal file
15
test/Jamfile.v2
Normal 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 ]
|
||||||
|
;
|
@ -32,7 +32,7 @@ void RunTests()
|
|||||||
test_type test_case = {};
|
test_type test_case = {};
|
||||||
const boost::array< T, 0 > const_test_case = test_type();
|
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
|
// front/back and operator[] must compile, but calling them is undefined
|
||||||
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
|
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
|
||||||
@ -56,9 +56,15 @@ void RunTests()
|
|||||||
if( test_case.begin() != test_case.end() ) {
|
if( test_case.begin() != test_case.end() ) {
|
||||||
fail_test( "Not an empty range" );
|
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() ) {
|
if( const_test_case.begin() != const_test_case.end() ) {
|
||||||
fail_test( "Not an empty range" );
|
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() ) {
|
if( test_case.begin() == const_test_case.begin() ) {
|
||||||
fail_test( "iterators for different containers are not distinct" );
|
fail_test( "iterators for different containers are not distinct" );
|
||||||
@ -73,8 +79,10 @@ void RunTests()
|
|||||||
// Check can safely use all iterator types with std algorithms
|
// 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.begin(), test_case.end(), BadValue< T > );
|
||||||
std::for_each( test_case.rbegin(), test_case.rend(), 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.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.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
|
// Check swap is well formed
|
||||||
std::swap( test_case, test_case );
|
std::swap( test_case, test_case );
|
@ -5,17 +5,21 @@
|
|||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
* 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 <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#include "print.hpp"
|
#include "print.hpp"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create and initialize array
|
// 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);
|
print_elements(a);
|
||||||
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,6 +39,13 @@ int main()
|
|||||||
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
|
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
|
||||||
std::cout << " " << *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;
|
std::cout << std::endl;
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
return 0; // makes Visual-C++ compiler happy
|
@ -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;
|
48
test/array6.cpp
Normal file
48
test/array6.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user