From 8f10fdf27eef4653821be60bff1f5ef62febf6d3 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Sat, 3 Jun 2006 12:51:13 +0000 Subject: [PATCH 01/38] Support for zero length arrays [SVN r34154] --- array0.cpp | 107 ++++++++++++++++++++++++++++++++++++ include/boost/array.hpp | 119 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 224 insertions(+), 2 deletions(-) create mode 100644 array0.cpp diff --git a/array0.cpp b/array0.cpp new file mode 100644 index 0000000..e6e5e8b --- /dev/null +++ b/array0.cpp @@ -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 +#include +#include + +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::range_error & ) { + } + + try { + BadValue( const_test_case.at( 0 ) ); + } catch ( const std::range_error & ) { + } +} + +} + +int main() +{ + RunTests< bool >(); + RunTests< void * >(); + RunTests< long double >(); + RunTests< std::string >(); + return failed_tests; +} + diff --git a/include/boost/array.hpp b/include/boost/array.hpp index ce9eda7..841ed76 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -52,7 +52,7 @@ 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; } @@ -135,6 +135,7 @@ namespace boost { // 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; } @@ -154,13 +155,127 @@ namespace boost { // check range (may be private because it is static) static void rangecheck (size_type i) { - if (i >= size()) { + if (i >= size()) { throw std::range_error("array<>: index out of range"); } } }; + 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 reverse_iterator; + typedef std::reverse_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 > reverse_iterator; + typedef std::reverse_iterator > const_reverse_iterator; +#else + // workaround for broken reverse_iterator implementations + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator 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) + { + BOOST_ASSERT( "out of range" ); + failed_rangecheck(); + } + + const_reference operator[](size_type i) const + { + BOOST_ASSERT( "out of range" ); + failed_rangecheck(); + } + + // at() with range check + reference at(size_type i) { failed_rangecheck(); } + const_reference at(size_type i) const { failed_rangecheck(); } + + // front() and back() + reference front() + { + failed_rangecheck(); + } + + const_reference front() const + { + failed_rangecheck(); + } + + reference back() + { + failed_rangecheck(); + } + + const_reference back() const + { + 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& 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 + array& operator= (const array& ) { + return *this; + } + + // assign one value to all elements + void assign (const T& ) { } + + // check range (may be private because it is static) + static void failed_rangecheck () { + throw std::range_error("attempt to access element of an empty array"); + } + + }; + // comparisons template bool operator== (const array& x, const array& y) { From 7da1c4b310af70abf92c10786ebf6d0d0072a721 Mon Sep 17 00:00:00 2001 From: Alisdair Meredith Date: Sun, 4 Jun 2006 11:01:59 +0000 Subject: [PATCH 02/38] Remove size zero support for old compilers that do not support partial template specialization [SVN r34161] --- include/boost/array.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 841ed76..102664e 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -162,6 +162,7 @@ namespace boost { }; +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) template< class T > class array< T, 0 > { @@ -273,8 +274,8 @@ namespace boost { static void failed_rangecheck () { throw std::range_error("attempt to access element of an empty array"); } - }; +#endif // comparisons template From 0dc11c2f2373755f5b804a2e43b6bc2059e31230 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 9 Jun 2006 11:40:07 +0000 Subject: [PATCH 03/38] Fix compiler errors resulting from missing return values. [SVN r34259] --- include/boost/array.hpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 102664e..7eef6af 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -30,6 +30,7 @@ // Handles broken standard libraries better than #include +#include #include // FIXES for broken compilers @@ -212,37 +213,43 @@ namespace boost { { BOOST_ASSERT( "out of range" ); failed_rangecheck(); + return null_item(); } const_reference operator[](size_type i) const { BOOST_ASSERT( "out of range" ); failed_rangecheck(); + return null_item(); } // at() with range check - reference at(size_type i) { failed_rangecheck(); } - const_reference at(size_type i) const { failed_rangecheck(); } + reference at(size_type i) { failed_rangecheck(); return null_item(); } + const_reference at(size_type i) const { failed_rangecheck(); return null_item(); } // front() and back() reference front() { failed_rangecheck(); + return null_item(); } const_reference front() const { failed_rangecheck(); + return null_item(); } reference back() { failed_rangecheck(); + return null_item(); } const_reference back() const { failed_rangecheck(); + return null_item(); } // size is constant @@ -272,8 +279,19 @@ namespace boost { // check range (may be private because it is static) static void failed_rangecheck () { - throw std::range_error("attempt to access element of an empty array"); + std::range_error e("attempt to access element of an empty array"); + boost::throw_exception(e); } + static reference null_item() + { + // + // This function must exist to allow our various interfaces to + // actually compile, however it will never be called, because + // an exception will always be thrown before we get here. + // + static T placeholder; + return placeholder; + } }; #endif From 564e4029d03bcc41fdc961466f5272e3de263e33 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 24 Jun 2006 11:31:19 +0000 Subject: [PATCH 04/38] Simplified code. [SVN r34384] --- include/boost/array.hpp | 43 +++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 7eef6af..21e5f1b 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -211,45 +211,37 @@ namespace boost { // operator[] reference operator[](size_type i) { - BOOST_ASSERT( "out of range" ); - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } const_reference operator[](size_type i) const { - BOOST_ASSERT( "out of range" ); - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } // at() with range check - reference at(size_type i) { failed_rangecheck(); return null_item(); } - const_reference at(size_type i) const { failed_rangecheck(); return null_item(); } + reference at(size_type i) { return failed_rangecheck(); } + const_reference at(size_type i) const { return failed_rangecheck(); } // front() and back() reference front() { - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } const_reference front() const { - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } reference back() { - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } const_reference back() const { - failed_rangecheck(); - return null_item(); + return failed_rangecheck(); } // size is constant @@ -278,20 +270,17 @@ namespace boost { void assign (const T& ) { } // check range (may be private because it is static) - static void failed_rangecheck () { + static reference failed_rangecheck () { std::range_error 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; } - static reference null_item() - { - // - // This function must exist to allow our various interfaces to - // actually compile, however it will never be called, because - // an exception will always be thrown before we get here. - // - static T placeholder; - return placeholder; - } }; #endif From d7a5408143cd1202fd7f559d4aef9cbb050e29b1 Mon Sep 17 00:00:00 2001 From: Gennaro Prota Date: Tue, 8 Aug 2006 18:49:30 +0000 Subject: [PATCH 05/38] http://www.josuttis.com/ hasn't the latest version any more [SVN r34855] --- include/boost/array.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 21e5f1b..b41c656 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -2,13 +2,13 @@ * 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) From f0bbb8b211dde9632d612c5c6794b9bac9bbd556 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Tue, 7 Nov 2006 19:11:57 +0000 Subject: [PATCH 06/38] Add copyright, license [SVN r35905] --- index.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 588f27e..a9e3c34 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,10 @@ Automatic redirection failed, please go to -../../doc/html/array.html +../../doc/html/array.html  
+

© Copyright Beman Dawes, 2001

+

Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy +at www.boost.org/LICENSE_1_0.txt)

- + \ No newline at end of file From b06f12b0b71112cfb79ea72d4bf1178d2e316c56 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 1 Dec 2006 10:29:49 +0000 Subject: [PATCH 07/38] Fixed license & copyright issues. [SVN r36224] --- doc/array.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/array.xml b/doc/array.xml index e09c0c0..fca63a6 100644 --- a/doc/array.xml +++ b/doc/array.xml @@ -17,11 +17,11 @@ - 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. + 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) + STL compliant container wrapper for arrays of constant size From 526953fc5e1b46e2f6dd2b394251bf20cc2b7ab6 Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 8 Dec 2006 16:53:49 +0000 Subject: [PATCH 08/38] Test for out_of_range rather than range_error. See 21.1.1 paragraph 13. [SVN r36303] --- array0.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/array0.cpp b/array0.cpp index e6e5e8b..065256b 100644 --- a/array0.cpp +++ b/array0.cpp @@ -85,12 +85,12 @@ void RunTests() // Confirm at() throws the std lib defined exception try { BadValue( test_case.at( 0 ) ); - } catch ( const std::range_error & ) { + } catch ( const std::out_of_range & ) { } try { BadValue( const_test_case.at( 0 ) ); - } catch ( const std::range_error & ) { + } catch ( const std::out_of_range & ) { } } From 069b5e2ca1fdc4d2aa38c76d2dfa1664ddf104ef Mon Sep 17 00:00:00 2001 From: Beman Dawes Date: Fri, 8 Dec 2006 16:54:30 +0000 Subject: [PATCH 09/38] Throw out_of_range rather than range_error. See 21.1.1 paragraph 13. [SVN r36304] --- include/boost/array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index b41c656..52218aa 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -157,7 +157,7 @@ namespace boost { // 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"); + throw std::out_of_range("array<>: index out of range"); } } @@ -271,7 +271,7 @@ namespace boost { // check range (may be private because it is static) static reference failed_rangecheck () { - std::range_error 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); // // We need to return something here to keep From 9804292dad3e497636c7b4b08aca755261c8ab09 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Sun, 13 Apr 2008 22:12:12 +0000 Subject: [PATCH 10/38] Move array test into canonical test subdir structure. [SVN r44376] --- test/Jamfile.v2 | 14 ++++++++++++++ array0.cpp => test/array0.cpp | 0 array1.cpp => test/array1.cpp | 0 array2.cpp => test/array2.cpp | 0 array3.cpp => test/array3.cpp | 0 array4.cpp => test/array4.cpp | 0 array5.cpp => test/array5.cpp | 0 print.hpp => test/print.hpp | 0 8 files changed, 14 insertions(+) create mode 100644 test/Jamfile.v2 rename array0.cpp => test/array0.cpp (100%) rename array1.cpp => test/array1.cpp (100%) rename array2.cpp => test/array2.cpp (100%) rename array3.cpp => test/array3.cpp (100%) rename array4.cpp => test/array4.cpp (100%) rename array5.cpp => test/array5.cpp (100%) rename print.hpp => test/print.hpp (100%) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 new file mode 100644 index 0000000..1379a5b --- /dev/null +++ b/test/Jamfile.v2 @@ -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 ] + ; diff --git a/array0.cpp b/test/array0.cpp similarity index 100% rename from array0.cpp rename to test/array0.cpp diff --git a/array1.cpp b/test/array1.cpp similarity index 100% rename from array1.cpp rename to test/array1.cpp diff --git a/array2.cpp b/test/array2.cpp similarity index 100% rename from array2.cpp rename to test/array2.cpp diff --git a/array3.cpp b/test/array3.cpp similarity index 100% rename from array3.cpp rename to test/array3.cpp diff --git a/array4.cpp b/test/array4.cpp similarity index 100% rename from array4.cpp rename to test/array4.cpp diff --git a/array5.cpp b/test/array5.cpp similarity index 100% rename from array5.cpp rename to test/array5.cpp diff --git a/print.hpp b/test/print.hpp similarity index 100% rename from print.hpp rename to test/print.hpp From a6b531b5b1a7a2ef2d770096b5ae557671ac1ff0 Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Sat, 1 Nov 2008 13:15:41 +0000 Subject: [PATCH 11/38] Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor [SVN r49510] --- CMakeLists.txt | 21 +++++++++++++++++++++ test/CMakeLists.txt | 6 ++++++ 2 files changed, 27 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..39a2788 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +#---------------------------------------------------------------------------- +# This file was automatically generated from the original CMakeLists.txt file +# Add a variable to hold the headers for the library +set (lib_headers + array.hpp +) + +# Add a library target to the build system +boost_library_project( + array + # SRCDIRS + TESTDIRS test + HEADERS ${lib_headers} + # DOCDIRS + DESCRIPTION "STL compliant container wrapper for arrays of constant size." + MODULARIZED + AUTHORS "Nicolai Josuttis" + # MAINTAINERS +) + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..786b09b --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,6 @@ +boost_test_run(array0 array0.cpp) +boost_test_run(array1 array1.cpp) +boost_test_run(array2 array2.cpp) +boost_test_run(array3 array3.cpp) +boost_test_run(array4 array4.cpp) +boost_test_run(array5 array5.cpp) From b3ace9fb6ebbea9d44a3ef720f4983884c34ae77 Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:02:56 +0000 Subject: [PATCH 12/38] Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use. [SVN r49627] --- test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 786b09b..2301077 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,5 @@ +boost_additional_test_dependencies(array BOOST_DEPENDS test) + boost_test_run(array0 array0.cpp) boost_test_run(array1 array1.cpp) boost_test_run(array2 array2.cpp) From d2910e195a29607fd9253e3de42e58285319d42a Mon Sep 17 00:00:00 2001 From: "Michael A. Jackson" Date: Fri, 7 Nov 2008 17:05:27 +0000 Subject: [PATCH 13/38] Updating dependency information for modularized libraries. [SVN r49628] --- module.cmake | 1 + 1 file changed, 1 insertion(+) create mode 100644 module.cmake diff --git a/module.cmake b/module.cmake new file mode 100644 index 0000000..ccd2813 --- /dev/null +++ b/module.cmake @@ -0,0 +1 @@ +boost_module(array DEPENDS utility) \ No newline at end of file From 9cf5e0c9a1ece15ed37448d9964f8b457f267e3f Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Tue, 19 May 2009 02:37:04 +0000 Subject: [PATCH 14/38] Use boost::swap instead of std::swap_ranges to enable ADL. Fixes #2753. [SVN r53104] --- include/boost/array.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 52218aa..3b1c0b0 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -27,6 +27,7 @@ #include #include #include +#include // Handles broken standard libraries better than #include @@ -131,7 +132,8 @@ namespace boost { // swap (note: linear complexity) void swap (array& 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) From 471bc9bf06489aafa92b4f9f4b2c8bbd7fd86dc5 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Tue, 19 May 2009 03:00:53 +0000 Subject: [PATCH 15/38] Supress warnings in array [SVN r53105] --- include/boost/array.hpp | 10 +++++----- test/array3.cpp | 2 +- test/array5.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 3b1c0b0..8ef73c4 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -211,19 +211,19 @@ namespace boost { } // operator[] - reference operator[](size_type i) + reference operator[](size_type /*i*/) { return failed_rangecheck(); } - const_reference operator[](size_type i) const + 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(); } + const_reference at(size_type /*i*/) const { return failed_rangecheck(); } // front() and back() reference front() @@ -252,7 +252,7 @@ namespace boost { static size_type max_size() { return 0; } enum { static_size = 0 }; - void swap (array& y) { + void swap (array& /*y*/) { } // direct access to data (read-only) diff --git a/test/array3.cpp b/test/array3.cpp index a4eac5d..b815fe7 100644 --- a/test/array3.cpp +++ b/test/array3.cpp @@ -21,7 +21,7 @@ int main() // copy and change order boost::array 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())); } diff --git a/test/array5.cpp b/test/array5.cpp index d6c472a..23156b9 100644 --- a/test/array5.cpp +++ b/test/array5.cpp @@ -27,7 +27,7 @@ int main() typedef boost::array 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; From 7fb9412ea8b0b9d2b63a865cf194742382ca00bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20J=C3=B8rgen=20Ottosen?= Date: Tue, 30 Jun 2009 20:04:45 +0000 Subject: [PATCH 16/38] removed warning on vc++ for using std::equal [SVN r54541] --- include/boost/array.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 8ef73c4..d58b93a 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -24,6 +24,13 @@ #ifndef BOOST_ARRAY_HPP #define BOOST_ARRAY_HPP +#include + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +# pragma warning(push) +# pragma warning(disable:4996) // 'std::equal': Function call with parameters that may be unsafe +#endif + #include #include #include @@ -320,4 +327,9 @@ namespace boost { } /* namespace boost */ + +#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) +# pragma warning(pop) +#endif + #endif /*BOOST_ARRAY_HPP*/ From 100b5d687b712c73055055bed63ba38a13d73a02 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sun, 26 Jul 2009 00:49:56 +0000 Subject: [PATCH 17/38] 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] --- CMakeLists.txt | 6 ++++++ test/CMakeLists.txt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39a2788..ecdd503 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# #---------------------------------------------------------------------------- # This file was automatically generated from the original CMakeLists.txt file # Add a variable to hold the headers for the library diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2301077..379e7b1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,9 @@ +# +# Copyright Troy D. Straszheim +# +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt +# boost_additional_test_dependencies(array BOOST_DEPENDS test) boost_test_run(array0 array0.cpp) From e875287d5515d01d4117f7e0a34a27289249f486 Mon Sep 17 00:00:00 2001 From: "Troy D. Straszheim" Date: Sat, 17 Oct 2009 02:07:38 +0000 Subject: [PATCH 18/38] 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] --- CMakeLists.txt | 27 --------------------------- module.cmake | 1 - test/CMakeLists.txt | 14 -------------- 3 files changed, 42 deletions(-) delete mode 100644 CMakeLists.txt delete mode 100644 module.cmake delete mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index ecdd503..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -#---------------------------------------------------------------------------- -# This file was automatically generated from the original CMakeLists.txt file -# Add a variable to hold the headers for the library -set (lib_headers - array.hpp -) - -# Add a library target to the build system -boost_library_project( - array - # SRCDIRS - TESTDIRS test - HEADERS ${lib_headers} - # DOCDIRS - DESCRIPTION "STL compliant container wrapper for arrays of constant size." - MODULARIZED - AUTHORS "Nicolai Josuttis" - # MAINTAINERS -) - - diff --git a/module.cmake b/module.cmake deleted file mode 100644 index ccd2813..0000000 --- a/module.cmake +++ /dev/null @@ -1 +0,0 @@ -boost_module(array DEPENDS utility) \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 379e7b1..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright Troy D. Straszheim -# -# Distributed under the Boost Software License, Version 1.0. -# See http://www.boost.org/LICENSE_1_0.txt -# -boost_additional_test_dependencies(array BOOST_DEPENDS test) - -boost_test_run(array0 array0.cpp) -boost_test_run(array1 array1.cpp) -boost_test_run(array2 array2.cpp) -boost_test_run(array3 array3.cpp) -boost_test_run(array4 array4.cpp) -boost_test_run(array5 array5.cpp) From fb72e72640a9467ca062d75f4c2f285d085808b6 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 3 Feb 2010 12:10:56 +0000 Subject: [PATCH 19/38] MSVC warning suppression - fixes #3599. [SVN r59439] --- include/boost/array.hpp | 2 ++ test/array2.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index d58b93a..c95bb09 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -282,6 +282,7 @@ namespace boost { 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) // // We need to return something here to keep // some compilers happy: however we will never @@ -289,6 +290,7 @@ namespace boost { // static T placeholder; return placeholder; +#endif } }; #endif diff --git a/test/array2.cpp b/test/array2.cpp index abbc745..1c8ccf8 100644 --- a/test/array2.cpp +++ b/test/array2.cpp @@ -5,6 +5,11 @@ * 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 #include #include From 9609395af0e9a256406458462fbd6285472d9431 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 4 Feb 2010 18:22:13 +0000 Subject: [PATCH 20/38] Applied patches to fix #2886 [SVN r59476] --- include/boost/array.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index c95bb09..fd2242f 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -29,6 +29,8 @@ #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' : default constructor could not be generated +# pragma warning(disable:4610) // warning C4610: class 'boost::array' can never be instantiated - user defined constructor required #endif #include From 79cadb97d70b6d4d8ed37a01922e2d8df64dcd45 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 10 Mar 2010 14:23:49 +0000 Subject: [PATCH 21/38] Changed exception throwing to use boost::throw_exception [SVN r60417] --- include/boost/array.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index fd2242f..207445d 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -168,7 +168,8 @@ namespace boost { // 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"); + std::out_of_range e("array<>: index out of range"); + boost::throw_exception(e); } } From 5e811000353020c4866fa03c471378dc7528c0fb Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 10 Mar 2010 18:03:30 +0000 Subject: [PATCH 22/38] Added support for SunCC and 'fill' operation; tickets #3893 and #3168 respectively [SVN r60436] --- include/boost/array.hpp | 22 +++++++++++++++++++--- test/array0.cpp | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 207445d..6496469 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -13,6 +13,10 @@ * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * + * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. + * See 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) @@ -80,6 +84,11 @@ namespace boost { reference, iterator, reference> > reverse_iterator; typedef std::reverse_iterator > const_reverse_iterator; +#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; #else // workaround for broken reverse_iterator implementations typedef std::reverse_iterator reverse_iterator; @@ -160,7 +169,8 @@ 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); } @@ -205,6 +215,11 @@ namespace boost { reference, iterator, reference> > reverse_iterator; typedef std::reverse_iterator > const_reverse_iterator; +#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; #else // workaround for broken reverse_iterator implementations typedef std::reverse_iterator reverse_iterator; @@ -279,8 +294,9 @@ 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"); diff --git a/test/array0.cpp b/test/array0.cpp index 065256b..92135f1 100644 --- a/test/array0.cpp +++ b/test/array0.cpp @@ -32,7 +32,7 @@ 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 From c37498364e3427f22a296484c2ebad6a90400da6 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 19 Apr 2010 21:41:21 +0000 Subject: [PATCH 23/38] Detab array.hpp [SVN r61415] --- include/boost/array.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 6496469..b14a148 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -14,8 +14,8 @@ * http://www.boost.org/LICENSE_1_0.txt) * * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. - * See or Trac issue #3168 - * Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow) + * See 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. @@ -169,7 +169,7 @@ namespace boost { } // assign one value to all elements - void assign (const T& value) { fill ( value ); } // A synonym for fill + void assign (const T& value) { fill ( value ); } // A synonym for fill void fill (const T& value) { std::fill_n(begin(),size(),value); @@ -295,8 +295,8 @@ namespace boost { // assign one value to all elements void assign (const T& value) { fill ( value ); } - void fill (const T& ) {} - + 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"); From 64e5394540dbb6b0a88124be96572b97e09f8f33 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 6 Jun 2010 16:05:13 +0000 Subject: [PATCH 24/38] Added get_c_array to Boost.Array [SVN r62487] --- include/boost/array.hpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index b14a148..5925636 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -346,6 +346,38 @@ namespace boost { x.swap(y); } + // Specific for boost::array: simply returns its elems data member. + template + T(&get_c_array(boost::array& arg))[N] + { + return arg.elems; + } + + // Const version. + template + const T(&get_c_array(const boost::array& arg))[N] + { + return arg.elems; + } + +#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 + T(&get_c_array(std::array& arg))[N] + { + return static_cast(arg); + } + + // Const version. + template + const T(&get_c_array(const std::array& arg))[N] + { + return static_cast(arg); + } +#endif + } /* namespace boost */ From 2595eda7399b4bd4ec03e70e1d968562d9bad36b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 11 Jun 2010 14:46:31 +0000 Subject: [PATCH 25/38] Removed tabs [SVN r62803] --- include/boost/array.hpp | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 5925636..7df2771 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -346,36 +346,36 @@ namespace boost { x.swap(y); } - // Specific for boost::array: simply returns its elems data member. - template - T(&get_c_array(boost::array& arg))[N] - { - return arg.elems; - } - - // Const version. - template - const T(&get_c_array(const boost::array& arg))[N] - { - return arg.elems; - } + // Specific for boost::array: simply returns its elems data member. + template + T(&get_c_array(boost::array& arg))[N] + { + return arg.elems; + } + + // Const version. + template + const T(&get_c_array(const boost::array& arg))[N] + { + return arg.elems; + } #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 - T(&get_c_array(std::array& arg))[N] - { - return static_cast(arg); - } - - // Const version. - template - const T(&get_c_array(const std::array& arg))[N] - { - return static_cast(arg); - } + // Overload for std::array, assuming that std::array will have + // explicit conversion functions as discussed at the WG21 meeting + // in Summit, March 2009. + template + T(&get_c_array(std::array& arg))[N] + { + return static_cast(arg); + } + + // Const version. + template + const T(&get_c_array(const std::array& arg))[N] + { + return static_cast(arg); + } #endif } /* namespace boost */ From 38217688e1a217d4230eba132013c1a99c19f09f Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 23 Oct 2010 19:11:16 +0000 Subject: [PATCH 26/38] Fix elems for Sun compilers [SVN r66154] --- include/boost/array.hpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 7df2771..e80080c 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -346,7 +346,8 @@ namespace boost { x.swap(y); } - // Specific for boost::array: simply returns its elems data member. +#if 0 + // Specific for boost::array: simply returns its elems data member. template T(&get_c_array(boost::array& arg))[N] { @@ -359,7 +360,29 @@ namespace boost { { return arg.elems; } +#else + namespace detail { + template struct c_array + { + typedef T type[N]; + }; + } + + // Specific for boost::array: simply returns its elems data member. + template + typename detail::c_array::type& get_c_array(boost::array& arg) + { + return arg.elems; + } + // Specific for boost::array: simply returns its elems data member. + template + const typename detail::c_array::type& get_c_array(const boost::array& arg) + { + 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 From 6fbc8ee741264cd12d7be8e0d638494b5c57c658 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 31 Oct 2010 02:25:04 +0000 Subject: [PATCH 27/38] Added a test for 'get_c_array' [SVN r66294] --- test/Jamfile.v2 | 1 + test/array6.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/array6.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 1379a5b..2deb3d5 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,4 +11,5 @@ test-suite array : [ run array3.cpp ] [ run array4.cpp ] [ run array5.cpp ] + [ run array6.cpp ] ; diff --git a/test/array6.cpp b/test/array6.cpp new file mode 100644 index 0000000..aaeed2d --- /dev/null +++ b/test/array6.cpp @@ -0,0 +1,47 @@ +/* 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 +#include +#include +#include + +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 ); + if ( &*test_case.begin () != &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; +} + From 80fa50df2ef90e1374c7ea82ec3959998321feff Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 20 Nov 2010 00:48:33 +0000 Subject: [PATCH 28/38] SunPro workaround; references #4757 [SVN r66651] --- include/boost/array.hpp | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index e80080c..0a197b1 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -346,21 +346,12 @@ namespace boost { x.swap(y); } -#if 0 - // Specific for boost::array: simply returns its elems data member. - template - T(&get_c_array(boost::array& arg))[N] - { - return arg.elems; - } - - // Const version. - template - const T(&get_c_array(const boost::array& arg))[N] - { - return arg.elems; - } -#else +#if defined(__SUNPRO_CC) +// Trac ticket #4757; the Sun Solaris compiler can't handle +// syntax like 'T(&get_c_array(boost::array& arg))[N]' +// +// We can't just use this for all compilers, because the +// borland compilers can't handle this form. namespace detail { template struct c_array { @@ -381,6 +372,20 @@ namespace boost { { return arg.elems; } +#else +// Specific for boost::array: simply returns its elems data member. + template + T(&get_c_array(boost::array& arg))[N] + { + return arg.elems; + } + + // Const version. + template + const T(&get_c_array(const boost::array& arg))[N] + { + return arg.elems; + } #endif #if 0 From 5329bd6f1cad8189d603a32edc056f111baf36e3 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 24 Nov 2010 16:13:12 +0000 Subject: [PATCH 29/38] Slight tweak of get_c_array [SVN r66712] --- include/boost/array.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 0a197b1..a5bee24 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -368,7 +368,7 @@ namespace boost { // Specific for boost::array: simply returns its elems data member. template - const typename detail::c_array::type& get_c_array(const boost::array& arg) + typename const detail::c_array::type& get_c_array(const boost::array& arg) { return arg.elems; } From 72568827606c49724742e0b220e7bcf396dcd774 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 26 Nov 2010 20:16:34 +0000 Subject: [PATCH 30/38] Fix? for borland [SVN r66781] --- test/array6.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/array6.cpp b/test/array6.cpp index aaeed2d..388b39f 100644 --- a/test/array6.cpp +++ b/test/array6.cpp @@ -30,7 +30,8 @@ void RunTests() fail_test ( "Array6: Same thing not equal?(1)" ); const arr &caRef = get_c_array ( test_case ); - if ( &*test_case.begin () != &caRef[0] ) + typename test_type::const_iterator iter = test_case.begin (); + if ( &*iter != &caRef[0] ) fail_test ( "Array6: Same thing not equal?(2)" ); } From 05aa660128d7023a005482f5b49fa93c158df09b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 28 Dec 2010 18:39:14 +0000 Subject: [PATCH 31/38] Added cbegin and cend to Boost.Array; refs #4761. Will close ticket when merged to release branch [SVN r67478] --- include/boost/array.hpp | 23 +++++++++++++++-------- test/array0.cpp | 8 ++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index a5bee24..c34478b 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -13,6 +13,7 @@ * 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 for C++Ox compatibility. * 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group. * See or Trac issue #3168 * Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow) @@ -69,10 +70,13 @@ 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) @@ -200,10 +204,13 @@ 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) diff --git a/test/array0.cpp b/test/array0.cpp index 92135f1..d75db76 100644 --- a/test/array0.cpp +++ b/test/array0.cpp @@ -56,9 +56,15 @@ void RunTests() 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" ); @@ -73,8 +79,10 @@ void RunTests() // 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 ); From 97e912e82e35609c39a52df15e3de68bd7700804 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 28 Dec 2010 19:14:23 +0000 Subject: [PATCH 32/38] Added crbegin and crend to Boost.Array; refs #4761. Will close ticket when merged to release branch [SVN r67481] --- include/boost/array.hpp | 16 +++++++++++++++- test/array3.cpp | 7 +++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index c34478b..363493b 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -13,7 +13,7 @@ * 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 for C++Ox compatibility. + * 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 or Trac issue #3168 * Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow) @@ -103,10 +103,17 @@ 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) @@ -237,10 +244,17 @@ 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*/) diff --git a/test/array3.cpp b/test/array3.cpp index b815fe7..29aacb1 100644 --- a/test/array3.cpp +++ b/test/array3.cpp @@ -39,6 +39,13 @@ int main() =seasons.rbegin(); pos::const_reverse_iterator pos + =seasons.crbegin(); pos Date: Fri, 14 Jan 2011 02:59:34 +0000 Subject: [PATCH 33/38] Pathscale-4.0 configuration code/workarounds. [SVN r68142] --- include/boost/array.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 363493b..0628c89 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -322,7 +322,7 @@ namespace boost { 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) +#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 From 111e93aa4cdb5e75443af1591fe11550b3560e1d Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 26 Feb 2011 01:35:48 +0000 Subject: [PATCH 34/38] qualify array to avoid conflict with std::array; Refs #5233 [SVN r69291] --- test/array2.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/array2.cpp b/test/array2.cpp index 1c8ccf8..b33e0b5 100644 --- a/test/array2.cpp +++ b/test/array2.cpp @@ -15,12 +15,11 @@ #include #include "print.hpp" using namespace std; -using namespace boost; int main() { // create and initialize array - array a = { { 1, 2, 3, 4, 5 } }; + boost::array a = { { 1, 2, 3, 4, 5 } }; print_elements(a); From e6a44cf5296249b762c9ba5ff43a2b6989f1013b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 22 Mar 2011 23:55:20 +0000 Subject: [PATCH 35/38] Removed tabs [SVN r70442] --- include/boost/array.hpp | 16 ++++++++-------- test/array6.cpp | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 0628c89..ffb504b 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -368,17 +368,17 @@ namespace boost { } #if defined(__SUNPRO_CC) -// Trac ticket #4757; the Sun Solaris compiler can't handle -// syntax like 'T(&get_c_array(boost::array& arg))[N]' -// -// We can't just use this for all compilers, because the -// borland compilers can't handle this form. - namespace detail { +// Trac ticket #4757; the Sun Solaris compiler can't handle +// syntax like 'T(&get_c_array(boost::array& arg))[N]' +// +// We can't just use this for all compilers, because the +// borland compilers can't handle this form. + namespace detail { template struct c_array { typedef T type[N]; }; - } + } // Specific for boost::array: simply returns its elems data member. template @@ -408,7 +408,7 @@ namespace boost { 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 diff --git a/test/array6.cpp b/test/array6.cpp index 388b39f..658cec6 100644 --- a/test/array6.cpp +++ b/test/array6.cpp @@ -26,13 +26,13 @@ void RunTests() 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)" ); + 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)" ); } } From 992299f2bf63290b466b104395347e114bb81da5 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 28 Feb 2012 18:47:28 +0000 Subject: [PATCH 36/38] Use BOOST_ASSERT_MSG instead of naked BOOST_ASSERT [SVN r77135] --- include/boost/array.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/array.hpp b/include/boost/array.hpp index ffb504b..61d50e7 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -118,13 +118,13 @@ namespace boost { // 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]; } From f4a0cbd36412ed345bb38af90dd02325657cb5eb Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sat, 14 Apr 2012 18:07:34 +0000 Subject: [PATCH 37/38] Added support for Boost.Hash to Boost.Array; fixes #6791 [SVN r77976] --- include/boost/array.hpp | 9 ++++++++ test/Jamfile.v2 | 1 + test/array_hash.cpp | 49 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test/array_hash.cpp diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 61d50e7..fa06fa9 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -13,6 +13,7 @@ * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * + * 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 or Trac issue #3168 @@ -46,6 +47,7 @@ // Handles broken standard libraries better than #include #include +#include #include // FIXES for broken compilers @@ -427,6 +429,13 @@ namespace boost { } #endif + + template + std::size_t hash_value(const array& arr) + { + return boost::hash_range(arr.begin(), arr.end()); + } + } /* namespace boost */ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 2deb3d5..a09ba68 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -12,4 +12,5 @@ test-suite array : [ run array4.cpp ] [ run array5.cpp ] [ run array6.cpp ] + [ run array_hash.cpp ] ; diff --git a/test/array_hash.cpp b/test/array_hash.cpp new file mode 100644 index 0000000..474e29c --- /dev/null +++ b/test/array_hash.cpp @@ -0,0 +1,49 @@ +/* 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 +#include +#include +#include +#include + +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() +{ +// std::size_t hash0 = boost::hash > () ( boost::array ()); +// std::size_t hash1 = boost::hash > () ( boost::array ()); + + 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 () ( test_barr ); + std::size_t ahash = boost::hash () ( test_arr ); + if ( ahash != bhash ) + fail_test ( "Array_hash: Hash-mismatch on " ); +} + +} + +int main() +{ + RunTests< int >(); + RunTests< long >(); + RunTests< long double >(); + + return failed_tests; +} + From f41b1d2d4cc3eef150625cf08c6e8ffd292ecca8 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 14 Jun 2012 15:52:44 +0000 Subject: [PATCH 38/38] Added a note about std::array in C++11 [SVN r78947] --- doc/array.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/array.xml b/doc/array.xml index fca63a6..62bf7c2 100644 --- a/doc/array.xml +++ b/doc/array.xml @@ -70,6 +70,11 @@ Technical Report, which will extend the C++ Standard (see http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm). + Update: std::array is (as of C++11) part of the C++ standard. + The differences between boost::array and std::array are minimal. + If you are using C++11, you should consider using std::array instead of boost::array. + + Class array fulfills most but not all of the requirements of "reversible containers" (see Section 23.1, [lib.container.requirements] of the C++