Compare commits

...

76 Commits

Author SHA1 Message Date
Peter Dimov
e988ef9c4a Merge pull request #28 from ashtum/patch-1
Update index.html
2025-04-03 14:10:17 +03:00
Mohammad Nejati
a0be8d9537 Update index.html 2025-04-03 14:25:37 +03:30
Peter Dimov
eee0d5bbc5 Update documentation 2025-02-23 22:02:50 +02:00
Peter Dimov
ec61272c1f Remove stray parentheses 2025-02-23 21:04:28 +02:00
Peter Dimov
e97dc53868 Add to_array_test_cx.cpp 2025-02-23 20:59:49 +02:00
Peter Dimov
ffbced7a17 Disable initializer list test for GCC < 4.9 and Clang < 3.8 2025-02-23 20:54:43 +02:00
Peter Dimov
37289c5d92 Add to_array 2025-02-23 20:45:50 +02:00
Peter Dimov
9b508e3ad2 Disable <=> tests when <compare> isn't available 2025-01-29 04:26:00 +02:00
Peter Dimov
84d0f84c9b Check for the existence of <compare>, include it, use it; 0 <=> 0 doesn't work without it anyway. 2025-01-29 04:03:41 +02:00
Peter Dimov
37a4833e26 Add the rest of the Clangs to Drone 2025-01-29 03:14:12 +02:00
Peter Dimov
8991751e3b Regenerate CMakeLists.txt 2025-01-27 21:22:01 +02:00
Peter Dimov
b2f6f0ca65 Update build.jam 2025-01-27 21:21:34 +02:00
Peter Dimov
703ad46b81 Fix test/Jamfile project requirements 2025-01-27 21:18:15 +02:00
Peter Dimov
7482efd0a1 Merge branch 'modular' of https://github.com/grafikrobot/boostorg.array into feature/pr-24 2025-01-27 21:16:20 +02:00
Peter Dimov
61bbcbf341 Disable warnings for compile-fail tests 2025-01-27 19:53:31 +02:00
Peter Dimov
59e9940d5b Suppress false -Warray-bounds positive with -fsanitize=undefined 2025-01-27 19:53:16 +02:00
Peter Dimov
771750f7e1 Supress GCC and Clang warnings 2025-01-27 19:00:30 +02:00
Peter Dimov
75db85d1e9 Suppress MSVC unreachable code warnings 2025-01-27 18:23:43 +02:00
Peter Dimov
49e2a46c3a Enable warnings=extra, warnings-as-errors=on in test suite 2025-01-27 17:41:50 +02:00
Peter Dimov
07a14f33ef Update revision history 2025-01-27 17:19:06 +02:00
Peter Dimov
047ba01807 Update documentation 2025-01-27 17:16:50 +02:00
Peter Dimov
45de3be80c Add array_thw_test_cx.cpp 2025-01-27 04:03:06 +02:00
Peter Dimov
68db6ebd2d Add operator<=> overload for zero-sized arrays 2025-01-27 03:59:32 +02:00
Peter Dimov
329e59454f Add float tests to array_thw_test, as floats use std::partial_ordering 2025-01-27 03:55:13 +02:00
Peter Dimov
9a4010b88b Add operator<=>, array_thw_test.cpp 2025-01-27 03:40:19 +02:00
Peter Dimov
527ff0a80d Update revision history 2025-01-26 22:07:42 +02:00
Peter Dimov
f017dac435 Enable failing tests 2025-01-26 21:26:46 +02:00
Peter Dimov
567ba40840 Add a dummy element to array<T, 0> to enable initialization with = {{}} 2025-01-26 21:15:39 +02:00
Peter Dimov
29700ff270 Update revision history 2025-01-26 21:02:26 +02:00
Peter Dimov
b147799665 Remove local hash_value overload; boost::hash supports array-like types natively. 2025-01-26 20:35:19 +02:00
Peter Dimov
acef60446a Update revision history 2025-01-26 20:31:53 +02:00
Peter Dimov
3d9f39814c Re-enable failing tests 2025-01-26 19:23:41 +02:00
Peter Dimov
89f09e33f1 Change array<T, 0>::begin() to return nullptr and make it constexpr. 2025-01-26 19:21:39 +02:00
Peter Dimov
43326390d9 Reenable failing test 2025-01-26 08:19:00 +02:00
Peter Dimov
c95d855018 Remove obsolete workaround from failed_rangecheck 2025-01-26 08:09:41 +02:00
Peter Dimov
0a72026887 Update revision history 2025-01-26 06:09:05 +02:00
Peter Dimov
d2c295b85f Add array_access_test_cx2.cpp 2025-01-26 05:53:09 +02:00
Peter Dimov
324827cfc0 Add array_assign_test_cx.cpp 2025-01-26 05:45:36 +02:00
Peter Dimov
9253e8f1af Add array_fill_test_cx.cpp 2025-01-26 05:41:56 +02:00
Peter Dimov
cd0532b8fa Remove inclusion of <algorithm> 2025-01-26 05:08:42 +02:00
Peter Dimov
6a9e8c78da Update documentation of swap. 2025-01-26 04:11:14 +02:00
Peter Dimov
55bc631d40 Remove use of core/invoke_swap 2025-01-26 04:08:06 +02:00
Peter Dimov
435b293467 Mark std::get illegal overloads as deprecated 2025-01-26 03:16:23 +02:00
Peter Dimov
6447b408b2 Remove idef-ed out overload of get_c_array 2025-01-26 03:10:59 +02:00
Peter Dimov
17b49d86ad Mark get_c_array as deprecated 2025-01-26 03:10:23 +02:00
Peter Dimov
fe60e163c7 Remove obsolete Sun workaround 2025-01-26 03:07:53 +02:00
Peter Dimov
16280f660b Mark assign as deprecated 2025-01-26 03:06:28 +02:00
Peter Dimov
16b6ba8d84 Mark c_array as deprecated 2025-01-25 23:20:31 +02:00
Peter Dimov
f5a3f1b34a Remove obsolete reverse_iterator workarounds 2025-01-25 23:12:34 +02:00
Peter Dimov
9e2868f8e2 Reorder includes 2025-01-25 23:10:41 +02:00
Peter Dimov
4f2ed73766 Add array_get_test_cx.cpp 2025-01-25 21:20:12 +02:00
Peter Dimov
b32a6cfcfd Work around GCC 5..8 constexpr comparison failures 2025-01-25 20:59:46 +02:00
Peter Dimov
50cf6ebba7 Disable array_access_test_cx for GCC 4.x 2025-01-25 20:51:36 +02:00
Peter Dimov
ec05d6ca34 Disable array_iterator_test_cx for GCC 4.x 2025-01-25 20:50:45 +02:00
Peter Dimov
18ec6239b2 Disable array_data_test_cx for GCC 4.x 2025-01-25 20:49:14 +02:00
Peter Dimov
b44be8da89 Disable array_copy_test_cx for GCC 4.x 2025-01-25 20:47:36 +02:00
Peter Dimov
ea9dbd5674 Disable array_init_test_cx for GCC 4.x 2025-01-25 20:46:20 +02:00
Peter Dimov
5c05254afb Add array_lt_test_cx.cpp 2025-01-25 20:32:38 +02:00
Peter Dimov
a211468866 Add array_eq_test_cx.cpp 2025-01-25 20:24:15 +02:00
Peter Dimov
c06cadc04f Add array_access_test_cx.cpp 2025-01-25 20:09:17 +02:00
Peter Dimov
f155831795 Add array_iterator_test_cx.cpp 2025-01-25 20:02:57 +02:00
Peter Dimov
7ca2f112a2 Disable constexpr data() test for msvc-14.0 2025-01-25 19:42:21 +02:00
Peter Dimov
19f02c7615 Add array_data_test_cx.cpp 2025-01-25 19:38:01 +02:00
Peter Dimov
66386e8eda Add array_copy_test_cx.cpp 2025-01-25 19:29:47 +02:00
Peter Dimov
54d839c8bc Add array_size_test_cx.cpp 2025-01-25 19:23:50 +02:00
Peter Dimov
e7663434ee Add array_init_test_cx.cpp 2025-01-25 19:18:22 +02:00
Peter Dimov
52406dfcc0 Add revision history 2025-01-25 18:06:00 +02:00
Peter Dimov
9b8a342f44 Update documentation 2025-01-25 18:00:27 +02:00
Rene Rivera
78fb6a71dd Adjust self dependencies as inter-lib deps no longer apply globally. 2024-07-27 11:03:42 -05:00
Rene Rivera
40e2a2d4d8 Move inter-lib dependencies to a project variable and into the build targets. 2024-07-23 22:34:23 -05:00
Rene Rivera
fc10453994 Update copyright dates. 2024-07-20 22:52:04 -05:00
Rene Rivera
28d8d30b57 Bump B2 require to 5.2 2024-06-14 11:33:55 -05:00
Rene Rivera
fe1e99eb31 Add requires-b2 check to top-level build file. 2024-05-05 09:00:00 -05:00
Rene Rivera
1469f4b28e Sync from upstream. 2024-04-12 22:21:21 -05:00
Rene Rivera
d535c37a57 Switch to library requirements instead of source. As source puts extra source in install targets. 2024-03-29 21:12:36 -05:00
Rene Rivera
36bba5af2d Make the library modular usable. 2024-03-11 08:27:02 -05:00
51 changed files with 1685 additions and 365 deletions

View File

@@ -235,6 +235,76 @@ local windows_pipeline(name, image, environment, arch = "amd64") =
"clang-3.8", "clang-3.8",
), ),
linux_pipeline(
"Linux 18.04 Clang 3.9",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '03,11,14' },
"clang-3.9",
),
linux_pipeline(
"Linux 18.04 Clang 4.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '03,11,14' },
"clang-4.0",
),
linux_pipeline(
"Linux 18.04 Clang 5.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '03,11,14,1z' },
"clang-5.0",
),
linux_pipeline(
"Linux 18.04 Clang 6.0",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '03,11,14,17' },
"clang-6.0",
),
linux_pipeline(
"Linux 20.04 Clang 7",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '03,11,14,17' },
"clang-7",
),
linux_pipeline(
"Linux 20.04 Clang 8",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '03,11,14,17' },
"clang-8",
),
linux_pipeline(
"Linux 20.04 Clang 9",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '03,11,14,17,2a' },
"clang-9",
),
linux_pipeline(
"Linux 20.04 Clang 10",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '03,11,14,17,2a' },
"clang-10",
),
linux_pipeline(
"Linux 20.04 Clang 11",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '03,11,14,17,2a' },
"clang-11",
),
linux_pipeline(
"Linux 20.04 Clang 12",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '03,11,14,17,2a' },
"clang-12",
),
linux_pipeline( linux_pipeline(
"Linux 22.04 Clang 13", "Linux 22.04 Clang 13",
"cppalliance/droneubuntu2204:1", "cppalliance/droneubuntu2204:1",

View File

@@ -16,7 +16,6 @@ target_link_libraries(boost_array
INTERFACE INTERFACE
Boost::assert Boost::assert
Boost::config Boost::config
Boost::core
Boost::static_assert Boost::static_assert
Boost::throw_exception Boost::throw_exception
) )

24
build.jam Normal file
View File

@@ -0,0 +1,24 @@
# Copyright 2023-2024 René Ferdinand Rivera Morell
# Copyright 2024 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
require-b2 5.2 ;
constant boost_dependencies :
/boost/assert//boost_assert
/boost/config//boost_config
/boost/static_assert//boost_static_assert
/boost/throw_exception//boost_throw_exception
;
project /boost/array ;
explicit
[ alias boost_array : : : : <include>include <library>$(boost_dependencies) ]
[ alias all : boost_array test ]
;
call-if : boost-library array
;

View File

@@ -6,7 +6,7 @@ Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt https://www.boost.org/LICENSE_1_0.txt
//// ////
# Array # Boost.Array
Nicolai M. Josuttis Nicolai M. Josuttis
:toc: left :toc: left
:toclevels: 4 :toclevels: 4
@@ -18,8 +18,8 @@ Nicolai M. Josuttis
:leveloffset: +1 :leveloffset: +1
include::array/introduction.adoc[] include::array/introduction.adoc[]
include::array/changes.adoc[]
include::array/reference.adoc[] include::array/reference.adoc[]
include::array/design_rationale.adoc[] include::array/design_rationale.adoc[]
include::array/information.adoc[] include::array/information.adoc[]

24
doc/array/changes.adoc Normal file
View File

@@ -0,0 +1,24 @@
////
Copyright 2025 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
http://www.boost.org/LICENSE_1_0.txt
////
[#changes]
# Revision History
:toc:
:toc-title:
:idprefix:
## Changes in 1.88.0
* Converted documentation to AsciiDoc (Christian Mazakas).
* Added `noexcept` and `constexpr` as appropriate.
* Marked obsolete functions as deprecated.
* Removed obsolete compiler workarounds.
* Changed `array<T, 0>::begin()`, `cbegin()`, `end()`, `cend()` to return `nullptr`, enabling `constexpr`.
This matches the behavior of `std::array`.
* Removed local `hash_value` overload; `boost::hash` supports array-like types natively.
* `array<T, 0>` can now be initialized with `= {{}}`.
* Added `operator\<\=>`.
* Added `to_array`.

View File

@@ -12,4 +12,4 @@ Copyright (C) 2001-2004 Nicolai M. Josuttis
Copyright (C) 2012 Marshall Clow 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) Distributed under the https://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].

View File

@@ -37,7 +37,3 @@ Note that for standard conforming compilers it is possible to use fewer braces (
```cpp ```cpp
boost::array<int,4> a = { 1, 2, 3 }; 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.

View File

@@ -11,11 +11,18 @@ https://www.boost.org/LICENSE_1_0.txt
:idprefix: introduction_ :idprefix: introduction_
:cpp: C++ :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). 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. 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]. 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`. After considering different names, we decided to name this class simply `array`.

View File

@@ -15,24 +15,40 @@ https://www.boost.org/LICENSE_1_0.txt
```cpp ```cpp
namespace boost { namespace boost {
template<typename T, std::size_t N> class array; template<typename T, std::size_t N> class array;
template<typename T, std::size_t N> void swap(array<T, N>&, array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator==(const array<T, N>&, const array<T, N>&); void swap(array<T, N>&, array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator!=(const array<T, N>&, const array<T, N>&); constexpr bool operator==(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator<(const array<T, N>&, const array<T, N>&); constexpr bool operator!=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator>(const array<T, N>&, const array<T, N>&); constexpr bool operator<(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator<=(const array<T, N>&, const array<T, N>&); constexpr bool operator>(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator>=(const array<T, N>&, const array<T, N>&); constexpr bool operator<=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N, std::size_t Idx> template<typename T, std::size_t N>
T boost::get(array<T, N>&); constexpr bool operator>=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N, std::size_t Idx>
T boost::get(const array<T, N>&); template<typename T, std::size_t N>
constexpr auto operator<=>(const array<T, N>&, const array<T, N>&);
template<std::size_t Idx, typename T, std::size_t N>
constexpr T& get(array<T, N>&) noexcept;
template<std::size_t Idx, typename T, std::size_t N>
constexpr const T& get(const array<T, N>&) noexcept;
template<class T, std::size_t N>
constexpr array<T, N> to_array( T const (&)[N] );
template<class T, std::size_t N>
constexpr array<T, N> to_array( T (&&)[N] );
template<class T, std::size_t N>
constexpr array<T, N> to_array( T const (&&)[N] );
} }
``` ```
@@ -46,7 +62,9 @@ namespace boost {
template<typename T, std::size_t N> template<typename T, std::size_t N>
class array { class array {
public: public:
// types // types
typedef T value_type; typedef T value_type;
typedef T* iterator; typedef T* iterator;
typedef const T* const_iterator; typedef const T* const_iterator;
@@ -58,361 +76,377 @@ public:
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
// static constants // static constants
static const size_type static_size = N; static const size_type static_size = N;
// construct/copy/destruct // construct/copy/destroy
template<typename U> array& operator=(const array<U, N>&); template<typename U> array& operator=(const array<U, N>&);
// iterator support // iterator support
iterator begin();
const_iterator begin() const; constexpr iterator begin() noexcept;
iterator end(); constexpr const_iterator begin() const noexcept;
const_iterator end() const; constexpr const_iterator cbegin() const noexcept;
const_iterator cbegin();
const_iterator cend(); constexpr iterator end() noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
// reverse iterator support // reverse iterator support
reverse_iterator rbegin();
const_reverse_iterator rbegin() const; reverse_iterator rbegin() noexcept;
reverse_iterator rend(); const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator rend() const; const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crbegin();
const_reverse_iterator crend(); reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity // capacity
size_type size();
bool empty(); static constexpr size_type size() noexcept;
size_type max_size(); static constexpr bool empty() noexcept;
static constexpr size_type max_size() noexcept;
// element access // element access
reference operator[](size_type);
const_reference operator[](size_type) const; constexpr reference operator[](size_type);
reference at(size_type); constexpr const_reference operator[](size_type) const;
const_reference at(size_type) const;
reference front(); constexpr reference at(size_type);
const_reference front() const; constexpr const_reference at(size_type) const;
reference back();
const_reference back() const; constexpr reference front();
const T* data() const; constexpr const_reference front() const;
T* c_array();
constexpr reference back();
constexpr const_reference back() const;
constexpr T* data() noexcept;
constexpr const T* data() const noexcept;
T* c_array() noexcept; // deprecated
// modifiers // modifiers
void swap(array<T, N>&);
void assign(const T&); swap(array<T, N>&);
constexpr void fill(const T&);
void assign(const T&); // deprecated
// public data members // public data members
T elems[N]; T elems[N];
}; };
// specialized algorithms
template<typename T, std::size_t N> void swap(array<T, N>&, array<T, N>&);
// comparisons
template<typename T, std::size_t N>
bool operator==(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator!=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator<(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator>(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator<=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator>=(const array<T, N>&, const array<T, N>&);
// specializations
template<typename T, std::size_t N, std::size_t Idx>
T boost::get(array<T, N>&);
template<typename T, std::size_t N, std::size_t Idx>
T boost::get(const array<T, N>&);
``` ```
### Description ### Construct/Copy/Destroy
#### array public construct/copy/destruct
``` ```
template<typename U> array& operator=(const array<U, N>& other); template<typename U> array& operator=(const array<U, N>& other);
``` ```
[horizontal] [horizontal]
Effects: :: `std::copy(rhs.begin(), rhs.end(), begin())` Effects: :: For each `i` in `[0..N)`, performs `elems[i] = other.elems[i];`.
--- ---
#### array iterator support ### Iterator Support
``` ```
iterator begin(); constexpr iterator begin() noexcept;
const_iterator begin() const; constexpr const_iterator begin() const noexcept;
constexpr const_iterator cbegin() const noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: iterator for the first element Returns: :: `data()`.
Throws: :: will not throw
--- ---
``` ```
iterator end(); constexpr iterator end() noexcept;
const_iterator end() const; constexpr const_iterator end() const noexcept;
constexpr const_iterator cend() const noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: iterator for position after the last element Returns: :: `data() + size()`.
Throws: :: will not throw
--- ---
### Reverse Iterator Support
``` ```
const_iterator cbegin(); reverse_iterator rbegin() noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: constant iterator for the first element Returns: :: `reverse_iterator(end())`.
Throws: :: will not throw
--- ---
``` ```
const_iterator cend(); const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator crbegin() const noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: constant iterator for position after the last element Returns: :: `const_reverse_iterator(end())`.
Throws: :: will not throw
--- ---
#### array reverse iterator support
``` ```
reverse_iterator rbegin(); reverse_iterator rend() noexcept;
const_reverse_iterator rbegin() const;
``` ```
[horizontal] [horizontal]
Returns: :: reverse iterator for the first element of reverse iteration Returns: :: `reverse_iterator(begin())`.
--- ---
``` ```
reverse_iterator rend(); const_reverse_iterator rend() const noexcept;
const_reverse_iterator rend() const; const_reverse_iterator crend() const noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: reverse iterator for position after the last element in reverse iteration Returns: :: `const_reverse_iterator(begin())`.
--- ---
### Capacity
``` ```
const_reverse_iterator crbegin(); static constexpr size_type size() noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: constant reverse iterator for the first element of reverse iteration Returns: :: `N`.
Throws: :: will not throw
--- ---
``` ```
const_reverse_iterator crend(); static constexpr bool empty() noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: constant reverse iterator for position after the last element in reverse iteration Returns: :: `N == 0`.
Throws: :: will not throw
--- ---
#### array capacity
``` ```
size_type size(); static constexpr size_type max_size() noexcept;
``` ```
[horizontal] [horizontal]
Returns: :: `N` Returns: :: `N`.
--- ---
### Element Access
``` ```
bool empty(); constexpr reference operator[](size_type i);
constexpr const_reference operator[](size_type i) const;
``` ```
[horizontal] [horizontal]
Returns: :: `N==0` Requires: :: `i < N`.
Throws: :: will not throw Returns: :: `elems[i]`.
Throws: :: Nothing.
--- ---
``` ```
size_type max_size(); constexpr reference at(size_type i);
constexpr const_reference at(size_type i) const;
``` ```
[horizontal] [horizontal]
Returns: :: `N` Returns: :: `elems[i]`.
Throws: :: will not throw Throws: :: `std::out_of_range` if `i >= N`.
--- ---
#### array element access
``` ```
reference operator[](size_type i); constexpr reference front();
const_reference operator[](size_type i) const; constexpr const_reference front() const;
``` ```
[horizontal] [horizontal]
Requires: :: `i < N` Requires: :: `N > 0`.
Returns: :: element with index `i` Returns: :: `elems[0]`.
Throws: :: will not throw. Throws: :: Nothing.
--- ---
``` ```
reference at(size_type i); constexpr reference back();
const_reference at(size_type i) const; constexpr const_reference back() const;
``` ```
[horizontal] [horizontal]
Returns: :: element with index `i` Requires: :: `N > 0`.
Throws: :: `std::range_error` if `i >= N` Returns: :: `elems[N-1]`.
Throws: :: Nothing.
--- ---
``` ```
reference front(); constexpr T* data() noexcept;
const_reference front() const; constexpr const T* data() const noexcept;
``` ```
[horizontal] [horizontal]
Requires: :: `N > 0` Returns: :: `elems`.
Returns: :: the first element
Throws: :: will not throw
--- ---
``` ```
reference back(); T* c_array() noexcept; // deprecated
const_reference back() const;
``` ```
[horizontal] [horizontal]
Requires: :: `N > 0` Returns: :: `data()`.
Returns: :: the last element Remarks: :: This function is deprecated. Use `data()` instead.
Throws: :: will not throw
--- ---
``` ### Modifiers
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<T, N>& other); void swap(array<T, N>& other);
``` ```
[horizontal] [horizontal]
Effects: :: `std::swap_ranges(begin(), end(), other.begin())` Effects: :: `std::swap(elems, other.elems)`.
Complexity: :: linear in `N` Complexity: :: linear in `N`.
--- ---
``` ```
void assign(const T& value); void fill(const T& value);
``` ```
[horizontal] [horizontal]
Effects: :: `std::fill_n(begin(), N, value)` Effects: :: For each `i` in `[0..N)`, performs `elems[i] = value;`.
--- ---
#### array specialized algorithms
``` ```
template<typename T, std::size_t N> void swap(array<T, N>& x, array<T, N>& y); void assign(const T& value); // deprecated
``` ```
[horizontal] [horizontal]
Effects: :: `x.swap(y)` Effects: :: `fill(value)`.
Throws: :: will not throw. Remarks: :: An obsolete and deprecated spelling of `fill`. Use `fill` instead.
--- ---
#### array comparisons ### Specialized Algorithms
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator==(const array<T, N>& x, const array<T, N>& y); void swap(array<T, N>& x, array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `std::equal(x.begin(), x.end(), y.begin())` Effects: :: `x.swap(y)`.
---
### Comparisons
```
template<typename T, std::size_t N>
constexpr bool operator==(const array<T, N>& x, const array<T, N>& y);
```
[horizontal]
Returns: :: `std::equal(x.begin(), x.end(), y.begin())`.
--- ---
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator!=(const array<T, N>& x, const array<T, N>& y); constexpr bool operator!=(const array<T, N>& x, const array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `!(x == y)` Returns: :: `!(x == y)`.
--- ---
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator<(const array<T, N>& x, const array<T, N>& y); constexpr bool operator<(const array<T, N>& x, const array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end())` Returns: :: `std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end())`.
--- ---
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator>(const array<T, N>& x, const array<T, N>& y); constexpr bool operator>(const array<T, N>& x, const array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `y < x` Returns: :: `y < x`.
--- ---
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator<=(const array<T, N>& x, const array<T, N>& y); constexpr bool operator<=(const array<T, N>& x, const array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `!(y < x)` Returns: :: `!(y < x)`.
--- ---
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
bool operator>=(const array<T, N>& x, const array<T, N>& y); constexpr bool operator>=(const array<T, N>& x, const array<T, N>& y);
``` ```
[horizontal] [horizontal]
Returns: :: `!(x < y)` Returns: :: `!(x < y)`.
---
#### array specializations
```
template<typename T, std::size_t N, std::size_t Idx>
T boost::get(array<T, N>& arr);
```
[horizontal]
Returns: :: element of array with index `Idx`
Effects: :: Will `static_assert` if `Idx >= N`
--- ---
``` ```
template<typename T, std::size_t N, std::size_t Idx> template<typename T, std::size_t N>
T boost::get(const array<T, N>& arr); constexpr auto operator<=>(const array<T, N>& x, const array<T, N>& y)
-> decltype(x[0] <=> y[0]);
``` ```
[horizontal] [horizontal]
Returns: :: const element of array with index `Idx` Effects: :: For each `i` in `[0..N)`, if `(x[i] \<\=> y[i]) != 0`, returns `x[i] \<\=> y[i]`. Otherwise, returns `std::strong_ordering::equal`, converted to the return type.
Effects: :: Will `static_assert` if `Idx >= N` Remarks: :: When `N` is 0, the return type is `std::strong_ordering` and the return value is `std::strong_ordering::equal`.
---
### Specializations
```
template<std::size_t Idx, typename T, std::size_t N>
constexpr T& get(array<T, N>& arr) noexcept;
```
[horizontal]
Mandates: :: `Idx < N`.
Returns: :: `arr[Idx]`.
---
```
template<std::size_t Idx, typename T, std::size_t N>
constexpr const T& get(const array<T, N>& arr) noexcept;
```
[horizontal]
Mandates: :: `Idx < N`.
Returns: :: `arr[Idx]`.
---
### Creation
```
template<class T, std::size_t N>
constexpr array<T, N> to_array( T const (&a)[N] );
```
[horizontal]
Returns: :: an `array<T, N>` `r` such that for each `i` in `[0..N)`, `r[i]` is copied from `a[i]`.
```
template<class T, std::size_t N>
constexpr array<T, N> to_array( T (&&a)[N] );
```
[horizontal]
Returns: :: an `array<T, N>` `r` such that for each `i` in `[0..N)`, `r[i]` is moved from `std::move(a[i])`.
```
template<class T, std::size_t N>
constexpr array<T, N> to_array( T const (&&a)[N] );
```
[horizontal]
Returns: :: an `array<T, N>` `r` such that for each `i` in `[0..N)`, `r[i]` is copied from `a[i]`.
--- ---

View File

@@ -1,3 +1,6 @@
#ifndef BOOST_ARRAY_HPP_INCLUDED
#define BOOST_ARRAY_HPP_INCLUDED
/* The following code declares class array, /* The following code declares class array,
* an STL container (as wrapper) for arrays of constant size. * an STL container (as wrapper) for arrays of constant size.
* *
@@ -28,29 +31,31 @@
* *
* Jan 29, 2004 * Jan 29, 2004
*/ */
#ifndef BOOST_ARRAY_HPP
#define BOOST_ARRAY_HPP
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/config/workaround.hpp> #include <boost/config/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
# pragma warning(push) # pragma warning(push)
# pragma warning(disable:4996) // 'std::equal': Function call with parameters that may be unsafe # pragma warning(disable: 4510) // boost::array<T,N>' : default constructor could not be generated
# pragma warning(disable:4510) // boost::array<T,N>' : default constructor could not be generated # pragma warning(disable: 4512) // boost::array<T,N>' : assignment operator could not be generated
# pragma warning(disable:4610) // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required # pragma warning(disable: 4610) // class 'boost::array<T,N>' can never be instantiated - user defined constructor required
# pragma warning(disable: 4702) // unreachable code
#endif #endif
#include <cstddef> #include <boost/assert.hpp>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <iterator> #include <iterator>
#include <stdexcept> #include <stdexcept>
#include <boost/assert.hpp> #include <utility>
#include <boost/core/invoke_swap.hpp> #include <cstddef>
#include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm>
#if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
# if __has_include(<compare>)
# include <compare>
# endif
#endif
namespace boost { namespace boost {
@@ -79,19 +84,8 @@ namespace boost {
BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return elems+N; } BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return elems+N; }
// reverse iterator support // reverse iterator support
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
#endif
reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); } reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const BOOST_NOEXCEPT { const_reverse_iterator rbegin() const BOOST_NOEXCEPT {
@@ -155,31 +149,49 @@ namespace boost {
enum { static_size = N }; enum { static_size = N };
// swap (note: linear complexity) // swap (note: linear complexity)
BOOST_CXX14_CONSTEXPR void swap (array<T,N>& y) { BOOST_CXX14_CONSTEXPR void swap (array<T,N>& y)
for (size_type i = 0; i < N; ++i) {
boost::core::invoke_swap(elems[i],y.elems[i]); std::swap( elems, y.elems );
} }
// direct access to data (read-only) // direct access to data
BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return elems; } BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return elems; }
BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return elems; } BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return elems; }
// use array as C array (direct read/write access to data) // obsolete
BOOST_DEPRECATED( "please use `data()` instead" )
T* c_array() BOOST_NOEXCEPT { return elems; } T* c_array() BOOST_NOEXCEPT { return elems; }
// assignment with type conversion // assignment with type conversion
template <typename T2> template <typename T2>
array<T,N>& operator= (const array<T2,N>& rhs) { array<T,N>& operator= (const array<T2,N>& rhs)
std::copy(rhs.begin(),rhs.end(), begin()); {
for( std::size_t i = 0; i < N; ++i )
{
elems[ i ] = rhs.elems[ i ];
}
return *this; return *this;
} }
// assign one value to all elements // fill with one value
void assign (const T& value) { fill ( value ); } // A synonym for fill
BOOST_CXX14_CONSTEXPR void fill (const T& value) BOOST_CXX14_CONSTEXPR void fill (const T& value)
{ {
std::fill_n(begin(),size(),value); // using elems[ 0 ] as a temporary copy
// avoids the aliasing opportunity betw.
// `value` and `elems`
elems[ 0 ] = value;
for( std::size_t i = 1; i < N; ++i )
{
elems[ i ] = elems[ 0 ];
} }
}
// an obsolete synonym for fill
BOOST_DEPRECATED( "please use `fill` instead" )
void assign (const T& value) { fill ( value ); }
// check range (may be private because it is static) // check range (may be private because it is static)
static BOOST_CONSTEXPR bool rangecheck (size_type i) { static BOOST_CONSTEXPR bool rangecheck (size_type i) {
@@ -190,6 +202,8 @@ namespace boost {
template< class T > template< class T >
class array< T, 0 > { class array< T, 0 > {
public:
struct {} elems; // enables initialization with = {{}}
public: public:
// type definitions // type definitions
@@ -202,28 +216,17 @@ namespace boost {
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
// iterator support // iterator support
iterator begin() BOOST_NOEXCEPT { return iterator( reinterpret_cast< T * >( this ) ); } BOOST_CXX14_CONSTEXPR iterator begin() BOOST_NOEXCEPT { return data(); }
const_iterator begin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); } BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return data(); }
const_iterator cbegin() const BOOST_NOEXCEPT { return const_iterator( reinterpret_cast< const T * >( this ) ); } BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return data(); }
iterator end() BOOST_NOEXCEPT { return begin(); } BOOST_CXX14_CONSTEXPR iterator end() BOOST_NOEXCEPT { return begin(); }
const_iterator end() const BOOST_NOEXCEPT { return begin(); } BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return begin(); }
const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); } BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return cbegin(); }
// reverse iterator support // reverse iterator support
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
value_type, reference, iterator, difference_type> reverse_iterator;
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
#else
// workaround for broken reverse_iterator implementations
typedef std::reverse_iterator<iterator,T> reverse_iterator;
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
#endif
reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); } reverse_iterator rbegin() BOOST_NOEXCEPT { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const BOOST_NOEXCEPT { const_reverse_iterator rbegin() const BOOST_NOEXCEPT {
@@ -283,14 +286,16 @@ namespace boost {
static BOOST_CONSTEXPR size_type max_size() BOOST_NOEXCEPT { return 0; } static BOOST_CONSTEXPR size_type max_size() BOOST_NOEXCEPT { return 0; }
enum { static_size = 0 }; enum { static_size = 0 };
void swap (array<T,0>& /*y*/) { BOOST_CXX14_CONSTEXPR void swap (array<T,0>& /*y*/)
{
} }
// direct access to data (read-only) // direct access to data
BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return 0; } BOOST_CONSTEXPR const T* data() const BOOST_NOEXCEPT { return 0; }
BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return 0; } BOOST_CXX14_CONSTEXPR T* data() BOOST_NOEXCEPT { return 0; }
// use array as C array (direct read/write access to data) // obsolete
BOOST_DEPRECATED( "please use `data()` instead" )
T* c_array() BOOST_NOEXCEPT { return 0; } T* c_array() BOOST_NOEXCEPT { return 0; }
// assignment with type conversion // assignment with type conversion
@@ -299,47 +304,79 @@ namespace boost {
return *this; return *this;
} }
// assign one value to all elements // an obsolete synonym for fill
BOOST_DEPRECATED( "please use `fill` instead" )
void assign (const T& value) { fill ( value ); } void assign (const T& value) { fill ( value ); }
// fill with one value
BOOST_CXX14_CONSTEXPR void fill (const T& ) {} BOOST_CXX14_CONSTEXPR void fill (const T& ) {}
// check range (may be private because it is static) // check range (may be private because it is static)
static reference failed_rangecheck () { static reference failed_rangecheck ()
std::out_of_range e("attempt to access element of an empty array"); {
boost::throw_exception(e); boost::throw_exception( std::out_of_range( "attempt to access element of an empty array" ) );
#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
//
// We need to return something here to keep
// some compilers happy: however we will never
// actually get here....
//
static T placeholder;
return placeholder;
#endif
} }
}; };
// comparisons // comparisons
template<class T, std::size_t N> template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator== (const array<T,N>& x, const array<T,N>& y) { BOOST_CXX14_CONSTEXPR bool operator== (const array<T,N>& x, const array<T,N>& y)
return std::equal(x.begin(), x.end(), y.begin()); {
for( std::size_t i = 0; i < N; ++i )
{
if( !( x[ i ] == y[ i ] ) ) return false;
} }
template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y) { return true;
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
} }
#if BOOST_WORKAROUND(BOOST_GCC, < 90000)
template<class T>
BOOST_CXX14_CONSTEXPR bool operator== (const array<T, 0>& /*x*/, const array<T, 0>& /*y*/)
{
return true;
}
#endif
template<class T, std::size_t N> template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator!= (const array<T,N>& x, const array<T,N>& y) { BOOST_CXX14_CONSTEXPR bool operator!= (const array<T,N>& x, const array<T,N>& y) {
return !(x==y); return !(x==y);
} }
template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y)
{
for( std::size_t i = 0; i < N; ++i )
{
if( x[ i ] < y[ i ] ) return true;
if( y[ i ] < x[ i ] ) return false;
}
return false;
}
#if BOOST_WORKAROUND(BOOST_GCC, < 90000)
template<class T>
BOOST_CXX14_CONSTEXPR bool operator< (const array<T, 0>& /*x*/, const array<T, 0>& /*y*/)
{
return false;
}
#endif
template<class T, std::size_t N> template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator> (const array<T,N>& x, const array<T,N>& y) { BOOST_CXX14_CONSTEXPR bool operator> (const array<T,N>& x, const array<T,N>& y) {
return y<x; return y<x;
} }
template<class T, std::size_t N> template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator<= (const array<T,N>& x, const array<T,N>& y) { BOOST_CXX14_CONSTEXPR bool operator<= (const array<T,N>& x, const array<T,N>& y) {
return !(y<x); return !(y<x);
} }
template<class T, std::size_t N> template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator>= (const array<T,N>& x, const array<T,N>& y) { BOOST_CXX14_CONSTEXPR bool operator>= (const array<T,N>& x, const array<T,N>& y) {
return !(x<y); return !(x<y);
@@ -347,39 +384,39 @@ namespace boost {
// global swap() // global swap()
template<class T, std::size_t N> template<class T, std::size_t N>
inline void swap (array<T,N>& x, array<T,N>& y) { BOOST_CXX14_CONSTEXPR inline void swap (array<T,N>& x, array<T,N>& y) {
x.swap(y); x.swap(y);
} }
#if defined(__SUNPRO_CC) #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L
// Trac ticket #4757; the Sun Solaris compiler can't handle # if __has_include(<compare>)
// syntax like 'T(&get_c_array(boost::array<T,N>& arg))[N]'
// template<class T, std::size_t N>
// We can't just use this for all compilers, because the constexpr auto operator<=> (const array<T,N>& x, const array<T,N>& y)
// borland compilers can't handle this form. -> decltype( x.elems[ 0 ] <=> y.elems[ 0 ] )
namespace detail {
template <typename T, std::size_t N> struct c_array
{ {
typedef T type[N]; for( std::size_t i = 0; i < N; ++i )
}; {
auto r = x.elems[ i ] <=> y.elems[ i ];
if( r != 0 ) return r;
} }
// Specific for boost::array: simply returns its elems data member. return std::strong_ordering::equal;
template <typename T, std::size_t N>
typename detail::c_array<T,N>::type& get_c_array(boost::array<T,N>& arg)
{
return arg.elems;
} }
// Specific for boost::array: simply returns its elems data member. template<class T>
template <typename T, std::size_t N> constexpr auto operator<=> (const array<T,0>& /*x*/, const array<T,0>& /*y*/)
typename detail::c_array<T,N>::type const& get_c_array(const boost::array<T,N>& arg) -> std::strong_ordering
{ {
return arg.elems; return std::strong_ordering::equal;
} }
#else
// Specific for boost::array: simply returns its elems data member. # endif
#endif
// undocumented and obsolete
template <typename T, std::size_t N> template <typename T, std::size_t N>
BOOST_DEPRECATED( "please use `elems` instead" )
T(&get_c_array(boost::array<T,N>& arg))[N] T(&get_c_array(boost::array<T,N>& arg))[N]
{ {
return arg.elems; return arg.elems;
@@ -387,62 +424,83 @@ namespace boost {
// Const version. // Const version.
template <typename T, std::size_t N> template <typename T, std::size_t N>
BOOST_DEPRECATED( "please use `elems` instead" )
const T(&get_c_array(const boost::array<T,N>& arg))[N] const T(&get_c_array(const boost::array<T,N>& arg))[N]
{ {
return arg.elems; return arg.elems;
} }
#endif
#if 0
// Overload for std::array, assuming that std::array will have
// explicit conversion functions as discussed at the WG21 meeting
// in Summit, March 2009.
template <typename T, std::size_t N>
T(&get_c_array(std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
// Const version.
template <typename T, std::size_t N>
const T(&get_c_array(const std::array<T,N>& arg))[N]
{
return static_cast<T(&)[N]>(arg);
}
#endif
template <class It> std::size_t hash_range(It, It);
template<class T, std::size_t N>
std::size_t hash_value(const array<T,N>& arr)
{
return boost::hash_range(arr.begin(), arr.end());
}
template <size_t Idx, typename T, size_t N> template <size_t Idx, typename T, size_t N>
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT { BOOST_CXX14_CONSTEXPR T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" ); BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" );
return arr[Idx]; return arr[Idx];
} }
template <size_t Idx, typename T, size_t N> template <size_t Idx, typename T, size_t N>
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT { BOOST_CONSTEXPR const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" ); BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" );
return arr[Idx]; return arr[Idx];
} }
template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR array<T, N> to_array( T const (&a)[ N ] )
{
array<T, N> r = {};
for( std::size_t i = 0; i < N; ++i )
{
r[ i ] = a[ i ];
}
return r;
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR array<T, N> to_array( T (&&a)[ N ] )
{
array<T, N> r = {};
for( std::size_t i = 0; i < N; ++i )
{
r[ i ] = std::move( a[ i ] );
}
return r;
}
template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR array<T, N> to_array( T const (&&a)[ N ] )
{
array<T, N> r = {};
for( std::size_t i = 0; i < N; ++i )
{
r[ i ] = a[ i ];
}
return r;
}
#endif
} /* namespace boost */ } /* namespace boost */
#ifndef BOOST_NO_CXX11_HDR_ARRAY #ifndef BOOST_NO_CXX11_HDR_ARRAY
// If we don't have std::array, I'm assuming that we don't have std::get // If we don't have std::array, I'm assuming that we don't have std::get
namespace std { namespace std {
template <size_t Idx, typename T, size_t N> template <size_t Idx, typename T, size_t N>
BOOST_DEPRECATED( "please use `boost::get` instead" )
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT { T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" ); BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" );
return arr[Idx]; return arr[Idx];
} }
template <size_t Idx, typename T, size_t N> template <size_t Idx, typename T, size_t N>
BOOST_DEPRECATED( "please use `boost::get` instead" )
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT { const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" ); BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" );
return arr[Idx]; return arr[Idx];
@@ -454,4 +512,4 @@ namespace std {
# pragma warning(pop) # pragma warning(pop)
#endif #endif
#endif /*BOOST_ARRAY_HPP*/ #endif // #ifndef BOOST_ARRAY_HPP_INCLUDED

View File

@@ -4,8 +4,8 @@
</head> </head>
<body> <body>
Automatic redirection failed, please go to Automatic redirection failed, please go to
<a href="../../doc/html/array.html">doc/html/array.html</a> &nbsp;<hr> <a href="doc/html/array.html">doc/html/array.html</a> &nbsp;<hr>
<p><EFBFBD> Copyright Beman Dawes, 2001</p> <p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying <p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>

View File

@@ -7,6 +7,41 @@ import testing ;
import-search /boost/config/checks ; import-search /boost/config/checks ;
import config : requires ; import config : requires ;
project
: requirements
<library>/boost/array//boost_array
<library>/boost/core//boost_core
<warnings>extra
<toolset>msvc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>gcc-4.6:<cxxflags>-Wno-missing-braces
<toolset>gcc-4.7:<cxxflags>-Wno-missing-braces
<toolset>gcc-4.6:<cxxflags>-Wno-missing-field-initializers
<toolset>gcc-4.7:<cxxflags>-Wno-missing-field-initializers
<toolset>gcc-4.8:<cxxflags>-Wno-missing-field-initializers
<toolset>gcc-4.9:<cxxflags>-Wno-missing-field-initializers
<toolset>gcc-4.6:<cxxflags>-Wno-type-limits
<toolset>gcc-4.7:<cxxflags>-Wno-type-limits
<toolset>gcc-10:<cxxflags>-Wno-type-limits
<toolset>clang:<cxxflags>-Wno-unnamed-type-template-args
<toolset>clang-3.5:<cxxflags>-Wno-missing-braces
<toolset>clang-3.6:<cxxflags>-Wno-missing-braces
<toolset>clang-3.7:<cxxflags>-Wno-missing-braces
<toolset>clang-3.8:<cxxflags>-Wno-missing-braces
<toolset>clang-3.9:<cxxflags>-Wno-missing-braces
<toolset>clang-4:<cxxflags>-Wno-missing-braces
<toolset>clang-5:<cxxflags>-Wno-missing-braces
;
# #
run array0.cpp ; run array0.cpp ;
@@ -20,11 +55,13 @@ run array7.cpp ;
compile array_constexpr.cpp ; compile array_constexpr.cpp ;
compile-fail array_getfail1.cpp ; compile-fail array_getfail1.cpp
compile-fail array_getfail2.cpp ; : <warnings>off ;
compile-fail array_getfail2.cpp
: <warnings>off ;
run array_hash.cpp run array_hash.cpp
: : : [ requires cxx11_noexcept ] ; : : : <library>/boost/container_hash//boost_container_hash [ requires cxx11_noexcept ] ;
# #
@@ -45,7 +82,29 @@ run array_swap_test.cpp ;
run array_swap_test2.cpp ; run array_swap_test2.cpp ;
run array_eq_test.cpp ; run array_eq_test.cpp ;
run array_lt_test.cpp ; run array_lt_test.cpp ;
run array_thw_test.cpp ;
run array_get_test.cpp ; run array_get_test.cpp ;
run to_array_test.cpp ;
# C++11 constexpr
compile array_init_test_cx.cpp ;
compile array_copy_test_cx.cpp ;
compile array_data_test_cx.cpp ;
compile array_iterator_test_cx.cpp ;
compile array_size_test_cx.cpp ;
compile array_access_test_cx.cpp ;
compile array_get_test_cx.cpp ;
# C++14 constexpr
compile array_assign_test_cx.cpp ;
compile array_access_test_cx2.cpp ;
compile array_fill_test_cx.cpp ;
compile array_eq_test_cx.cpp ;
compile array_lt_test_cx.cpp ;
compile array_thw_test_cx.cpp ;
compile to_array_test_cx.cpp ;
# #

View File

@@ -5,11 +5,11 @@
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
*/ */
#include <boost/array.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <algorithm>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <boost/array.hpp>
#include <boost/core/lightweight_test_trait.hpp>
namespace { namespace {
@@ -44,7 +44,12 @@ void RunTests()
BOOST_TEST ( const_test_case.begin() == const_test_case.end()); BOOST_TEST ( const_test_case.begin() == const_test_case.end());
BOOST_TEST ( const_test_case.cbegin() == const_test_case.cend()); BOOST_TEST ( const_test_case.cbegin() == const_test_case.cend());
BOOST_TEST ( test_case.begin() != const_test_case.begin() ); // BOOST_TEST ( test_case.begin() != const_test_case.begin() );
//
// TR1 specified that begin() must return a unique value for zero-sized
// arrays. However, this makes constexpr unimplementable, and all standard
// libraries have converged on using nullptr instead (see LWG issue 2157.)
if( test_case.data() == const_test_case.data() ) { if( test_case.data() == const_test_case.data() ) {
// Value of data is unspecified in TR1, so no requirement this test pass or fail // Value of data is unspecified in TR1, so no requirement this test pass or fail
// However, it must compile! // However, it must compile!

View File

@@ -5,6 +5,8 @@
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
*/ */
#define BOOST_ALLOW_DEPRECATED_SYMBOLS // assign
#include <iostream> #include <iostream>
#include <boost/array.hpp> #include <boost/array.hpp>

View File

@@ -5,12 +5,20 @@
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
*/ */
#define BOOST_ALLOW_DEPRECATED_SYMBOLS // get_c_array
#include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <boost/array.hpp>
#include <algorithm> #include <algorithm>
#include <boost/core/lightweight_test_trait.hpp> #if defined(BOOST_GCC) && BOOST_GCC / 10000 == 13
// false -Warray-bounds positive when using -fsanitize=undefined
// restricted to GCC 13 because that's what is tested on Drone
# pragma GCC diagnostic ignored "-Warray-bounds"
#endif
namespace { namespace {
template< class T > template< class T >

View File

@@ -5,6 +5,8 @@
* http://www.boost.org/LICENSE_1_0.txt) * http://www.boost.org/LICENSE_1_0.txt)
*/ */
#define BOOST_ALLOW_DEPRECATED_SYMBOLS // std::get
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <boost/array.hpp> #include <boost/array.hpp>

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#define BOOST_ENABLE_ASSERT_HANDLER #define BOOST_ENABLE_ASSERT_HANDLER

View File

@@ -0,0 +1,50 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_MSVC < 1910")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T> void test()
{
constexpr boost::array<T, 4> a = {{}};
STATIC_ASSERT( &a[ 0 ] == a.data() + 0 );
STATIC_ASSERT( &a[ 1 ] == a.data() + 1 );
STATIC_ASSERT( &a[ 2 ] == a.data() + 2 );
STATIC_ASSERT( &a[ 3 ] == a.data() + 3 );
STATIC_ASSERT( &a.at( 0 ) == a.data() + 0 );
STATIC_ASSERT( &a.at( 1 ) == a.data() + 1 );
STATIC_ASSERT( &a.at( 2 ) == a.data() + 2 );
STATIC_ASSERT( &a.at( 3 ) == a.data() + 3 );
STATIC_ASSERT( &a.front() == a.data() );
STATIC_ASSERT( &a.back() == a.data() + 3 );
}
int main()
{
test<int>();
}
#endif

View File

@@ -0,0 +1,45 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> constexpr boost::array<T, N> modified( boost::array<T, N> a1 )
{
a1.front() = 1;
a1[ 1 ] = 2;
a1.at( 2 ) = 3;
a1.back() = 4;
return a1;
}
template<class T> void test1()
{
constexpr boost::array<T, 4> a1 = {};
constexpr boost::array<T, 4> a2 = modified( a1 );
STATIC_ASSERT( a2[0] == 1 );
STATIC_ASSERT( a2[1] == 2 );
STATIC_ASSERT( a2[2] == 3 );
STATIC_ASSERT( a2[3] == 4 );
}
int main()
{
test1<int>();
}
#endif

View File

@@ -1,13 +1,18 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#define BOOST_ALLOW_DEPRECATED_SYMBOLS
// assign is a deprecated nonstandard equivalent of fill
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
// assign is a nonstandard equivalent of fill #if defined(_MSC_VER)
// it probably needs to be deprecated and removed # pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {

View File

@@ -0,0 +1,54 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> constexpr boost::array<T, N> assigned( boost::array<T, N> const& a1 )
{
boost::array<T, N> a2 = {};
a2 = a1;
return a2;
}
template<class T> void test1()
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = assigned( a1 );
STATIC_ASSERT( a1[0] == a2[0] );
STATIC_ASSERT( a1[1] == a2[1] );
STATIC_ASSERT( a1[2] == a2[2] );
STATIC_ASSERT( a1[3] == a2[3] );
}
template<class T> void test2()
{
constexpr boost::array<T, 0> a1 = {};
constexpr boost::array<T, 0> a2 = assigned( a1 );
(void)a1;
(void)a2;
}
int main()
{
test1<int>();
test2<int>();
}
#endif

View File

@@ -1,6 +1,8 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#define BOOST_ALLOW_DEPRECATED_SYMBOLS
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -8,8 +10,7 @@
#include <boost/config/workaround.hpp> #include <boost/config/workaround.hpp>
#include <cstddef> #include <cstddef>
// c_array and get_c_array are nonstandard extensions // c_array and get_c_array are deprecated nonstandard extensions
// probably need to be deprecated and removed
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -44,11 +44,11 @@ template<class T> void test4()
int main() int main()
{ {
// test1<int, 0>(); test1<int, 0>();
test1<int, 1>(); test1<int, 1>();
test1<int, 7>(); test1<int, 7>();
// test1<int const, 0>(); test1<int const, 0>();
test1<int const, 1>(); test1<int const, 1>();
test1<int const, 7>(); test1<int const, 7>();

View File

@@ -0,0 +1,58 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T> void test1()
{
constexpr boost::array<T, 2> a1 = {};
constexpr boost::array<T, 2> a2 = a1;
STATIC_ASSERT( a1[0] == a2[0] );
STATIC_ASSERT( a1[1] == a2[1] );
}
template<class T> void test2()
{
constexpr boost::array<T, 3> a1 = {{ 1, 2, 3 }};
constexpr boost::array<T, 3> a2 = a1;
STATIC_ASSERT( a1[0] == a2[0] );
STATIC_ASSERT( a1[1] == a2[1] );
STATIC_ASSERT( a1[2] == a2[2] );
}
template<class T> void test3()
{
constexpr boost::array<T, 0> a1 = {};
constexpr boost::array<T, 0> a2 = a1;
(void)a1;
(void)a2;
}
int main()
{
test1<int>();
test2<int>();
test3<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>

View File

@@ -0,0 +1,47 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_MSVC < 1910")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr boost::array<T, N> a = {};
STATIC_ASSERT( a.data() == a.elems );
}
template<class T> void test2()
{
constexpr boost::array<T, 0> a = {};
STATIC_ASSERT( a.data() == 0 );
}
int main()
{
test1<int, 1>();
test1<int, 7>();
test2<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>

View File

@@ -1,11 +1,15 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {
{ {

55
test/array_eq_test_cx.cpp Normal file
View File

@@ -0,0 +1,55 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr boost::array<T, N> a1 = {};
constexpr boost::array<T, N> a2 = {};
STATIC_ASSERT( a1 == a2 );
STATIC_ASSERT( !( a1 != a2 ) );
}
template<class T> void test2()
{
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 4 }};
STATIC_ASSERT( a1 == a2 );
STATIC_ASSERT( !( a1 != a2 ) );
}
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 5 }};
STATIC_ASSERT( !( a1 == a2 ) );
STATIC_ASSERT( a1 != a2 );
}
}
int main()
{
test1<int, 0>();
test1<int, 1>();
test1<int, 7>();
test2<int>();
}
#endif

View File

@@ -1,11 +1,15 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {
boost::array<T, N> a = {}; boost::array<T, N> a = {};

View File

@@ -0,0 +1,51 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> constexpr boost::array<T, N> filled( T const& v )
{
boost::array<T, N> r = {};
r.fill( v );
return r;
}
template<class T> void test1()
{
constexpr boost::array<T, 4> a1 = filled<T, 4>( 7 );
STATIC_ASSERT( a1[0] == 7 );
STATIC_ASSERT( a1[1] == 7 );
STATIC_ASSERT( a1[2] == 7 );
STATIC_ASSERT( a1[3] == 7 );
}
template<class T> void test2()
{
constexpr boost::array<T, 0> a1 = filled<T, 0>( 7 );
(void)a1;
}
int main()
{
test1<int>();
test2<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>

View File

@@ -0,0 +1,42 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_MSVC < 1910")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T> void test()
{
constexpr boost::array<T, 4> a = {{ 1, 2, 3, 4 }};
STATIC_ASSERT( boost::get<0>( a ) == 1 );
STATIC_ASSERT( boost::get<1>( a ) == 2 );
STATIC_ASSERT( boost::get<2>( a ) == 3 );
STATIC_ASSERT( boost::get<3>( a ) == 4 );
}
int main()
{
test<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -8,6 +8,10 @@
#include <boost/config/workaround.hpp> #include <boost/config/workaround.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test1() template<class T, std::size_t N> void test1()
{ {
boost::array<T, N> a = {{}}; boost::array<T, N> a = {{}};
@@ -46,11 +50,11 @@ template<class T> void test4()
int main() int main()
{ {
// test1<int, 0>(); test1<int, 0>();
test1<int, 1>(); test1<int, 1>();
test1<int, 7>(); test1<int, 7>();
// test1<int const, 0>(); test1<int const, 0>();
test1<int const, 1>(); test1<int const, 1>();
test1<int const, 7>(); test1<int const, 7>();
@@ -58,7 +62,7 @@ int main()
test2<int, 1>(); test2<int, 1>();
test2<int, 7>(); test2<int, 7>();
// test2<int const, 0>(); test2<int const, 0>();
#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) || BOOST_WORKAROUND(BOOST_GCC, < 50000) #if BOOST_WORKAROUND(BOOST_MSVC, < 1910) || BOOST_WORKAROUND(BOOST_GCC, < 50000)

View File

@@ -0,0 +1,79 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T> void test1()
{
constexpr boost::array<T, 1> a = {{}};
STATIC_ASSERT( a[0] == 0 );
}
template<class T> void test2()
{
constexpr boost::array<T, 2> a = {};
STATIC_ASSERT( a[0] == 0 );
STATIC_ASSERT( a[1] == 0 );
}
template<class T> void test3()
{
constexpr boost::array<T, 3> a = {{ 1, 2, 3 }};
STATIC_ASSERT( a[0] == 1 );
STATIC_ASSERT( a[1] == 2 );
STATIC_ASSERT( a[2] == 3 );
}
template<class T> void test4()
{
constexpr boost::array<T, 4> a = { 1, 2, 3, 4 };
STATIC_ASSERT( a[0] == 1 );
STATIC_ASSERT( a[1] == 2 );
STATIC_ASSERT( a[2] == 3 );
STATIC_ASSERT( a[3] == 4 );
}
template<class T> void test5()
{
constexpr boost::array<T, 0> a = {{}};
(void)a;
}
template<class T> void test6()
{
constexpr boost::array<T, 0> a = {};
(void)a;
}
int main()
{
test1<int>();
test2<int>();
test3<int>();
test4<int>();
test5<int>();
test6<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -94,11 +94,11 @@ template<class T> void test2()
int main() int main()
{ {
// test<int, 0>(); test<int, 0>();
test<int, 1>(); test<int, 1>();
test<int, 7>(); test<int, 7>();
// test<int const, 0>(); test<int const, 0>();
test<int const, 1>(); test<int const, 1>();
test<int const, 7>(); test<int const, 7>();

View File

@@ -0,0 +1,55 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1910)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_MSVC < 1910")
#elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_GCC < 50000")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr boost::array<T, N> a = {};
STATIC_ASSERT( a.begin() == a.data() );
STATIC_ASSERT( a.end() == a.data() + N );
STATIC_ASSERT( a.cbegin() == a.data() );
STATIC_ASSERT( a.cend() == a.data() + N );
}
template<class T> void test2()
{
constexpr boost::array<T, 0> a = {};
STATIC_ASSERT( a.begin() == a.end() );
STATIC_ASSERT( a.cbegin() == a.cend() );
}
int main()
{
test1<int, 0>();
test1<int, 1>();
test1<int, 7>();
test2<int>();
}
#endif

View File

@@ -1,11 +1,15 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {
{ {

74
test/array_lt_test_cx.cpp Normal file
View File

@@ -0,0 +1,74 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr boost::array<T, N> a1 = {};
constexpr boost::array<T, N> a2 = {};
STATIC_ASSERT( !( a1 < a2 ) );
STATIC_ASSERT( !( a1 > a2 ) );
STATIC_ASSERT( a1 <= a2 );
STATIC_ASSERT( a1 >= a2 );
}
template<class T> void test2()
{
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 4 }};
STATIC_ASSERT( !( a1 < a2 ) );
STATIC_ASSERT( !( a1 > a2 ) );
STATIC_ASSERT( a1 <= a2 );
STATIC_ASSERT( a1 >= a2 );
}
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 5 }};
STATIC_ASSERT( a1 < a2 );
STATIC_ASSERT( !( a1 > a2 ) );
STATIC_ASSERT( a1 <= a2 );
STATIC_ASSERT( !( a1 >= a2 ) );
}
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 2 }};
STATIC_ASSERT( !( a1 < a2 ) );
STATIC_ASSERT( a1 > a2 );
STATIC_ASSERT( !( a1 <= a2 ) );
STATIC_ASSERT( a1 >= a2 );
}
}
int main()
{
test1<int, 0>();
test1<int, 1>();
test1<int, 7>();
test2<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -76,11 +76,11 @@ template<class T, std::size_t N> void test()
int main() int main()
{ {
// test<int, 0>(); test<int, 0>();
test<int, 1>(); test<int, 1>();
test<int, 7>(); test<int, 7>();
// test<int const, 0>(); test<int const, 0>();
test<int const, 1>(); test<int const, 1>();
test<int const, 7>(); test<int const, 7>();

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
@@ -15,6 +15,8 @@ template<class T, std::size_t N> void test1()
BOOST_TEST_EQ( a.size(), N ); BOOST_TEST_EQ( a.size(), N );
BOOST_TEST_EQ( a.empty(), N == 0 ); BOOST_TEST_EQ( a.empty(), N == 0 );
BOOST_TEST_EQ( a.max_size(), N ); BOOST_TEST_EQ( a.max_size(), N );
(void)a; // msvc-12.0
} }
{ {
@@ -23,6 +25,8 @@ template<class T, std::size_t N> void test1()
BOOST_TEST_EQ( a.size(), N ); BOOST_TEST_EQ( a.size(), N );
BOOST_TEST_EQ( a.empty(), N == 0 ); BOOST_TEST_EQ( a.empty(), N == 0 );
BOOST_TEST_EQ( a.max_size(), N ); BOOST_TEST_EQ( a.max_size(), N );
(void)a; // msvc-12.0
} }
} }
@@ -49,11 +53,11 @@ template<class T, std::size_t N> void test3()
int main() int main()
{ {
// test1<int, 0>(); test1<int, 0>();
test1<int, 1>(); test1<int, 1>();
test1<int, 7>(); test1<int, 7>();
// test1<int const, 0>(); test1<int const, 0>();
test1<int const, 1>(); test1<int const, 1>();
test1<int const, 7>(); test1<int const, 7>();

View File

@@ -0,0 +1,64 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX11_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr boost::array<T, N> a = {};
STATIC_ASSERT( a.size() == N );
STATIC_ASSERT( a.empty() == (N == 0) );
STATIC_ASSERT( a.max_size() == N );
}
template<class T, std::size_t N> void test2()
{
typedef boost::array<T, N> A;
STATIC_ASSERT( A().size() == N );
STATIC_ASSERT( A().empty() == (N == 0) );
STATIC_ASSERT( A().max_size() == N );
}
// the functions are static, which deviates from the standard
template<class T, std::size_t N> void test3()
{
typedef boost::array<T, N> A;
STATIC_ASSERT( A::size() == N );
STATIC_ASSERT( A::empty() == (N == 0) );
STATIC_ASSERT( A::max_size() == N );
STATIC_ASSERT( A::static_size == N );
}
int main()
{
test1<int, 0>();
test1<int, 1>();
test1<int, 7>();
test2<int, 0>();
test2<int, 1>();
test2<int, 7>();
test3<int, 0>();
test3<int, 1>();
test3<int, 7>();
}
#endif

View File

@@ -1,11 +1,15 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {
boost::array<T, N> a1 = {}; boost::array<T, N> a1 = {};

View File

@@ -1,11 +1,15 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp> #include <boost/core/lightweight_test.hpp>
#include <cstddef> #include <cstddef>
#if defined(_MSC_VER)
# pragma warning(disable: 4702) // unreachable code
#endif
template<class T, std::size_t N> void test() template<class T, std::size_t N> void test()
{ {
boost::array<T, N> a1 = {}; boost::array<T, N> a1 = {};

102
test/array_thw_test.cpp Normal file
View File

@@ -0,0 +1,102 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <cstddef>
#if defined(__has_include)
# if __has_include(<compare>)
# define HAS_COMPARE
# endif
#endif
#if !defined(__cpp_impl_three_way_comparison)
BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is not defined" )
int main() {}
#elif !( __cpp_impl_three_way_comparison >= 201907L )
BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is defined to " BOOST_STRINGIZE(__cpp_impl_three_way_comparison) )
int main() {}
#elif !defined(HAS_COMPARE)
BOOST_PRAGMA_MESSAGE( "Test skipped because <compare> is not available" )
int main() {}
#else
template<class T, std::size_t N> void test()
{
constexpr auto eq = 0 <=> 0;
constexpr auto lt = 0 <=> 1;
constexpr auto gt = 1 <=> 0;
{
boost::array<T, N> const a1 = {};
boost::array<T, N> const a2 = {};
BOOST_TEST( ( a1 <=> a2 ) == eq );
}
{
boost::array<T, N> a1;
boost::array<T, N> a2;
a1.fill( 1 );
a2.fill( 1 );
BOOST_TEST( ( a1 <=> a2 ) == eq );
}
for( std::size_t i = 0; i < N; ++i )
{
boost::array<T, N> a1;
boost::array<T, N> a2;
a1.fill( 1 );
a2.fill( 1 );
a1[ i ] = 0;
BOOST_TEST( ( a1 <=> a2 ) == lt );
{
boost::array<T, N> const a3 = a1;
boost::array<T, N> const a4 = a2;
BOOST_TEST( ( a3 <=> a4 ) == lt );
}
a1[ i ] = 2;
BOOST_TEST( ( a1 <=> a2 ) == gt );
{
boost::array<T, N> const a3 = a1;
boost::array<T, N> const a4 = a2;
BOOST_TEST( ( a3 <=> a4 ) == gt );
}
}
}
int main()
{
test<int, 0>();
test<int, 1>();
test<int, 7>();
test<float, 0>();
test<float, 1>();
test<float, 7>();
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,81 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(__has_include)
# if __has_include(<compare>)
# define HAS_COMPARE
# endif
#endif
#if !defined(__cpp_impl_three_way_comparison)
BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is not defined" )
int main() {}
#elif !( __cpp_impl_three_way_comparison >= 201907L )
BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is defined to " BOOST_STRINGIZE(__cpp_impl_three_way_comparison) )
int main() {}
#elif !defined(HAS_COMPARE)
BOOST_PRAGMA_MESSAGE( "Test skipped because <compare> is not available" )
int main() {}
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
template<class T, std::size_t N> void test1()
{
constexpr auto eq = 0 <=> 0;
constexpr boost::array<T, N> a1 = {};
constexpr boost::array<T, N> a2 = {};
STATIC_ASSERT( ( a1 <=> a2 ) == eq );
}
template<class T> void test2()
{
constexpr auto eq = 0 <=> 0;
constexpr auto lt = 0 <=> 1;
constexpr auto gt = 1 <=> 0;
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 4 }};
STATIC_ASSERT( ( a1 <=> a2 ) == eq );
}
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 5 }};
STATIC_ASSERT( ( a1 <=> a2 ) == lt );
}
{
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 2 }};
STATIC_ASSERT( ( a1 <=> a2 ) == gt );
}
}
int main()
{
test1<int, 0>();
test1<int, 1>();
test1<int, 7>();
test2<int>();
}
#endif

View File

@@ -1,6 +1,6 @@
// Copyright 2025 Peter Dimov // Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>
#include <boost/core/lightweight_test_trait.hpp> #include <boost/core/lightweight_test_trait.hpp>

View File

@@ -1,6 +1,6 @@
// Copyright 2023 Peter Dimov. // Copyright 2023 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt) // https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp> #include <boost/array.hpp>

109
test/to_array_test.cpp Normal file
View File

@@ -0,0 +1,109 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <memory>
#include <utility>
boost::array<int, 3> f1()
{
boost::array<int, 3> r = {{ 1, 2, 3 }};
return r;
}
boost::array<int, 3> const f2()
{
boost::array<int, 3> r = {{ 1, 2, 3 }};
return r;
}
int main()
{
{
int a[] = { 1, 2, 3 };
boost::array<int, 3> b = boost::to_array( a );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
{
int const a[] = { 1, 2, 3 };
boost::array<int, 3> b = boost::to_array( a );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
{
boost::array<int, 3> b = boost::to_array( f1().elems );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
{
boost::array<int, 3> b = boost::to_array( f2().elems );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
#if BOOST_CXX_VERSION >= 201103L
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
{
int a[] = { 1, 2, 3 };
boost::array<int, 3> b = boost::to_array( std::move( a ) );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
{
int const a[] = { 1, 2, 3 };
boost::array<int, 3> b = boost::to_array( std::move( a ) );
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
#endif
#if !BOOST_WORKAROUND(BOOST_GCC, < 40900) && !BOOST_WORKAROUND(BOOST_CLANG_VERSION, < 30800)
{
boost::array<int, 3> b = boost::to_array({ 1, 2, 3 });
BOOST_TEST_EQ( b[0], 1 );
BOOST_TEST_EQ( b[1], 2 );
BOOST_TEST_EQ( b[2], 3 );
}
#endif
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920)
{
std::unique_ptr<int> a[] = { {}, {}, {} };
boost::array<std::unique_ptr<int>, 3> b = boost::to_array( std::move( a ) );
(void)b;
}
#endif
#endif
return boost::report_errors();
}

32
test/to_array_test_cx.cpp Normal file
View File

@@ -0,0 +1,32 @@
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/array.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>
#if defined(BOOST_NO_CXX14_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
#else
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
int main()
{
{
constexpr int a[] = { 1, 2, 3, 4 };
constexpr boost::array<int, 4> b = boost::to_array( a );
STATIC_ASSERT( b[0] == 1 );
STATIC_ASSERT( b[1] == 2 );
STATIC_ASSERT( b[2] == 3 );
STATIC_ASSERT( b[3] == 4 );
}
}
#endif