mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Feature/span equality operators (#670)
* feat: implement equality operator * test: test equality operator * feat: implement not equal operator * test: test not equal operator --------- Co-authored-by: Kurtis Thrush <kthrush@jlg.com>
This commit is contained in:
parent
8634480fa6
commit
36a9d70d7c
@ -345,6 +345,24 @@ namespace etl
|
||||
return pbegin[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Compare two spans for equality.
|
||||
//*************************************************************************
|
||||
template <typename Type2, size_t N2, etl::enable_if_t<etl::is_same<etl::remove_cv_t<Type2>, value_type>::value, bool> = true>
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator==(const etl::span<Type2, N2>& other) const ETL_NOEXCEPT
|
||||
{
|
||||
return ((pbegin == other.pbegin) && (Extent == other.size()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Compare two spans for non-equality.
|
||||
//*************************************************************************
|
||||
template <typename Type2, size_t N2, etl::enable_if_t<etl::is_same<etl::remove_cv_t<Type2>, value_type>::value, bool> = true>
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator!=(const etl::span<Type2, N2>& other) const ETL_NOEXCEPT
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view over the first COUNT elements of this span.
|
||||
//*************************************************************************
|
||||
@ -731,6 +749,24 @@ namespace etl
|
||||
return pbegin[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Compare two spans for equality.
|
||||
//*************************************************************************
|
||||
template <typename Type2, etl::enable_if_t<etl::is_same<etl::remove_cv_t<Type2>, value_type>::value, bool> = true>
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator==(const etl::span<Type2>& other) const ETL_NOEXCEPT
|
||||
{
|
||||
return ((pbegin == other.pbegin) && (pend == other.pend));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Compare two spans for non-equality.
|
||||
//*************************************************************************
|
||||
template <typename Type2, etl::enable_if_t<etl::is_same<etl::remove_cv_t<Type2>, value_type>::value, bool> = true>
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool operator!=(const etl::span<Type2>& other) const ETL_NOEXCEPT
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Obtains a span that is a view over the first COUNT elements of this span.
|
||||
//*************************************************************************
|
||||
|
||||
@ -970,6 +970,34 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_equality)
|
||||
{
|
||||
etl::array data1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
etl::array data2{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
View view1{data1};
|
||||
View view2{data1};
|
||||
View view3{data2};
|
||||
|
||||
CHECK_TRUE((view1 == view2));
|
||||
CHECK_FALSE((view1 == view3));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_not_equal)
|
||||
{
|
||||
etl::array data1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
etl::array data2{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
View view1{data1};
|
||||
View view2{data1};
|
||||
View view3{data2};
|
||||
|
||||
CHECK_FALSE((view1 != view2));
|
||||
CHECK_TRUE((view1 != view3));
|
||||
}
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
};
|
||||
}
|
||||
|
||||
@ -960,6 +960,34 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_equality)
|
||||
{
|
||||
etl::array data1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
etl::array data2{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
View view1{data1};
|
||||
View view2{data1};
|
||||
View view3{data2};
|
||||
|
||||
CHECK_TRUE((view1 == view2));
|
||||
CHECK_FALSE((view1 == view3));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_not_equal)
|
||||
{
|
||||
etl::array data1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
etl::array data2{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
View view1{data1};
|
||||
View view2{data1};
|
||||
View view3{data2};
|
||||
|
||||
CHECK_FALSE((view1 != view2));
|
||||
CHECK_TRUE((view1 != view3));
|
||||
}
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user