diff --git a/include/boost/array.hpp b/include/boost/array.hpp index 2ecd800e..6266ddc2 100644 --- a/include/boost/array.hpp +++ b/include/boost/array.hpp @@ -321,25 +321,36 @@ namespace boost { // comparisons template - BOOST_CXX14_CONSTEXPR bool operator== (const array& x, const array& y) { - return std::equal(x.begin(), x.end(), y.begin()); - } - 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 false; + } + + return true; } + template BOOST_CXX14_CONSTEXPR bool operator!= (const array& x, const array& y) { return !(x==y); } + + template + BOOST_CXX14_CONSTEXPR bool operator< (const array& x, const array& y) { + return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()); + } + template BOOST_CXX14_CONSTEXPR bool operator> (const array& x, const array& y) { return y BOOST_CXX14_CONSTEXPR bool operator<= (const array& x, const array& y) { return !(y BOOST_CXX14_CONSTEXPR bool operator>= (const array& x, const array& y) { return !(x +#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 ) ); +} + +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 ) ); + } + { + constexpr boost::array a1 = {{ 1, 2, 3, 4 }}; + constexpr boost::array a2 = {{ 1, 2, 3, 5 }}; + + STATIC_ASSERT( !( a1 == a2 ) ); + STATIC_ASSERT( a1 != a2 ); + } +} + +int main() +{ + test1(); + test1(); + test1(); + + test2(); +} + +#endif