forked from boostorg/array
Add array_eq_test_cx.cpp
This commit is contained in:
@ -321,25 +321,36 @@ namespace boost {
|
|||||||
|
|
||||||
// comparisons
|
// comparisons
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CXX14_CONSTEXPR bool operator== (const array<T,N>& x, const array<T,N>& y) {
|
BOOST_CXX14_CONSTEXPR bool operator== (const array<T,N>& x, const array<T,N>& y)
|
||||||
return std::equal(x.begin(), x.end(), y.begin());
|
{
|
||||||
}
|
for( std::size_t i = 0; i < N; ++i )
|
||||||
template<class T, std::size_t N>
|
{
|
||||||
BOOST_CXX14_CONSTEXPR bool operator< (const array<T,N>& x, const array<T,N>& y) {
|
if( !( x[ i ] == y[ i ] ) ) return false;
|
||||||
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CXX14_CONSTEXPR bool operator!= (const array<T,N>& x, const array<T,N>& y) {
|
BOOST_CXX14_CONSTEXPR bool operator!= (const array<T,N>& x, const array<T,N>& y) {
|
||||||
return !(x==y);
|
return !(x==y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CXX14_CONSTEXPR bool operator> (const array<T,N>& x, const array<T,N>& y) {
|
BOOST_CXX14_CONSTEXPR bool operator> (const array<T,N>& x, const array<T,N>& y) {
|
||||||
return y<x;
|
return y<x;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CXX14_CONSTEXPR bool operator<= (const array<T,N>& x, const array<T,N>& y) {
|
BOOST_CXX14_CONSTEXPR bool operator<= (const array<T,N>& x, const array<T,N>& y) {
|
||||||
return !(y<x);
|
return !(y<x);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
BOOST_CXX14_CONSTEXPR bool operator>= (const array<T,N>& x, const array<T,N>& y) {
|
BOOST_CXX14_CONSTEXPR bool operator>= (const array<T,N>& x, const array<T,N>& y) {
|
||||||
return !(x<y);
|
return !(x<y);
|
||||||
|
@ -47,7 +47,7 @@ run array_eq_test.cpp ;
|
|||||||
run array_lt_test.cpp ;
|
run array_lt_test.cpp ;
|
||||||
run array_get_test.cpp ;
|
run array_get_test.cpp ;
|
||||||
|
|
||||||
#
|
# C++11 constexpr
|
||||||
|
|
||||||
compile array_init_test_cx.cpp ;
|
compile array_init_test_cx.cpp ;
|
||||||
compile array_copy_test_cx.cpp ;
|
compile array_copy_test_cx.cpp ;
|
||||||
@ -56,6 +56,10 @@ compile array_iterator_test_cx.cpp ;
|
|||||||
compile array_size_test_cx.cpp ;
|
compile array_size_test_cx.cpp ;
|
||||||
compile array_access_test_cx.cpp ;
|
compile array_access_test_cx.cpp ;
|
||||||
|
|
||||||
|
# C++14 constexpr
|
||||||
|
|
||||||
|
compile array_eq_test_cx.cpp ;
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
run quick.cpp ;
|
run quick.cpp ;
|
||||||
|
55
test/array_eq_test_cx.cpp
Normal file
55
test/array_eq_test_cx.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// 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 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ) );
|
||||||
|
}
|
||||||
|
{
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
test1<int, 0>();
|
||||||
|
test1<int, 1>();
|
||||||
|
test1<int, 7>();
|
||||||
|
|
||||||
|
test2<int>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user