mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge pull request #216 from neilmacintosh/dev/neilmac/span-rework
Corrected some variable naming.
This commit is contained in:
commit
e10d2e3028
@ -840,27 +840,27 @@ public:
|
|||||||
using index_size_type = typename IndexType::value_type;
|
using index_size_type = typename IndexType::value_type;
|
||||||
template <typename Bounds>
|
template <typename Bounds>
|
||||||
explicit bounds_iterator(const Bounds& bnd, value_type curr) noexcept
|
explicit bounds_iterator(const Bounds& bnd, value_type curr) noexcept
|
||||||
: boundary(bnd.index_bounds()),
|
: boundary_(bnd.index_bounds()),
|
||||||
curr(std::move(curr))
|
curr_(std::move(curr))
|
||||||
{
|
{
|
||||||
static_assert(is_bounds<Bounds>::value, "Bounds type must be provided");
|
static_assert(is_bounds<Bounds>::value, "Bounds type must be provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr reference operator*() const noexcept { return curr; }
|
constexpr reference operator*() const noexcept { return curr_; }
|
||||||
|
|
||||||
constexpr pointer operator->() const noexcept { return &curr; }
|
constexpr pointer operator->() const noexcept { return &curr_; }
|
||||||
|
|
||||||
constexpr bounds_iterator& operator++() noexcept
|
constexpr bounds_iterator& operator++() noexcept
|
||||||
{
|
{
|
||||||
for (size_t i = rank; i-- > 0;) {
|
for (size_t i = rank; i-- > 0;) {
|
||||||
if (curr[i] < boundary[i] - 1) {
|
if (curr_[i] < boundary_[i] - 1) {
|
||||||
curr[i]++;
|
curr_[i]++;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
curr[i] = 0;
|
curr_[i] = 0;
|
||||||
}
|
}
|
||||||
// If we're here we've wrapped over - set to past-the-end.
|
// If we're here we've wrapped over - set to past-the-end.
|
||||||
curr = boundary;
|
curr_ = boundary_;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -873,19 +873,19 @@ public:
|
|||||||
|
|
||||||
constexpr bounds_iterator& operator--() noexcept
|
constexpr bounds_iterator& operator--() noexcept
|
||||||
{
|
{
|
||||||
if (!less(curr, boundary)) {
|
if (!less(curr_, boundary_)) {
|
||||||
// if at the past-the-end, set to last element
|
// if at the past-the-end, set to last element
|
||||||
for (size_t i = 0; i < rank; ++i) {
|
for (size_t i = 0; i < rank; ++i) {
|
||||||
curr[i] = boundary[i] - 1;
|
curr_[i] = boundary_[i] - 1;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
for (size_t i = rank; i-- > 0;) {
|
for (size_t i = rank; i-- > 0;) {
|
||||||
if (curr[i] >= 1) {
|
if (curr_[i] >= 1) {
|
||||||
curr[i]--;
|
curr_[i]--;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
curr[i] = boundary[i] - 1;
|
curr_[i] = boundary_[i] - 1;
|
||||||
}
|
}
|
||||||
// If we're here the preconditions were violated
|
// If we're here the preconditions were violated
|
||||||
// "pre: there exists s such that r == ++s"
|
// "pre: there exists s such that r == ++s"
|
||||||
@ -908,18 +908,18 @@ public:
|
|||||||
|
|
||||||
constexpr bounds_iterator& operator+=(difference_type n) noexcept
|
constexpr bounds_iterator& operator+=(difference_type n) noexcept
|
||||||
{
|
{
|
||||||
auto linear_idx = linearize(curr) + n;
|
auto linear_idx = linearize(curr_) + n;
|
||||||
std::remove_const_t<value_type> stride = 0;
|
std::remove_const_t<value_type> stride = 0;
|
||||||
stride[rank - 1] = 1;
|
stride[rank - 1] = 1;
|
||||||
for (size_t i = rank - 1; i-- > 0;) {
|
for (size_t i = rank - 1; i-- > 0;) {
|
||||||
stride[i] = stride[i + 1] * boundary[i + 1];
|
stride[i] = stride[i + 1] * boundary_[i + 1];
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < rank; ++i) {
|
for (size_t i = 0; i < rank; ++i) {
|
||||||
curr[i] = linear_idx / stride[i];
|
curr_[i] = linear_idx / stride[i];
|
||||||
linear_idx = linear_idx % stride[i];
|
linear_idx = linear_idx % stride[i];
|
||||||
}
|
}
|
||||||
// index is out of bounds of the array
|
// index is out of bounds of the array
|
||||||
Expects(!less(curr, index_type{}) && !less(boundary, curr));
|
Expects(!less(curr_, index_type{}) && !less(boundary_, curr_));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -933,21 +933,21 @@ public:
|
|||||||
|
|
||||||
constexpr difference_type operator-(const bounds_iterator& rhs) const noexcept
|
constexpr difference_type operator-(const bounds_iterator& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return linearize(curr) - linearize(rhs.curr);
|
return linearize(curr_) - linearize(rhs.curr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr value_type operator[](difference_type n) const noexcept { return *(*this + n); }
|
constexpr value_type operator[](difference_type n) const noexcept { return *(*this + n); }
|
||||||
|
|
||||||
constexpr bool operator==(const bounds_iterator& rhs) const noexcept
|
constexpr bool operator==(const bounds_iterator& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return curr == rhs.curr;
|
return curr_ == rhs.curr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator!=(const bounds_iterator& rhs) const noexcept { return !(*this == rhs); }
|
constexpr bool operator!=(const bounds_iterator& rhs) const noexcept { return !(*this == rhs); }
|
||||||
|
|
||||||
constexpr bool operator<(const bounds_iterator& rhs) const noexcept
|
constexpr bool operator<(const bounds_iterator& rhs) const noexcept
|
||||||
{
|
{
|
||||||
return less(curr, rhs.curr);
|
return less(curr_, rhs.curr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator<=(const bounds_iterator& rhs) const noexcept { return !(rhs < *this); }
|
constexpr bool operator<=(const bounds_iterator& rhs) const noexcept { return !(rhs < *this); }
|
||||||
@ -958,8 +958,8 @@ public:
|
|||||||
|
|
||||||
void swap(bounds_iterator& rhs) noexcept
|
void swap(bounds_iterator& rhs) noexcept
|
||||||
{
|
{
|
||||||
std::swap(boundary, rhs.boundary);
|
std::swap(boundary_, rhs.boundary_);
|
||||||
std::swap(curr, rhs.curr);
|
std::swap(curr_, rhs.curr_);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -977,25 +977,25 @@ private:
|
|||||||
// Check if past-the-end
|
// Check if past-the-end
|
||||||
index_size_type multiplier = 1;
|
index_size_type multiplier = 1;
|
||||||
index_size_type res = 0;
|
index_size_type res = 0;
|
||||||
if (!less(idx, boundary)) {
|
if (!less(idx, boundary_)) {
|
||||||
res = 1;
|
res = 1;
|
||||||
for (size_t i = rank; i-- > 0;) {
|
for (size_t i = rank; i-- > 0;) {
|
||||||
res += (idx[i] - 1) * multiplier;
|
res += (idx[i] - 1) * multiplier;
|
||||||
multiplier *= boundary[i];
|
multiplier *= boundary_[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (size_t i = rank; i-- > 0;) {
|
for (size_t i = rank; i-- > 0;) {
|
||||||
res += idx[i] * multiplier;
|
res += idx[i] * multiplier;
|
||||||
multiplier *= boundary[i];
|
multiplier *= boundary_[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
value_type boundary;
|
value_type boundary_;
|
||||||
std::remove_const_t<value_type> curr;
|
std::remove_const_t<value_type> curr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename IndexType>
|
template <typename IndexType>
|
||||||
|
@ -1606,8 +1606,8 @@ SUITE(span_tests)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
auto f = [&]() {
|
auto f = [&]() {
|
||||||
span<int, 4> av4 = {arr2, 2};
|
span<int, 4> av9 = {arr2, 2};
|
||||||
(void) av4;
|
(void) av9;
|
||||||
};
|
};
|
||||||
CHECK_THROW(f(), fail_fast);
|
CHECK_THROW(f(), fail_fast);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user