Added tests for span iterators, fixed implementation.

This commit is contained in:
Neil MacIntosh
2016-07-18 11:38:01 -07:00
parent 8855c59579
commit 30a038ca6a
3 changed files with 141 additions and 13 deletions
+3 -3
View File
@@ -19,10 +19,10 @@
#ifndef GSL_GSL_H
#define GSL_GSL_H
#include "gsl_assert.h" // Ensures/Expects
#include "gsl_util.h" // finally()/narrow()/narrow_cast()...
#include "gsl_assert.h" // Ensures/Expects
#include "gsl_util.h" // finally()/narrow()/narrow_cast()...
#include "span.h" // span
#include "multi_span.h" // multi_span, strided_span...
#include "multi_span.h" // multi_span, strided_span...
#include "string_span.h" // zstring, string_span, zstring_builder...
#include <memory>
+10 -6
View File
@@ -192,7 +192,7 @@ public:
constexpr const_span_iterator& operator--() noexcept
{
Expects(span_ && index > 0 && index_ <= span_->length());
Expects(span_ && index_ > 0 && index_ <= span_->length());
--index_;
return *this;
}
@@ -366,7 +366,7 @@ public:
using reference = element_type&;
using iterator = details::span_iterator<span<ElementType, Extent>>;
using const_iterator = details::span_iterator<span>;
using const_iterator = details::const_span_iterator<span>;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
@@ -512,13 +512,17 @@ public:
// [span.iter], span iterator support
iterator begin() const noexcept { return {this, 0}; }
iterator end() const noexcept { return {this, length()}; }
const_iterator cbegin() const noexcept { return {this, 0}; }
const_iterator cend() const noexcept { return {this, length()}; }
reverse_iterator rbegin() const noexcept { return {this, length()}; }
reverse_iterator rend() const noexcept { return {this, 0}; }
reverse_iterator rbegin() const noexcept { return reverse_iterator{{this, length()}}; }
reverse_iterator rend() const noexcept { return reverse_iterator{{this, 0}}; }
const_reverse_iterator crbegin() const noexcept { return reverse_iterator{{this, length()}}; }
const_reverse_iterator crend() const noexcept { return reverse_iterator{{this, 0}}; }
private:
constexpr static const bool is_span_type = true;
template <index_type Extent>
class extent_type;