From 99c3a4b9664a5e70cef034e3bc57d620675e5ff3 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Wed, 18 Dec 2024 15:31:13 -0800 Subject: [PATCH] refactor documentation to use asciidoc --- doc/.gitignore | 1 + doc/Jamfile.v2 | 23 +- doc/array.adoc | 28 ++ doc/array.xml | 639 -------------------------------- doc/array/copyright.adoc | 15 + doc/array/design_rationale.adoc | 43 +++ doc/array/information.adoc | 22 ++ doc/array/introduction.adoc | 37 ++ doc/array/reference.adoc | 418 +++++++++++++++++++++ 9 files changed, 574 insertions(+), 652 deletions(-) create mode 100644 doc/.gitignore create mode 100644 doc/array.adoc delete mode 100644 doc/array.xml create mode 100644 doc/array/copyright.adoc create mode 100644 doc/array/design_rationale.adoc create mode 100644 doc/array/information.adoc create mode 100644 doc/array/introduction.adoc create mode 100644 doc/array/reference.adoc diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 0000000..35b5e99 --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1 @@ +/html diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index b7f51b7..7087c6c 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -1,19 +1,16 @@ #~ Copyright Marshall Clow 2013 +#~ Copyright Christian Mazakas 2024 #~ 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) -using boostbook ; +import asciidoctor ; -boostbook standalone - : array.xml - : boost.root=../../../.. ; +html array.html : array.adoc ; -############################################################################### -alias boostdoc - : array.xml - : - : - : ; -explicit boostdoc ; -alias boostrelease ; -explicit boostrelease ; +install html_ : array.html : html ; + +pdf array.pdf : array.adoc ; +explicit array.pdf ; + +install pdf_ : array.pdf : pdf ; +explicit pdf_ ; diff --git a/doc/array.adoc b/doc/array.adoc new file mode 100644 index 0000000..d6292b5 --- /dev/null +++ b/doc/array.adoc @@ -0,0 +1,28 @@ +//// +Copyright 2001-2004 Nicolai M. Josuttis +Copyright 2012 Marshall Clow +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +# Array +Nicolai M. Josuttis +:toc: left +:toclevels: 4 +:idprefix: +:docinfo: private-footer +:source-highlighter: rouge +:source-language: c++ +:sectanchors: + +:leveloffset: +1 + + +include::array/introduction.adoc[] +include::array/reference.adoc[] +include::array/design_rationale.adoc[] +include::array/information.adoc[] +include::array/copyright.adoc[] + +:leveloffset: -1 diff --git a/doc/array.xml b/doc/array.xml deleted file mode 100644 index 68ee5a3..0000000 --- a/doc/array.xml +++ /dev/null @@ -1,639 +0,0 @@ - - - - - - Nicolai - Josuttis - - - Marshall - Clow - - - - 2001 - 2002 - 2003 - 2004 - Nicolai M. Josuttis - - - - 2012 - Marshall Clow - - - - 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 - - - - 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://www.open-std.org/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++ - 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 - - - - - const_iterator - - - constant iterator for the first element - will not throw - - - - - const_iterator - - - constant 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 - - - - - const_reverse_iterator - - - constant reverse iterator for the first element of reverse iteration - will not throw - - - - - const_reverse_iterator - - - constant reverse iterator for position after the last element in reverse iteration - will not throw - - - - - - 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) - - - - - - - - T - - - array<T, N>& - - element of array with index Idx - Will static_assert if Idx >= N - - - - - - T - - - const array<T, N>& - - const element of array with index Idx - Will static_assert if Idx >= N - - - - - -
-
- -
- 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/doc/array/copyright.adoc b/doc/array/copyright.adoc new file mode 100644 index 0000000..f04e3a8 --- /dev/null +++ b/doc/array/copyright.adoc @@ -0,0 +1,15 @@ +//// +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +[#copyright] +# Copyright and License +:idprefix: copyright + +Copyright (C) 2001-2004 Nicolai M. Josuttis + +Copyright (C) 2012 Marshall Clow + +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) diff --git a/doc/array/design_rationale.adoc b/doc/array/design_rationale.adoc new file mode 100644 index 0000000..bedc0a0 --- /dev/null +++ b/doc/array/design_rationale.adoc @@ -0,0 +1,43 @@ +//// +Copyright 2001-2004 Nicolai M. Josuttis +Copyright 2012 Marshall Clow +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +[#design] +# Design Rationale +:idprefix: design_ +:cpp: C++ + +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: ++ +-- +```cpp +boost::array 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: + +```cpp +boost::array 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. diff --git a/doc/array/information.adoc b/doc/array/information.adoc new file mode 100644 index 0000000..ca8b1a8 --- /dev/null +++ b/doc/array/information.adoc @@ -0,0 +1,22 @@ +//// +Copyright 2001-2004 Nicolai M. Josuttis +Copyright 2012 Marshall Clow +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +[#information] +# For more information... +:idprefix: information_ +:cpp: C++ + +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 + + +http://www.josuttis.com/[Home Page of Nicolai Josuttis] diff --git a/doc/array/introduction.adoc b/doc/array/introduction.adoc new file mode 100644 index 0000000..9330a8f --- /dev/null +++ b/doc/array/introduction.adoc @@ -0,0 +1,37 @@ +//// +Copyright 2001-2004 Nicolai M. Josuttis +Copyright 2012 Marshall Clow +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +[#introduction] +# Introduction +:idprefix: introduction_ +:cpp: C++ + +The {cpp} Standard Template Library STL as part of the {cpp} 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 {cpp} Programming Language_, 3rd edition, Bjarne Stroustrup introduces a similar class, called c_array, which I (http://www.josuttis.com/[Nicolai Josuttis]) present slightly modified in my book _The {cpp} Standard Library - A Tutorial and Reference_, called `carray`. This is the essence of these approaches spiced with many feedback from https://www.boost.org/[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 {cpp} Standard (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm). + +Update: `std::array` is (as of {cpp}11) part of the {cpp} standard. The differences between `boost::array` and `std::array` are minimal. If you are using {cpp}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 {cpp} Standard). The reasons array is not an reversible STL container is because: + +* No constructors are provided. +* Elements may have an undetermined initial value (see the <>). +* `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 {cpp} Standard), except that: + +* `front()` and `back()` are provided. +* `operator[]` and `at()` are provided. diff --git a/doc/array/reference.adoc b/doc/array/reference.adoc new file mode 100644 index 0000000..bde9266 --- /dev/null +++ b/doc/array/reference.adoc @@ -0,0 +1,418 @@ +//// +Copyright 2001-2004 Nicolai M. Josuttis +Copyright 2012 Marshall Clow +Copyright 2024 Christian Mazakas +Distributed under the Boost Software License, Version 1.0. +https://www.boost.org/LICENSE_1_0.txt +//// + +[#reference] +# Reference +:idprefix: reference_ +:cpp: C++ + +## Header + +```cpp +namespace boost { + template class array; + template void swap(array&, array&); + template + bool operator==(const array&, const array&); + template + bool operator!=(const array&, const array&); + template + bool operator<(const array&, const array&); + template + bool operator>(const array&, const array&); + template + bool operator<=(const array&, const array&); + template + bool operator>=(const array&, const array&); + template + T boost::get(array&); + template + T boost::get(const array&); +} +``` + +## Class template array + +### Synopsis + +```cpp +// In header: + +template +class array { +public: + // types + typedef T value_type; + typedef T* iterator; + typedef const T* const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + // static constants + static const size_type static_size = N; + + // construct/copy/destruct + template array& operator=(const array&); + + // iterator support + iterator begin(); + const_iterator begin() const; + iterator end(); + const_iterator end() const; + const_iterator cbegin(); + const_iterator cend(); + + // reverse iterator support + reverse_iterator rbegin(); + const_reverse_iterator rbegin() const; + reverse_iterator rend(); + const_reverse_iterator rend() const; + const_reverse_iterator crbegin(); + const_reverse_iterator crend(); + + // capacity + size_type size(); + bool empty(); + size_type max_size(); + + // element access + reference operator[](size_type); + const_reference operator[](size_type) const; + reference at(size_type); + const_reference at(size_type) const; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + const T* data() const; + T* c_array(); + + // modifiers + void swap(array&); + void assign(const T&); + + // public data members + T elems[N]; +}; + +// specialized algorithms +template void swap(array&, array&); + +// comparisons +template + bool operator==(const array&, const array&); +template + bool operator!=(const array&, const array&); +template + bool operator<(const array&, const array&); +template + bool operator>(const array&, const array&); +template + bool operator<=(const array&, const array&); +template + bool operator>=(const array&, const array&); + +// specializations +template + T boost::get(array&); +template + T boost::get(const array&); +``` + +### Description + +#### array public construct/copy/destruct + +``` +template array& operator=(const array& other); +``` +[horizontal] +Effects: :: `std::copy(rhs.begin(), rhs.end(), begin())` + +--- + +#### array iterator support + +``` +iterator begin(); +const_iterator begin() const; +``` +[horizontal] +Returns: :: iterator for the first element +Throws: :: will not throw + +--- + +``` +iterator end(); +const_iterator end() const; +``` +[horizontal] +Returns: :: iterator for position after the last element +Throws: :: will not throw + +--- + +``` +const_iterator cbegin(); +``` +[horizontal] +Returns: :: constant iterator for the first element +Throws: :: will not throw + +--- + +``` +const_iterator cend(); +``` +[horizontal] +Returns: :: constant iterator for position after the last element +Throws: :: will not throw + +--- + +#### array reverse iterator support + +``` +reverse_iterator rbegin(); +const_reverse_iterator rbegin() const; +``` +[horizontal] +Returns: :: reverse iterator for the first element of reverse iteration + +--- + +``` +reverse_iterator rend(); +const_reverse_iterator rend() const; +``` +[horizontal] +Returns: :: reverse iterator for position after the last element in reverse iteration + +--- + +``` +const_reverse_iterator crbegin(); +``` +[horizontal] +Returns: :: constant reverse iterator for the first element of reverse iteration +Throws: :: will not throw + +--- + +``` +const_reverse_iterator crend(); +``` +[horizontal] +Returns: :: constant reverse iterator for position after the last element in reverse iteration +Throws: :: will not throw + +--- + +#### array capacity + +``` +size_type size(); +``` +[horizontal] +Returns: :: `N` + +--- + +``` +bool empty(); +``` +[horizontal] +Returns: :: `N==0` +Throws: :: will not throw + +--- + +``` +size_type max_size(); +``` +[horizontal] +Returns: :: `N` +Throws: :: will not throw + +--- + +#### array element access + +``` +reference operator[](size_type i); +const_reference operator[](size_type i) const; +``` +[horizontal] +Requires: :: `i < N` +Returns: :: element with index `i` +Throws: :: will not throw. + +--- + +``` +reference at(size_type i); +const_reference at(size_type i) const; +``` +[horizontal] +Returns: :: element with index `i` +Throws: :: `std::range_error` if `i >= N` + +--- + +``` +reference front(); +const_reference front() const; +``` +[horizontal] +Requires: :: `N > 0` +Returns: :: the first element +Throws: :: will not throw + +--- + +``` +reference back(); +const_reference back() const; +``` +[horizontal] +Requires: :: `N > 0` +Returns: :: the last element +Throws: :: will not throw + +--- + +``` +const T* data() const; +``` +[horizontal] +Returns: :: `elems` +Throws: :: will not throw + +--- + +``` +T* c_array(); +``` +[horizontal] +Returns: :: `elems` +Throws: :: will not throw + +--- + +#### array modifiers + +``` +void swap(array& other); +``` +[horizontal] +Effects: :: `std::swap_ranges(begin(), end(), other.begin())` +Complexity: :: linear in `N` + +--- + +``` +void assign(const T& value); +``` +[horizontal] +Effects: :: `std::fill_n(begin(), N, value)` + +--- + +#### array specialized algorithms + +``` +template void swap(array& x, array& y); +``` +[horizontal] +Effects: :: `x.swap(y)` +Throws: :: will not throw. + +--- + +#### array comparisons + +``` +template + bool operator==(const array& x, const array& y); +``` +[horizontal] +Returns: :: `std::equal(x.begin(), x.end(), y.begin())` + +--- + +``` +template + bool operator!=(const array& x, const array& y); +``` +[horizontal] +Returns: :: `!(x == y)` + +--- + +``` +template + bool operator<(const array& x, const array& y); +``` +[horizontal] +Returns: :: `std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end())` + +--- + +``` +template + bool operator>(const array& x, const array& y); +``` +[horizontal] +Returns: :: `y < x` + +--- + +``` +template + bool operator<=(const array& x, const array& y); +``` +[horizontal] +Returns: :: `!(y < x)` + +--- + +``` +template + bool operator>=(const array& x, const array& y); +``` +[horizontal] +Returns: :: `!(x < y)` + +--- + +#### array specializations + +``` +template + T boost::get(array& arr); +``` +[horizontal] +Returns: :: element of array with index `Idx` +Effects: :: Will `static_assert` if `Idx >= N` + +--- + +``` +template + T boost::get(const array& arr); +``` +[horizontal] +Returns: :: const element of array with index `Idx` +Effects: :: Will `static_assert` if `Idx >= N` + +---