From 25e959e4a91d6a0c6a09aa8175e4756beccae5d8 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 13 Sep 2005 14:20:32 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'thread_rewrite'. [SVN r30953] --- array1.cpp | 58 ------ array2.cpp | 40 ---- array3.cpp | 55 ----- array4.cpp | 43 ---- array5.cpp | 72 ------- doc/array.xml | 546 -------------------------------------------------- index.html | 9 - print.hpp | 27 --- 8 files changed, 850 deletions(-) delete mode 100644 array1.cpp delete mode 100644 array2.cpp delete mode 100644 array3.cpp delete mode 100644 array4.cpp delete mode 100644 array5.cpp delete mode 100644 doc/array.xml delete mode 100644 index.html delete mode 100644 print.hpp diff --git a/array1.cpp b/array1.cpp deleted file mode 100644 index 740968f..0000000 --- a/array1.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* simple example for using class array<> - * - * (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) - * - * Changelog: - * 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it - * (David Abrahams) - */ - -#include -#include - -int main() -{ - // define special type name - typedef boost::array Array; - - // create and initialize an array - Array a = { { 42 } }; - - // access elements - for (unsigned i=1; i - * (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) - */ - -#include -#include -#include -#include "print.hpp" -using namespace std; -using namespace boost; - -int main() -{ - // create and initialize array - array a = { { 1, 2, 3, 4, 5 } }; - - print_elements(a); - - // modify elements directly - for (unsigned i=0; i()); // operation - print_elements(a); - - return 0; // makes Visual-C++ compiler happy -} - diff --git a/array3.cpp b/array3.cpp deleted file mode 100644 index a4eac5d..0000000 --- a/array3.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* example for using class array<> - * (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) - */ - -#include -#include -#include - -template -void print_elements (const T& x); - -int main() -{ - // create array of four seasons - boost::array seasons = { - { "spring", "summer", "autumn", "winter" } - }; - - // copy and change order - boost::array seasons_orig = seasons; - for (unsigned i=seasons.size()-1; i>0; --i) { - std::swap(seasons.at(i),seasons.at((i+1)%seasons.size())); - } - - std::cout << "one way: "; - print_elements(seasons); - - // try swap() - std::cout << "other way: "; - std::swap(seasons,seasons_orig); - print_elements(seasons); - - // try reverse iterators - std::cout << "reverse: "; - for (boost::array::reverse_iterator pos - =seasons.rbegin(); pos -void print_elements (const T& x) -{ - for (unsigned i=0; i - * (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) - */ - -#include -#include -#include -#include -#include - -int main() -{ - // array of arrays of seasons - boost::array,2> seasons_i18n = { - { { { "spring", "summer", "autumn", "winter", } }, - { { "Fruehling", "Sommer", "Herbst", "Winter" } } - } - }; - - // for any array of seasons print seasons - for (unsigned i=0; i seasons = seasons_i18n[i]; - for (unsigned j=0; j - * (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) - */ - -#include -#include - -template -void test_static_size (const T& cont) -{ - int tmp[T::static_size]; - for (unsigned i=0; i Array; - - // create and initialize an array - const Array a = { { 42.42 } }; - - // use some common STL container operations - std::cout << "static_size: " << a.size() << std::endl; - std::cout << "size: " << a.size() << std::endl; - // Can't use std::boolalpha because it isn't portable - std::cout << "empty: " << (a.empty()? "true" : "false") << std::endl; - std::cout << "max_size: " << a.max_size() << std::endl; - std::cout << "front: " << a.front() << std::endl; - std::cout << "back: " << a.back() << std::endl; - std::cout << "[0]: " << a[0] << std::endl; - std::cout << "elems: "; - - // iterate through all elements - for (Array::const_iterator pos=a.begin(); pos DArray; - typedef boost::array IArray; - IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning - DArray da; - da = ia; - da.assign(42); - - return 0; // makes Visual-C++ compiler happy -} - diff --git a/doc/array.xml b/doc/array.xml deleted file mode 100644 index 414dd79..0000000 --- a/doc/array.xml +++ /dev/null @@ -1,546 +0,0 @@ - - - - - - Nicolai - Josuttis - - - - 2001 - 2002 - 2003 - 2004 - Nicolai M. Josuttis - - - - 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. - - - STL compliant container wrapper for arrays of constant size - - - - Boost.Array - -
- Introduction - - - - - The C++ Standard Template Library STL as part of the C++ - Standard Library provides a framework for processing algorithms on - different kind of containers. However, ordinary arrays don't - provide the interface of STL containers (although, they provide - the iterator interface of STL containers). - - As replacement for ordinary arrays, the STL provides class - std::vector. However, - std::vector<> provides - the semantics of dynamic arrays. Thus, it manages data to be able - to change the number of elements. This results in some overhead in - case only arrays with static size are needed. - - In his book, Generic Programming and the - STL, Matthew H. Austern introduces a useful wrapper - class for ordinary arrays with static size, called - block. It is safer and has no worse performance than - ordinary arrays. In The C++ Programming - Language, 3rd edition, Bjarne Stroustrup introduces a - similar class, called c_array, which I (Nicolai Josuttis) present - slightly modified in my book The C++ Standard Library - - A Tutorial and Reference, called - carray. This is the essence of these approaches - spiced with many feedback from boost. - - After considering different names, we decided to name this - class simply array. - - Note that this class is suggested to be part of the next - Technical Report, which will extend the C++ Standard (see - http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1548.htm). - - Class array fulfills most - but not all of the requirements of "reversible containers" (see - Section 23.1, [lib.container.requirements] of the C++ - Standard). The reasons array is not an reversible STL container is - because: - - No constructors are provided. - Elements may have an undetermined initial value (see ). - swap() has no constant complexity. - size() is always constant, based on the second template argument of the type. - The container provides no allocator support. - - - - It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that: - - front() and back() are provided. - operator[] and at() are provided. - - -
- - -
- - - - - STL compliant container wrapper for arrays of constant size - - T - - - T* - - - const T* - - - std::reverse_iterator<iterator> - - - std::reverse_iterator<const_iterator> - - - T& - - - const T& - - - std::size_t - - - std::ptrdiff_t - - - - size_type - N - - - - - - const array<U, N>& - - std::copy(rhs.begin(),rhs.end(), begin()) - - - - - - iterator - - - const_iterator - - - iterator for the first element - will not throw - - - - - iterator - - - const_iterator - - - iterator for position after the last element - will not throw - - - - - - - reverse_iterator - - - const_reverse_iterator - - - reverse iterator for the first element of reverse iteration - - - - - reverse_iterator - - - const_reverse_iterator - - - reverse iterator for position after the last element in reverse iteration - - - - - - size_type - N - - - bool - N==0 - will not throw - - - size_type - N - will not throw - - - - - - - reference - - size_type - - - - - const_reference - - size_type - - - - i < N - element with index i - will not throw. - - - - - reference - - size_type - - - - - const_reference - - size_type - - - - element with index i - std::range_error if i >= N - - - - - reference - - - const_reference - - N > 0 - the first element - will not throw - - - - - reference - - - const_reference - - N > 0 - the last element - will not throw - - - - const T* - elems - will not throw - - - - T* - elems - will not throw - - - - - - void - - array<T, N>& - - std::swap_ranges(begin(), end(), other.begin()) - linear in N - - - void - - const T& - - std::fill_n(begin(), N, value) - - - - - T - - - - - - - void - - - array<T, N>& - - - array<T, N>& - - - x.swap(y) - will not throw. - - - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - std::equal(x.begin(), x.end(), y.begin()) - - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - !(x == y) - - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()) - - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - y < x - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - !(y < x) - - - - - - bool - - - const array<T, N>& - - - const array<T, N>& - - - !(x < y) - - - - -
-
- -
- Design Rationale - - There was an important design tradeoff regarding the - constructors: We could implement array as an "aggregate" (see - Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would - mean: - - An array can be initialized with a - brace-enclosing, comma-separated list of initializers for the - elements of the container, written in increasing subscript - order: - - boost::array<int,4> a = { { 1, 2, 3 } }; - - Note that if there are fewer elements in the - initializer list, then each remaining element gets - default-initialized (thus, it has a defined value). - - - However, this approach has its drawbacks: passing no initializer list means that the elements - have an indetermined initial value, because the rule says - that aggregates may have: - - No user-declared constructors. - No private or protected non-static data members. - No base classes. - No virtual functions. - - - - Nevertheless, The current implementation uses this approach. - - Note that for standard conforming compilers it is possible to - use fewer braces (according to 8.5.1 (11) of the Standard). That is, - you can initialize an array as follows: - - -boost::array<int,4> a = { 1, 2, 3 }; - - - I'd appreciate any constructive feedback. Please note: I don't have time to read all boost - mails. Thus, to make sure that feedback arrives to me, please send - me a copy of each mail regarding this class. - - The code is provided "as is" without expressed or implied - warranty. - -
- -
- For more information... - To find more details about using ordinary arrays in C++ and - the framework of the STL, see e.g. - - The C++ Standard Library - A Tutorial and Reference -by Nicolai M. Josuttis -Addison Wesley Longman, 1999 -ISBN 0-201-37926-0 - - - Home Page of Nicolai - Josuttis -
- -
- Acknowledgements - - Doug Gregor ported the documentation to the BoostBook format. -
- - - -
diff --git a/index.html b/index.html deleted file mode 100644 index 588f27e..0000000 --- a/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - -Automatic redirection failed, please go to -../../doc/html/array.html - - diff --git a/print.hpp b/print.hpp deleted file mode 100644 index 6d68e8e..0000000 --- a/print.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* The following code example is taken from the book - * "The C++ Standard Library - A Tutorial and Reference" - * by Nicolai M. Josuttis, Addison-Wesley, 1999 - * - * (C) Copyright Nicolai M. Josuttis 1999. - * 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 - -/* print_elements() - * - prints optional C-string optcstr followed by - * - all elements of the collection coll - * - separated by spaces - */ -template -inline void print_elements (const T& coll, const char* optcstr="") -{ - typename T::const_iterator pos; - - std::cout << optcstr; - for (pos=coll.begin(); pos!=coll.end(); ++pos) { - std::cout << *pos << ' '; - } - std::cout << std::endl; -}