Add last() to SkZip
Change-Id: Ia1a1e58df38bd4865d4d3d389a6a75835b5e87df Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254809 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
170de0193f
commit
c9dcd09f24
@ -82,8 +82,14 @@ public:
|
||||
constexpr std::tuple<Ts*...> data() const { return fPointers; }
|
||||
constexpr SkZip first(size_t n) const {
|
||||
SkASSERT(n <= this->size());
|
||||
if (n == 0) { return SkZip(); }
|
||||
return SkZip{n, fPointers};
|
||||
}
|
||||
constexpr SkZip last(size_t n) const {
|
||||
SkASSERT(n <= this->size());
|
||||
if (n == 0) { return SkZip(); }
|
||||
return SkZip{n, this->pointersAt(fSize - n)};
|
||||
}
|
||||
|
||||
private:
|
||||
constexpr SkZip(size_t n, const std::tuple<Ts*...>& pointers)
|
||||
@ -101,6 +107,17 @@ private:
|
||||
return ReturnTuple((std::get<Is>(fPointers))[i]...);
|
||||
}
|
||||
|
||||
std::tuple<Ts*...> pointersAt(size_t i) const {
|
||||
SkASSERT(this->size() > 0);
|
||||
SkASSERT(i < this->size());
|
||||
return pointersAtDetail(i, skstd::make_index_sequence<sizeof...(Ts)>{});
|
||||
}
|
||||
|
||||
template<std::size_t... Is>
|
||||
constexpr std::tuple<Ts*...> pointersAtDetail(size_t i, skstd::index_sequence<Is...>) const {
|
||||
return std::tuple<Ts*...>{&(std::get<Is>(fPointers))[i]...};
|
||||
}
|
||||
|
||||
std::tuple<Ts*...> fPointers;
|
||||
size_t fSize;
|
||||
};
|
||||
|
@ -333,6 +333,22 @@ DEF_TEST(SkZip, reporter) {
|
||||
REPORTER_ASSERT(reporter, i = 2);
|
||||
}
|
||||
|
||||
{
|
||||
// Check last(n)
|
||||
int i = 0;
|
||||
for (auto t : z.last(2)) {
|
||||
uint16_t a; float b; int c; int d; int s;
|
||||
std::tie(a, b, c, d, s) = t;
|
||||
REPORTER_ASSERT(reporter, a == A[i + 2]);
|
||||
REPORTER_ASSERT(reporter, b == B[i + 2]);
|
||||
REPORTER_ASSERT(reporter, c == C[i + 2]);
|
||||
REPORTER_ASSERT(reporter, d == D[i + 2]);
|
||||
REPORTER_ASSERT(reporter, s == S[i + 2]);
|
||||
|
||||
i++;
|
||||
}
|
||||
REPORTER_ASSERT(reporter, i = 2);
|
||||
}
|
||||
|
||||
{
|
||||
// Check copy.
|
||||
|
Loading…
Reference in New Issue
Block a user