forked from boostorg/array
Compare commits
10 Commits
feature/re
...
feature/re
Author | SHA1 | Date | |
---|---|---|---|
b147799665 | |||
acef60446a | |||
3d9f39814c | |||
89f09e33f1 | |||
43326390d9 | |||
c95d855018 | |||
0a72026887 | |||
d2c295b85f | |||
324827cfc0 | |||
9253e8f1af |
@ -14,3 +14,7 @@ http://www.boost.org/LICENSE_1_0.txt
|
|||||||
|
|
||||||
* Converted documentation to AsciiDoc (Christian Mazakas).
|
* Converted documentation to AsciiDoc (Christian Mazakas).
|
||||||
* Added `noexcept` and `constexpr` as appropriate.
|
* 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`.
|
||||||
|
@ -207,13 +207,13 @@ 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
|
||||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
@ -303,19 +303,10 @@ namespace boost {
|
|||||||
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
|
||||||
@ -404,14 +395,6 @@ namespace boost {
|
|||||||
return arg.elems;
|
return arg.elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
||||||
BOOST_CXX14_CONSTEXPR 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" );
|
||||||
|
@ -59,6 +59,9 @@ compile array_get_test_cx.cpp ;
|
|||||||
|
|
||||||
# C++14 constexpr
|
# 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_eq_test_cx.cpp ;
|
||||||
compile array_lt_test_cx.cpp ;
|
compile array_lt_test_cx.cpp ;
|
||||||
|
|
||||||
|
@ -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!
|
||||||
|
45
test/array_access_test_cx2.cpp
Normal file
45
test/array_access_test_cx2.cpp
Normal 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
|
54
test/array_assign_test_cx.cpp
Normal file
54
test/array_assign_test_cx.cpp
Normal 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
|
51
test/array_fill_test_cx.cpp
Normal file
51
test/array_fill_test_cx.cpp
Normal 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
|
@ -58,7 +58,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)
|
||||||
|
|
||||||
|
@ -39,20 +39,17 @@ template<class T> void test2()
|
|||||||
{
|
{
|
||||||
constexpr boost::array<T, 0> a = {};
|
constexpr boost::array<T, 0> a = {};
|
||||||
|
|
||||||
// iterator access is not constexpr for boost::array<T, 0>
|
|
||||||
// it is for std::array<T, 0>, though, so we should change it
|
|
||||||
|
|
||||||
STATIC_ASSERT( a.begin() == a.end() );
|
STATIC_ASSERT( a.begin() == a.end() );
|
||||||
STATIC_ASSERT( a.cbegin() == a.cend() );
|
STATIC_ASSERT( a.cbegin() == a.cend() );
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// test1<int, 0>();
|
test1<int, 0>();
|
||||||
test1<int, 1>();
|
test1<int, 1>();
|
||||||
test1<int, 7>();
|
test1<int, 7>();
|
||||||
|
|
||||||
// test2<int>();
|
test2<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user