Skip to content

Commit

Permalink
Add array_lt_test_cx.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Jan 25, 2025
1 parent a211468 commit 5c05254
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/boost/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,15 @@ namespace boost {
}

template<class T, std::size_t N>
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y) {
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
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;
}

template<class T, std::size_t N>
Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ compile array_access_test_cx.cpp ;
# C++14 constexpr

compile array_eq_test_cx.cpp ;
compile array_lt_test_cx.cpp ;

#

Expand Down
74 changes: 74 additions & 0 deletions test/array_lt_test_cx.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5c05254

Please sign in to comment.