diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 6266ddc..0506326 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -337,8 +337,15 @@ namespace boost { } template - BOOST_CXX14_CONSTEXPR bool operator< (const array& x, const array& y) { - return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); + BOOST_CXX14_CONSTEXPR bool operator< (const array& x, const array& 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 diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ad3173e..2a41c8f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 ; # diff --git a/test/array_lt_test_cx.cpp b/test/array_lt_test_cx.cpp new file mode 100644 index 0000000..d01c9e4 --- /dev/null +++ b/test/array_lt_test_cx.cpp @@ -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 +#include +#include +#include +#include + +#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 void test1() +{ + constexpr boost::array a1 = {}; + constexpr boost::array a2 = {}; + + STATIC_ASSERT( !( a1 < a2 ) ); + STATIC_ASSERT( !( a1 > a2 ) ); + + STATIC_ASSERT( a1 <= a2 ); + STATIC_ASSERT( a1 >= a2 ); +} + +template void test2() +{ + { + constexpr boost::array a1 = {{ 1, 2, 3, 4 }}; + constexpr boost::array a2 = {{ 1, 2, 3, 4 }}; + + STATIC_ASSERT( !( a1 < a2 ) ); + STATIC_ASSERT( !( a1 > a2 ) ); + + STATIC_ASSERT( a1 <= a2 ); + STATIC_ASSERT( a1 >= a2 ); + } + { + constexpr boost::array a1 = {{ 1, 2, 3, 4 }}; + constexpr boost::array a2 = {{ 1, 2, 3, 5 }}; + + STATIC_ASSERT( a1 < a2 ); + STATIC_ASSERT( !( a1 > a2 ) ); + + STATIC_ASSERT( a1 <= a2 ); + STATIC_ASSERT( !( a1 >= a2 ) ); + } + { + constexpr boost::array a1 = {{ 1, 2, 3, 4 }}; + constexpr boost::array a2 = {{ 1, 2, 3, 2 }}; + + STATIC_ASSERT( !( a1 < a2 ) ); + STATIC_ASSERT( a1 > a2 ); + + STATIC_ASSERT( !( a1 <= a2 ) ); + STATIC_ASSERT( a1 >= a2 ); + } +} + +int main() +{ + test1(); + test1(); + test1(); + + test2(); +} + +#endif