Compare commits

..

9 Commits

Author SHA1 Message Date
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
9 changed files with 194 additions and 34 deletions
+2
View File
@@ -14,3 +14,5 @@ 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.
+5 -5
View File
@@ -19,7 +19,7 @@ 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> template<typename T, std::size_t N>
constexpr void swap(array<T, N>&, 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>
constexpr bool operator==(const array<T, N>&, const array<T, N>&); constexpr bool operator==(const array<T, N>&, const array<T, N>&);
@@ -120,7 +120,7 @@ public:
// modifiers // modifiers
constexpr void swap(array<T, N>&); swap(array<T, N>&);
constexpr void fill(const T&); constexpr void fill(const T&);
void assign(const T&); // deprecated void assign(const T&); // deprecated
@@ -290,10 +290,10 @@ Remarks: :: This function is deprecated. Use `data()` instead.
### Modifiers ### Modifiers
``` ```
constexpr void swap(array<T, N>& other); void swap(array<T, N>& other);
``` ```
[horizontal] [horizontal]
Effects: :: for each `i` in `[0..N)`, calls `swap(elems[i], other.elems[i])`. Effects: :: `std::swap(elems, other.elems)`.
Complexity: :: linear in `N`. Complexity: :: linear in `N`.
--- ---
@@ -319,7 +319,7 @@ Remarks: :: An obsolete and deprecated spelling of `fill`. Use `fill` instead.
``` ```
template<typename T, std::size_t N> template<typename T, std::size_t N>
constexpr void swap(array<T, N>& x, array<T, N>& y); void swap(array<T, N>& x, array<T, N>& y);
``` ```
[horizontal] [horizontal]
Effects: :: `x.swap(y)`. Effects: :: `x.swap(y)`.
+30 -25
View File
@@ -37,18 +37,17 @@
#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:4610) // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required # pragma warning(disable:4512) // boost::array<T,N>' : assignment operator could not be generated
# pragma warning(disable:4610) // class 'boost::array<T,N>' can never be instantiated - user defined constructor required
#endif #endif
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/core/invoke_swap.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <algorithm>
#include <iterator> #include <iterator>
#include <stdexcept> #include <stdexcept>
#include <utility>
#include <cstddef> #include <cstddef>
namespace boost { namespace boost {
@@ -143,9 +142,9 @@ 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 // direct access to data
@@ -158,15 +157,29 @@ namespace boost {
// 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;
} }
// fill with one value // fill with one value
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 // an obsolete synonym for fill
@@ -264,7 +277,8 @@ 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 // direct access to data
@@ -289,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
@@ -370,7 +375,7 @@ 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);
} }
+3
View File
@@ -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 ;
+3 -3
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 {
+45
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
+54
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
+51
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
+1 -1
View File
@@ -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)