Commit 73564b6c authored by jdoerrie's avatar jdoerrie Committed by Commit Bot

[base] Remove base::span's comparison operators

At the recent ISO C++ Committee meeting in San Diego it was decided [1]
to make std::span SemiRegular and drop its comparison operators [2]. For
further info see also this blog post [3].

This change updates the base::span implemention appropriately and
replaces prior usages of the comparison operators with their STL
algorithm equivalent.

[1] http://redd.it/9vwvbz
[2] https://wg21.link/p1085
[3] https://abseil.io/blog/20180531-regular-types#evaluating-span

Bug: 828324
Change-Id: I94e94450df5f233b6de81da81f309386e0dcf4a7
Reviewed-on: https://chromium-review.googlesource.com/c/1337628Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRyan Sleevi <rsleevi@chromium.org>
Reviewed-by: default avatarJohn Rummell <jrummell@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJun Choi <hongjunchoi@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608702}
parent 6256f554
...@@ -424,39 +424,6 @@ class span : public internal::ExtentStorage<Extent> { ...@@ -424,39 +424,6 @@ class span : public internal::ExtentStorage<Extent> {
template <class T, size_t Extent> template <class T, size_t Extent>
constexpr size_t span<T, Extent>::extent; constexpr size_t span<T, Extent>::extent;
// [span.comparison], span comparison operators
// Relational operators. Equality is a element-wise comparison.
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator==(span<T, X> lhs, span<U, Y> rhs) noexcept {
return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend());
}
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator!=(span<T, X> lhs, span<U, Y> rhs) noexcept {
return !(lhs == rhs);
}
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator<(span<T, X> lhs, span<U, Y> rhs) noexcept {
return std::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(),
rhs.cend());
}
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator<=(span<T, X> lhs, span<U, Y> rhs) noexcept {
return !(rhs < lhs);
}
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator>(span<T, X> lhs, span<U, Y> rhs) noexcept {
return rhs < lhs;
}
template <typename T, size_t X, typename U, size_t Y>
constexpr bool operator>=(span<T, X> lhs, span<U, Y> rhs) noexcept {
return !(lhs < rhs);
}
// [span.objectrep], views of object representation // [span.objectrep], views of object representation
template <typename T, size_t X> template <typename T, size_t X>
span<const uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)> span<const uint8_t, (X == dynamic_extent ? dynamic_extent : sizeof(T) * X)>
......
...@@ -274,11 +274,13 @@ TEST(SpanTest, ConvertBetweenEquivalentTypes) { ...@@ -274,11 +274,13 @@ TEST(SpanTest, ConvertBetweenEquivalentTypes) {
span<int32_t> int32_t_span(vector); span<int32_t> int32_t_span(vector);
span<int> converted_span(int32_t_span); span<int> converted_span(int32_t_span);
EXPECT_EQ(int32_t_span, converted_span); EXPECT_EQ(int32_t_span.data(), converted_span.data());
EXPECT_EQ(int32_t_span.size(), converted_span.size());
span<int32_t, 5> static_int32_t_span(vector); span<int32_t, 5> static_int32_t_span(vector);
span<int, 5> static_converted_span(static_int32_t_span); span<int, 5> static_converted_span(static_int32_t_span);
EXPECT_EQ(static_int32_t_span, static_converted_span); EXPECT_EQ(static_int32_t_span.data(), static_converted_span.data());
EXPECT_EQ(static_int32_t_span.size(), static_converted_span.size());
} }
TEST(SpanTest, TemplatedFirst) { TEST(SpanTest, TemplatedFirst) {
...@@ -906,122 +908,6 @@ TEST(SpanTest, ReverseIterator) { ...@@ -906,122 +908,6 @@ TEST(SpanTest, ReverseIterator) {
span.crbegin(), span.crend())); span.crbegin(), span.crend()));
} }
TEST(SpanTest, Equality) {
static constexpr int kArray1[] = {3, 1, 4, 1, 5};
static constexpr int kArray2[] = {3, 1, 4, 1, 5};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 5> span2(kArray2);
EXPECT_EQ(span1, span2);
static constexpr int kArray3[] = {2, 7, 1, 8, 3};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 == span3);
static double kArray4[] = {2.0, 7.0, 1.0, 8.0, 3.0};
span<double, 5> span4(kArray4);
EXPECT_EQ(span3, span4);
}
TEST(SpanTest, Inequality) {
static constexpr int kArray1[] = {2, 3, 5, 7, 11};
static constexpr int kArray2[] = {1, 4, 6, 8, 9};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 5> span2(kArray2);
EXPECT_NE(span1, span2);
static constexpr int kArray3[] = {2, 3, 5, 7, 11};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 != span3);
static double kArray4[] = {1.0, 4.0, 6.0, 8.0, 9.0};
span<double, 5> span4(kArray4);
EXPECT_NE(span3, span4);
}
TEST(SpanTest, LessThan) {
static constexpr int kArray1[] = {2, 3, 5, 7, 11};
static constexpr int kArray2[] = {2, 3, 5, 7, 11, 13};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 6> span2(kArray2);
EXPECT_LT(span1, span2);
static constexpr int kArray3[] = {2, 3, 5, 7, 11};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 < span3);
static double kArray4[] = {2.0, 3.0, 5.0, 7.0, 11.0, 13.0};
span<double, 6> span4(kArray4);
EXPECT_LT(span3, span4);
}
TEST(SpanTest, LessEqual) {
static constexpr int kArray1[] = {2, 3, 5, 7, 11};
static constexpr int kArray2[] = {2, 3, 5, 7, 11, 13};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 6> span2(kArray2);
EXPECT_LE(span1, span1);
EXPECT_LE(span1, span2);
static constexpr int kArray3[] = {2, 3, 5, 7, 10};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 <= span3);
static double kArray4[] = {2.0, 3.0, 5.0, 7.0, 11.0, 13.0};
span<double, 6> span4(kArray4);
EXPECT_LE(span3, span4);
}
TEST(SpanTest, GreaterThan) {
static constexpr int kArray1[] = {2, 3, 5, 7, 11, 13};
static constexpr int kArray2[] = {2, 3, 5, 7, 11};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 5> span2(kArray2);
EXPECT_GT(span1, span2);
static constexpr int kArray3[] = {2, 3, 5, 7, 11, 13};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 > span3);
static double kArray4[] = {2.0, 3.0, 5.0, 7.0, 11.0};
span<double, 5> span4(kArray4);
EXPECT_GT(span3, span4);
}
TEST(SpanTest, GreaterEqual) {
static constexpr int kArray1[] = {2, 3, 5, 7, 11, 13};
static constexpr int kArray2[] = {2, 3, 5, 7, 11};
constexpr span<const int> span1(kArray1);
constexpr span<const int, 5> span2(kArray2);
EXPECT_GE(span1, span1);
EXPECT_GE(span1, span2);
static constexpr int kArray3[] = {2, 3, 5, 7, 12};
constexpr span<const int> span3(kArray3);
EXPECT_FALSE(span1 >= span3);
static double kArray4[] = {2.0, 3.0, 5.0, 7.0, 11.0};
span<double, 5> span4(kArray4);
EXPECT_GE(span3, span4);
}
TEST(SpanTest, AsBytes) { TEST(SpanTest, AsBytes) {
{ {
constexpr int kArray[] = {2, 3, 5, 7, 11, 13}; constexpr int kArray[] = {2, 3, 5, 7, 11, 13};
...@@ -1065,7 +951,8 @@ TEST(SpanTest, MakeSpanFromDataAndSize) { ...@@ -1065,7 +951,8 @@ TEST(SpanTest, MakeSpanFromDataAndSize) {
std::vector<int> vector = {1, 1, 2, 3, 5, 8}; std::vector<int> vector = {1, 1, 2, 3, 5, 8};
span<int> span(vector.data(), vector.size()); span<int> span(vector.data(), vector.size());
auto made_span = make_span(vector.data(), vector.size()); auto made_span = make_span(vector.data(), vector.size());
EXPECT_EQ(span, made_span); EXPECT_EQ(span.data(), made_span.data());
EXPECT_EQ(span.size(), made_span.size());
static_assert(decltype(made_span)::extent == dynamic_extent, ""); static_assert(decltype(made_span)::extent == dynamic_extent, "");
} }
...@@ -1078,49 +965,56 @@ TEST(SpanTest, MakeSpanFromPointerPair) { ...@@ -1078,49 +965,56 @@ TEST(SpanTest, MakeSpanFromPointerPair) {
std::vector<int> vector = {1, 1, 2, 3, 5, 8}; std::vector<int> vector = {1, 1, 2, 3, 5, 8};
span<int> span(vector.data(), vector.size()); span<int> span(vector.data(), vector.size());
auto made_span = make_span(vector.data(), vector.data() + vector.size()); auto made_span = make_span(vector.data(), vector.data() + vector.size());
EXPECT_EQ(span, made_span); EXPECT_EQ(span.data(), made_span.data());
EXPECT_EQ(span.size(), made_span.size());
static_assert(decltype(made_span)::extent == dynamic_extent, ""); static_assert(decltype(made_span)::extent == dynamic_extent, "");
} }
TEST(SpanTest, MakeSpanFromConstexprArray) { TEST(SpanTest, MakeSpanFromConstexprArray) {
static constexpr int kArray[] = {1, 2, 3, 4, 5}; static constexpr int kArray[] = {1, 2, 3, 4, 5};
constexpr span<const int> span(kArray); constexpr span<const int> span(kArray);
EXPECT_EQ(span, make_span(kArray)); EXPECT_EQ(span.data(), make_span(kArray).data());
EXPECT_EQ(span.size(), make_span(kArray).size());
static_assert(decltype(make_span(kArray))::extent == 5, ""); static_assert(decltype(make_span(kArray))::extent == 5, "");
} }
TEST(SpanTest, MakeSpanFromStdArray) { TEST(SpanTest, MakeSpanFromStdArray) {
const std::array<int, 5> kArray = {{1, 2, 3, 4, 5}}; const std::array<int, 5> kArray = {{1, 2, 3, 4, 5}};
span<const int> span(kArray); span<const int> span(kArray);
EXPECT_EQ(span, make_span(kArray)); EXPECT_EQ(span.data(), make_span(kArray).data());
EXPECT_EQ(span.size(), make_span(kArray).size());
static_assert(decltype(make_span(kArray))::extent == 5, ""); static_assert(decltype(make_span(kArray))::extent == 5, "");
} }
TEST(SpanTest, MakeSpanFromConstContainer) { TEST(SpanTest, MakeSpanFromConstContainer) {
const std::vector<int> vector = {-1, -2, -3, -4, -5}; const std::vector<int> vector = {-1, -2, -3, -4, -5};
span<const int> span(vector); span<const int> span(vector);
EXPECT_EQ(span, make_span(vector)); EXPECT_EQ(span.data(), make_span(vector).data());
EXPECT_EQ(span.size(), make_span(vector).size());
static_assert(decltype(make_span(vector))::extent == dynamic_extent, ""); static_assert(decltype(make_span(vector))::extent == dynamic_extent, "");
} }
TEST(SpanTest, MakeStaticSpanFromConstContainer) { TEST(SpanTest, MakeStaticSpanFromConstContainer) {
const std::vector<int> vector = {-1, -2, -3, -4, -5}; const std::vector<int> vector = {-1, -2, -3, -4, -5};
span<const int, 5> span(vector); span<const int, 5> span(vector);
EXPECT_EQ(span, make_span<5>(vector)); EXPECT_EQ(span.data(), make_span<5>(vector).data());
EXPECT_EQ(span.size(), make_span<5>(vector).size());
static_assert(decltype(make_span<5>(vector))::extent == 5, ""); static_assert(decltype(make_span<5>(vector))::extent == 5, "");
} }
TEST(SpanTest, MakeSpanFromContainer) { TEST(SpanTest, MakeSpanFromContainer) {
std::vector<int> vector = {-1, -2, -3, -4, -5}; std::vector<int> vector = {-1, -2, -3, -4, -5};
span<int> span(vector); span<int> span(vector);
EXPECT_EQ(span, make_span(vector)); EXPECT_EQ(span.data(), make_span(vector).data());
EXPECT_EQ(span.size(), make_span(vector).size());
static_assert(decltype(make_span(vector))::extent == dynamic_extent, ""); static_assert(decltype(make_span(vector))::extent == dynamic_extent, "");
} }
TEST(SpanTest, MakeStaticSpanFromContainer) { TEST(SpanTest, MakeStaticSpanFromContainer) {
std::vector<int> vector = {-1, -2, -3, -4, -5}; std::vector<int> vector = {-1, -2, -3, -4, -5};
span<int, 5> span(vector); span<int, 5> span(vector);
EXPECT_EQ(span, make_span<5>(vector)); EXPECT_EQ(span.data(), make_span<5>(vector).data());
EXPECT_EQ(span.size(), make_span<5>(vector).size());
static_assert(decltype(make_span<5>(vector))::extent == 5, ""); static_assert(decltype(make_span<5>(vector))::extent == 5, "");
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "device/fido/ble/fido_ble_frames.h" #include "device/fido/ble/fido_ble_frames.h"
#include <algorithm>
#include <vector> #include <vector>
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -38,7 +39,9 @@ TEST(FidoBleFramesTest, InitializationFragment) { ...@@ -38,7 +39,9 @@ TEST(FidoBleFramesTest, InitializationFragment) {
FidoBleFrameInitializationFragment::Parse(buffer, &parsed_fragment)); FidoBleFrameInitializationFragment::Parse(buffer, &parsed_fragment));
EXPECT_EQ(kDataLength, parsed_fragment.data_length()); EXPECT_EQ(kDataLength, parsed_fragment.data_length());
EXPECT_EQ(base::make_span(data), parsed_fragment.fragment()); EXPECT_TRUE(std::equal(data.begin(), data.end(),
parsed_fragment.fragment().begin(),
parsed_fragment.fragment().end()));
EXPECT_EQ(FidoBleDeviceCommand::kMsg, parsed_fragment.command()); EXPECT_EQ(FidoBleDeviceCommand::kMsg, parsed_fragment.command());
} }
...@@ -58,7 +61,9 @@ TEST(FidoBleFramesTest, ContinuationFragment) { ...@@ -58,7 +61,9 @@ TEST(FidoBleFramesTest, ContinuationFragment) {
ASSERT_TRUE( ASSERT_TRUE(
FidoBleFrameContinuationFragment::Parse(buffer, &parsed_fragment)); FidoBleFrameContinuationFragment::Parse(buffer, &parsed_fragment));
EXPECT_EQ(base::make_span(data), parsed_fragment.fragment()); EXPECT_TRUE(std::equal(data.begin(), data.end(),
parsed_fragment.fragment().begin(),
parsed_fragment.fragment().end()));
EXPECT_EQ(kSequence, parsed_fragment.sequence()); EXPECT_EQ(kSequence, parsed_fragment.sequence());
} }
......
...@@ -116,8 +116,9 @@ MATCHER_P2(IsAdvertisementContent, ...@@ -116,8 +116,9 @@ MATCHER_P2(IsAdvertisementContent,
manufacturer_data_payload[1] == 0x15 && // Manufacturer Data Type manufacturer_data_payload[1] == 0x15 && // Manufacturer Data Type
manufacturer_data_payload[2] == 0x20 && // Cable Flags manufacturer_data_payload[2] == 0x20 && // Cable Flags
manufacturer_data_payload[3] == kTestCableVersionNumber && manufacturer_data_payload[3] == kTestCableVersionNumber &&
base::make_span(manufacturer_data_payload).subspan(4) == std::equal(manufacturer_data_payload.begin() + 4,
expected_client_eid; manufacturer_data_payload.end(),
expected_client_eid.begin(), expected_client_eid.end());
#elif defined(OS_LINUX) || defined(OS_CHROMEOS) #elif defined(OS_LINUX) || defined(OS_CHROMEOS)
const auto service_data = arg->service_data(); const auto service_data = arg->service_data();
...@@ -131,7 +132,8 @@ MATCHER_P2(IsAdvertisementContent, ...@@ -131,7 +132,8 @@ MATCHER_P2(IsAdvertisementContent,
return (service_data_value[0] >> 5 & 1) && return (service_data_value[0] >> 5 & 1) &&
service_data_value[1] == kTestCableVersionNumber && service_data_value[1] == kTestCableVersionNumber &&
service_data_value.size() == 18u && service_data_value.size() == 18u &&
base::make_span(service_data_value).subspan(2) == expected_client_eid; std::equal(service_data_value.begin() + 2, service_data_value.end(),
expected_client_eid.begin(), expected_client_eid.end());
#endif #endif
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <iterator>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -22,14 +23,16 @@ ...@@ -22,14 +23,16 @@
namespace device { namespace device {
namespace fido_parsing_utils { namespace fido_parsing_utils {
// Comparator object that calls base::make_span on its arguments before // Comparator object that calls std::lexicographical_compare on the begin and
// comparing them with operator<. Useful when comparing sequence containers that // end iterators of the passed in ranges. Useful when comparing sequence
// are of different types, but have similar semantics. // containers that are of different types, but have similar semantics.
struct SpanLess { struct RangeLess {
template <typename T, typename U> template <typename T, typename U>
constexpr bool operator()(T&& lhs, U&& rhs) const { constexpr bool operator()(T&& lhs, U&& rhs) const {
return base::make_span(std::forward<T>(lhs)) < using std::begin;
base::make_span(std::forward<U>(rhs)); using std::end;
return std::lexicographical_compare(begin(lhs), end(lhs), begin(rhs),
end(rhs));
} }
using is_transparent = void; using is_transparent = void;
......
...@@ -20,64 +20,64 @@ constexpr uint8_t kThree[] = {0x03}; ...@@ -20,64 +20,64 @@ constexpr uint8_t kThree[] = {0x03};
constexpr uint8_t kOneTwoThree[] = {0x01, 0x02, 0x03}; constexpr uint8_t kOneTwoThree[] = {0x01, 0x02, 0x03};
} // namespace } // namespace
TEST(U2fParsingUtils, SpanLess) { TEST(U2fParsingUtils, RangeLess) {
const std::array<int, 4> kOneTwoThreeFour = {1, 2, 3, 4}; const std::array<int, 4> kOneTwoThreeFour = {1, 2, 3, 4};
EXPECT_FALSE(SpanLess()(kOne, kOne)); EXPECT_FALSE(RangeLess()(kOne, kOne));
EXPECT_TRUE(SpanLess()(kOne, kOneTwo)); EXPECT_TRUE(RangeLess()(kOne, kOneTwo));
EXPECT_TRUE(SpanLess()(kOne, kTwo)); EXPECT_TRUE(RangeLess()(kOne, kTwo));
EXPECT_TRUE(SpanLess()(kOne, kTwoThree)); EXPECT_TRUE(RangeLess()(kOne, kTwoThree));
EXPECT_TRUE(SpanLess()(kOne, kThree)); EXPECT_TRUE(RangeLess()(kOne, kThree));
EXPECT_TRUE(SpanLess()(kOne, kOneTwoThree)); EXPECT_TRUE(RangeLess()(kOne, kOneTwoThree));
EXPECT_TRUE(SpanLess()(kOne, kOneTwoThreeFour)); EXPECT_TRUE(RangeLess()(kOne, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kOneTwo, kOne)); EXPECT_FALSE(RangeLess()(kOneTwo, kOne));
EXPECT_FALSE(SpanLess()(kOneTwo, kOneTwo)); EXPECT_FALSE(RangeLess()(kOneTwo, kOneTwo));
EXPECT_TRUE(SpanLess()(kOneTwo, kTwo)); EXPECT_TRUE(RangeLess()(kOneTwo, kTwo));
EXPECT_TRUE(SpanLess()(kOneTwo, kTwoThree)); EXPECT_TRUE(RangeLess()(kOneTwo, kTwoThree));
EXPECT_TRUE(SpanLess()(kOneTwo, kThree)); EXPECT_TRUE(RangeLess()(kOneTwo, kThree));
EXPECT_TRUE(SpanLess()(kOneTwo, kOneTwoThree)); EXPECT_TRUE(RangeLess()(kOneTwo, kOneTwoThree));
EXPECT_TRUE(SpanLess()(kOneTwo, kOneTwoThreeFour)); EXPECT_TRUE(RangeLess()(kOneTwo, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kTwo, kOne)); EXPECT_FALSE(RangeLess()(kTwo, kOne));
EXPECT_FALSE(SpanLess()(kTwo, kOneTwo)); EXPECT_FALSE(RangeLess()(kTwo, kOneTwo));
EXPECT_FALSE(SpanLess()(kTwo, kTwo)); EXPECT_FALSE(RangeLess()(kTwo, kTwo));
EXPECT_TRUE(SpanLess()(kTwo, kTwoThree)); EXPECT_TRUE(RangeLess()(kTwo, kTwoThree));
EXPECT_TRUE(SpanLess()(kTwo, kThree)); EXPECT_TRUE(RangeLess()(kTwo, kThree));
EXPECT_FALSE(SpanLess()(kTwo, kOneTwoThree)); EXPECT_FALSE(RangeLess()(kTwo, kOneTwoThree));
EXPECT_FALSE(SpanLess()(kTwo, kOneTwoThreeFour)); EXPECT_FALSE(RangeLess()(kTwo, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kTwoThree, kOne)); EXPECT_FALSE(RangeLess()(kTwoThree, kOne));
EXPECT_FALSE(SpanLess()(kTwoThree, kOneTwo)); EXPECT_FALSE(RangeLess()(kTwoThree, kOneTwo));
EXPECT_FALSE(SpanLess()(kTwoThree, kTwo)); EXPECT_FALSE(RangeLess()(kTwoThree, kTwo));
EXPECT_FALSE(SpanLess()(kTwoThree, kTwoThree)); EXPECT_FALSE(RangeLess()(kTwoThree, kTwoThree));
EXPECT_TRUE(SpanLess()(kTwoThree, kThree)); EXPECT_TRUE(RangeLess()(kTwoThree, kThree));
EXPECT_FALSE(SpanLess()(kTwoThree, kOneTwoThree)); EXPECT_FALSE(RangeLess()(kTwoThree, kOneTwoThree));
EXPECT_FALSE(SpanLess()(kTwoThree, kOneTwoThreeFour)); EXPECT_FALSE(RangeLess()(kTwoThree, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kThree, kOne)); EXPECT_FALSE(RangeLess()(kThree, kOne));
EXPECT_FALSE(SpanLess()(kThree, kOneTwo)); EXPECT_FALSE(RangeLess()(kThree, kOneTwo));
EXPECT_FALSE(SpanLess()(kThree, kTwo)); EXPECT_FALSE(RangeLess()(kThree, kTwo));
EXPECT_FALSE(SpanLess()(kThree, kTwoThree)); EXPECT_FALSE(RangeLess()(kThree, kTwoThree));
EXPECT_FALSE(SpanLess()(kThree, kThree)); EXPECT_FALSE(RangeLess()(kThree, kThree));
EXPECT_FALSE(SpanLess()(kThree, kOneTwoThree)); EXPECT_FALSE(RangeLess()(kThree, kOneTwoThree));
EXPECT_FALSE(SpanLess()(kThree, kOneTwoThreeFour)); EXPECT_FALSE(RangeLess()(kThree, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kOneTwoThree, kOne)); EXPECT_FALSE(RangeLess()(kOneTwoThree, kOne));
EXPECT_FALSE(SpanLess()(kOneTwoThree, kOneTwo)); EXPECT_FALSE(RangeLess()(kOneTwoThree, kOneTwo));
EXPECT_TRUE(SpanLess()(kOneTwoThree, kTwo)); EXPECT_TRUE(RangeLess()(kOneTwoThree, kTwo));
EXPECT_TRUE(SpanLess()(kOneTwoThree, kTwoThree)); EXPECT_TRUE(RangeLess()(kOneTwoThree, kTwoThree));
EXPECT_TRUE(SpanLess()(kOneTwoThree, kThree)); EXPECT_TRUE(RangeLess()(kOneTwoThree, kThree));
EXPECT_FALSE(SpanLess()(kOneTwoThree, kOneTwoThree)); EXPECT_FALSE(RangeLess()(kOneTwoThree, kOneTwoThree));
EXPECT_TRUE(SpanLess()(kOneTwoThree, kOneTwoThreeFour)); EXPECT_TRUE(RangeLess()(kOneTwoThree, kOneTwoThreeFour));
EXPECT_FALSE(SpanLess()(kOneTwoThreeFour, kOne)); EXPECT_FALSE(RangeLess()(kOneTwoThreeFour, kOne));
EXPECT_FALSE(SpanLess()(kOneTwoThreeFour, kOneTwo)); EXPECT_FALSE(RangeLess()(kOneTwoThreeFour, kOneTwo));
EXPECT_TRUE(SpanLess()(kOneTwoThreeFour, kTwo)); EXPECT_TRUE(RangeLess()(kOneTwoThreeFour, kTwo));
EXPECT_TRUE(SpanLess()(kOneTwoThreeFour, kTwoThree)); EXPECT_TRUE(RangeLess()(kOneTwoThreeFour, kTwoThree));
EXPECT_TRUE(SpanLess()(kOneTwoThreeFour, kThree)); EXPECT_TRUE(RangeLess()(kOneTwoThreeFour, kThree));
EXPECT_FALSE(SpanLess()(kOneTwoThreeFour, kOneTwoThree)); EXPECT_FALSE(RangeLess()(kOneTwoThreeFour, kOneTwoThree));
EXPECT_FALSE(SpanLess()(kOneTwoThreeFour, kOneTwoThreeFour)); EXPECT_FALSE(RangeLess()(kOneTwoThreeFour, kOneTwoThreeFour));
} }
TEST(U2fParsingUtils, Materialize) { TEST(U2fParsingUtils, Materialize) {
......
...@@ -167,7 +167,8 @@ void FidoHidDevice::OnAllocateChannel(std::vector<uint8_t> nonce, ...@@ -167,7 +167,8 @@ void FidoHidDevice::OnAllocateChannel(std::vector<uint8_t> nonce,
auto received_nonce = base::make_span(payload).first(8); auto received_nonce = base::make_span(payload).first(8);
// Received a broadcast message for a different client. Disregard and continue // Received a broadcast message for a different client. Disregard and continue
// reading. // reading.
if (base::make_span(nonce) != received_nonce) { if (!std::equal(nonce.begin(), nonce.end(), received_nonce.begin(),
received_nonce.end())) {
auto repeating_callback = auto repeating_callback =
base::AdaptCallbackForRepeating(std::move(callback)); base::AdaptCallbackForRepeating(std::move(callback));
ArmTimeout(repeating_callback); ArmTimeout(repeating_callback);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "device/fido/virtual_fido_device.h" #include "device/fido/virtual_fido_device.h"
#include <algorithm>
#include <tuple> #include <tuple>
#include <utility> #include <utility>
...@@ -156,9 +157,11 @@ VirtualFidoDevice::RegistrationData* VirtualFidoDevice::FindRegistrationData( ...@@ -156,9 +157,11 @@ VirtualFidoDevice::RegistrationData* VirtualFidoDevice::FindRegistrationData(
if (it == mutable_state()->registrations.end()) if (it == mutable_state()->registrations.end())
return nullptr; return nullptr;
if (application_parameter != if (!std::equal(application_parameter.begin(), application_parameter.end(),
base::make_span(it->second.application_parameter)) it->second.application_parameter.begin(),
it->second.application_parameter.end())) {
return nullptr; return nullptr;
}
return &(it->second); return &(it->second);
} }
......
...@@ -70,7 +70,7 @@ class COMPONENT_EXPORT(DEVICE_FIDO) VirtualFidoDevice : public FidoDevice { ...@@ -70,7 +70,7 @@ class COMPONENT_EXPORT(DEVICE_FIDO) VirtualFidoDevice : public FidoDevice {
// Registered keys. Keyed on key handle (a.k.a. "credential ID"). // Registered keys. Keyed on key handle (a.k.a. "credential ID").
std::map<std::vector<uint8_t>, std::map<std::vector<uint8_t>,
RegistrationData, RegistrationData,
fido_parsing_utils::SpanLess> fido_parsing_utils::RangeLess>
registrations; registrations;
// If set, this callback is called whenever a "press" is required. It allows // If set, this callback is called whenever a "press" is required. It allows
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "media/cdm/cbcs_decryptor.h" #include "media/cdm/cbcs_decryptor.h"
#include <algorithm>
#include <array> #include <array>
#include <memory> #include <memory>
...@@ -177,10 +178,11 @@ TEST_F(CbcsDecryptorTest, AdditionalData) { ...@@ -177,10 +178,11 @@ TEST_F(CbcsDecryptorTest, AdditionalData) {
EXPECT_EQ(encrypted_buffer->is_key_frame(), decrypted_buffer->is_key_frame()); EXPECT_EQ(encrypted_buffer->is_key_frame(), decrypted_buffer->is_key_frame());
EXPECT_EQ(encrypted_buffer->side_data_size(), EXPECT_EQ(encrypted_buffer->side_data_size(),
decrypted_buffer->side_data_size()); decrypted_buffer->side_data_size());
EXPECT_EQ(base::make_span(encrypted_buffer->side_data(), EXPECT_TRUE(std::equal(
encrypted_buffer->side_data_size()), encrypted_buffer->side_data(),
base::make_span(decrypted_buffer->side_data(), encrypted_buffer->side_data() + encrypted_buffer->side_data_size(),
decrypted_buffer->side_data_size())); decrypted_buffer->side_data(),
decrypted_buffer->side_data() + encrypted_buffer->side_data_size()));
} }
TEST_F(CbcsDecryptorTest, DifferentPattern) { TEST_F(CbcsDecryptorTest, DifferentPattern) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <stdint.h> #include <stdint.h>
#include <algorithm>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -160,10 +161,11 @@ TEST_F(CencDecryptorTest, ExtraData) { ...@@ -160,10 +161,11 @@ TEST_F(CencDecryptorTest, ExtraData) {
EXPECT_EQ(encrypted_buffer->is_key_frame(), decrypted_buffer->is_key_frame()); EXPECT_EQ(encrypted_buffer->is_key_frame(), decrypted_buffer->is_key_frame());
EXPECT_EQ(encrypted_buffer->side_data_size(), EXPECT_EQ(encrypted_buffer->side_data_size(),
decrypted_buffer->side_data_size()); decrypted_buffer->side_data_size());
EXPECT_EQ(base::make_span(encrypted_buffer->side_data(), EXPECT_TRUE(std::equal(
encrypted_buffer->side_data_size()), encrypted_buffer->side_data(),
base::make_span(decrypted_buffer->side_data(), encrypted_buffer->side_data() + encrypted_buffer->side_data_size(),
decrypted_buffer->side_data_size())); decrypted_buffer->side_data(),
decrypted_buffer->side_data() + encrypted_buffer->side_data_size()));
} }
TEST_F(CencDecryptorTest, NoSubsamples) { TEST_F(CencDecryptorTest, NoSubsamples) {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <algorithm>
#include "mojo/public/cpp/base/read_only_buffer_mojom_traits.h" #include "mojo/public/cpp/base/read_only_buffer_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/mojom/base/read_only_buffer.mojom.h" #include "mojo/public/mojom/base/read_only_buffer.mojom.h"
...@@ -16,7 +18,7 @@ TEST(ReadOnlyBufferTest, ReadOnlyBufferEmptySpan) { ...@@ -16,7 +18,7 @@ TEST(ReadOnlyBufferTest, ReadOnlyBufferEmptySpan) {
ASSERT_TRUE( ASSERT_TRUE(
mojo::test::SerializeAndDeserialize<mojom::ReadOnlyBuffer>(&in, &out)); mojo::test::SerializeAndDeserialize<mojom::ReadOnlyBuffer>(&in, &out));
EXPECT_EQ(in, out); EXPECT_TRUE(std::equal(in.begin(), in.end(), out.begin(), out.end()));
} }
TEST(ReadOnlyBufferTest, ReadOnlyBufferNonEmptySpan) { TEST(ReadOnlyBufferTest, ReadOnlyBufferNonEmptySpan) {
...@@ -30,7 +32,7 @@ TEST(ReadOnlyBufferTest, ReadOnlyBufferNonEmptySpan) { ...@@ -30,7 +32,7 @@ TEST(ReadOnlyBufferTest, ReadOnlyBufferNonEmptySpan) {
std::vector<uint8_t> data = mojom::ReadOnlyBuffer::Serialize(&in); std::vector<uint8_t> data = mojom::ReadOnlyBuffer::Serialize(&in);
EXPECT_TRUE(mojom::ReadOnlyBuffer::Deserialize(std::move(data), &out)); EXPECT_TRUE(mojom::ReadOnlyBuffer::Deserialize(std::move(data), &out));
EXPECT_EQ(in, out); EXPECT_TRUE(std::equal(in.begin(), in.end(), out.begin(), out.end()));
} }
} // namespace read_only_buffer_unittest } // namespace read_only_buffer_unittest
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "net/ntlm/ntlm.h" #include "net/ntlm/ntlm.h"
#include <algorithm>
#include <iterator>
#include <string> #include <string>
#include "base/md5.h" #include "base/md5.h"
...@@ -62,7 +64,8 @@ TEST(NtlmTest, MapHashToDesKeysAllOnes) { ...@@ -62,7 +64,8 @@ TEST(NtlmTest, MapHashToDesKeysAllOnes) {
// is undefined, so clear it to do memcmp. // is undefined, so clear it to do memcmp.
ClearLsb(result); ClearLsb(result);
EXPECT_EQ(base::make_span(expected), base::make_span(result)); EXPECT_TRUE(std::equal(std::begin(expected), std::end(expected),
std::begin(result), std::end(result)));
} }
TEST(NtlmTest, MapHashToDesKeysAllZeros) { TEST(NtlmTest, MapHashToDesKeysAllZeros) {
...@@ -76,7 +79,8 @@ TEST(NtlmTest, MapHashToDesKeysAllZeros) { ...@@ -76,7 +79,8 @@ TEST(NtlmTest, MapHashToDesKeysAllZeros) {
// is undefined, so clear it to do memcmp. // is undefined, so clear it to do memcmp.
ClearLsb(result); ClearLsb(result);
EXPECT_EQ(base::make_span(expected), base::make_span(result)); EXPECT_TRUE(std::equal(std::begin(expected), std::end(expected),
std::begin(result), std::end(result)));
} }
TEST(NtlmTest, MapHashToDesKeysAlternatingBits) { TEST(NtlmTest, MapHashToDesKeysAlternatingBits) {
...@@ -93,7 +97,8 @@ TEST(NtlmTest, MapHashToDesKeysAlternatingBits) { ...@@ -93,7 +97,8 @@ TEST(NtlmTest, MapHashToDesKeysAlternatingBits) {
// is undefined, so clear it to do memcmp. // is undefined, so clear it to do memcmp.
ClearLsb(result); ClearLsb(result);
EXPECT_EQ(base::make_span(expected), base::make_span(result)); EXPECT_TRUE(std::equal(std::begin(expected), std::end(expected),
std::begin(result), std::end(result)));
} }
TEST(NtlmTest, GenerateNtlmHashV1PasswordSpecTests) { TEST(NtlmTest, GenerateNtlmHashV1PasswordSpecTests) {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "storage/browser/blob/blob_builder_from_stream.h" #include "storage/browser/blob/blob_builder_from_stream.h"
#include <algorithm>
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -130,8 +132,10 @@ class BlobBuilderFromStreamTestWithDelayedLimits ...@@ -130,8 +132,10 @@ class BlobBuilderFromStreamTestWithDelayedLimits
EXPECT_LE(item->length(), kTestBlobStorageMaxBlobMemorySize); EXPECT_LE(item->length(), kTestBlobStorageMaxBlobMemorySize);
ASSERT_LE(next_memory_offset + item->length(), in_memory_data.size()); ASSERT_LE(next_memory_offset + item->length(), in_memory_data.size());
EXPECT_EQ(in_memory_data.subspan(next_memory_offset, item->length()), EXPECT_TRUE(std::equal(
item->bytes()); in_memory_data.begin() + next_memory_offset,
in_memory_data.begin() + next_memory_offset + item->length(),
item->bytes().begin(), item->bytes().end()));
next_memory_offset += item->length(); next_memory_offset += item->length();
} else if (item->type() == BlobDataItem::Type::kFile) { } else if (item->type() == BlobDataItem::Type::kFile) {
...@@ -144,8 +148,10 @@ class BlobBuilderFromStreamTestWithDelayedLimits ...@@ -144,8 +148,10 @@ class BlobBuilderFromStreamTestWithDelayedLimits
std::string file_contents; std::string file_contents;
EXPECT_TRUE(base::ReadFileToString(item->path(), &file_contents)); EXPECT_TRUE(base::ReadFileToString(item->path(), &file_contents));
EXPECT_EQ(item->length(), file_contents.size()); EXPECT_EQ(item->length(), file_contents.size());
EXPECT_EQ(on_disk_data.subspan(next_file_offset, item->length()), EXPECT_TRUE(
base::make_span(file_contents)); std::equal(on_disk_data.begin() + next_file_offset,
on_disk_data.begin() + next_file_offset + item->length(),
file_contents.begin(), file_contents.end()));
next_file_offset += item->length(); next_file_offset += item->length();
if (next_file_offset < on_disk_data.size()) { if (next_file_offset < on_disk_data.size()) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "storage/browser/blob/blob_data_item.h" #include "storage/browser/blob/blob_data_item.h"
#include <algorithm>
#include <memory> #include <memory>
#include <utility> #include <utility>
...@@ -211,7 +212,8 @@ bool operator==(const BlobDataItem& a, const BlobDataItem& b) { ...@@ -211,7 +212,8 @@ bool operator==(const BlobDataItem& a, const BlobDataItem& b) {
return false; return false;
switch (a.type()) { switch (a.type()) {
case BlobDataItem::Type::kBytes: case BlobDataItem::Type::kBytes:
return a.bytes() == b.bytes(); return std::equal(a.bytes().begin(), a.bytes().end(), b.bytes().begin(),
b.bytes().end());
case BlobDataItem::Type::kBytesDescription: case BlobDataItem::Type::kBytesDescription:
return true; return true;
case BlobDataItem::Type::kFile: case BlobDataItem::Type::kFile:
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SHARED_BUFFER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_SHARED_BUFFER_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SHARED_BUFFER_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SHARED_BUFFER_H_
#include <algorithm>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -61,7 +62,9 @@ class PLATFORM_EXPORT SharedBuffer : public RefCounted<SharedBuffer> { ...@@ -61,7 +62,9 @@ class PLATFORM_EXPORT SharedBuffer : public RefCounted<SharedBuffer> {
return temp; return temp;
} }
bool operator==(const Iterator& that) const { bool operator==(const Iterator& that) const {
return value_ == that.value_ && buffer_ == that.buffer_; return std::equal(value_.begin(), value_.end(), that.value_.begin(),
that.value_.end()) &&
buffer_ == that.buffer_;
} }
bool operator!=(const Iterator& that) const { return !(*this == that); } bool operator!=(const Iterator& that) const { return !(*this == that); }
const base::span<const char>& operator*() const { const base::span<const char>& operator*() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment