Skip to content

Commit 5c05254

Browse files
committed
Add array_lt_test_cx.cpp
1 parent a211468 commit 5c05254

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

include/boost/array.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,15 @@ namespace boost {
337337
}
338338

339339
template<class T, std::size_t N>
340-
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y) {
341-
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
340+
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y)
341+
{
342+
for( std::size_t i = 0; i < N; ++i )
343+
{
344+
if( x[ i ] < y[ i ] ) return true;
345+
if( y[ i ] < x[ i ] ) return false;
346+
}
347+
348+
return false;
342349
}
343350

344351
template<class T, std::size_t N>

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ compile array_access_test_cx.cpp ;
5959
# C++14 constexpr
6060

6161
compile array_eq_test_cx.cpp ;
62+
compile array_lt_test_cx.cpp ;
6263

6364
#
6465

test/array_lt_test_cx.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2025 Peter Dimov
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt)
4+
5+
#include <boost/array.hpp>
6+
#include <boost/config.hpp>
7+
#include <boost/config/pragma_message.hpp>
8+
#include <boost/config/workaround.hpp>
9+
#include <cstddef>
10+
11+
#if defined(BOOST_NO_CXX14_CONSTEXPR)
12+
13+
BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX14_CONSTEXPR is defined")
14+
15+
#else
16+
17+
#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
18+
19+
template<class T, std::size_t N> void test1()
20+
{
21+
constexpr boost::array<T, N> a1 = {};
22+
constexpr boost::array<T, N> a2 = {};
23+
24+
STATIC_ASSERT( !( a1 < a2 ) );
25+
STATIC_ASSERT( !( a1 > a2 ) );
26+
27+
STATIC_ASSERT( a1 <= a2 );
28+
STATIC_ASSERT( a1 >= a2 );
29+
}
30+
31+
template<class T> void test2()
32+
{
33+
{
34+
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
35+
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 4 }};
36+
37+
STATIC_ASSERT( !( a1 < a2 ) );
38+
STATIC_ASSERT( !( a1 > a2 ) );
39+
40+
STATIC_ASSERT( a1 <= a2 );
41+
STATIC_ASSERT( a1 >= a2 );
42+
}
43+
{
44+
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
45+
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 5 }};
46+
47+
STATIC_ASSERT( a1 < a2 );
48+
STATIC_ASSERT( !( a1 > a2 ) );
49+
50+
STATIC_ASSERT( a1 <= a2 );
51+
STATIC_ASSERT( !( a1 >= a2 ) );
52+
}
53+
{
54+
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
55+
constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 2 }};
56+
57+
STATIC_ASSERT( !( a1 < a2 ) );
58+
STATIC_ASSERT( a1 > a2 );
59+
60+
STATIC_ASSERT( !( a1 <= a2 ) );
61+
STATIC_ASSERT( a1 >= a2 );
62+
}
63+
}
64+
65+
int main()
66+
{
67+
test1<int, 0>();
68+
test1<int, 1>();
69+
test1<int, 7>();
70+
71+
test2<int>();
72+
}
73+
74+
#endif

0 commit comments

Comments
 (0)