addressing feedback

This commit is contained in:
Jordan Maples [MSFT] 2020-02-03 18:13:14 -08:00
parent 81c2a1da15
commit e0dc8095b3

View File

@ -71,7 +71,7 @@ namespace gsl
{ {
// [views.constants], constants // [views.constants], constants
constexpr const std::size_t dynamic_extent = static_cast<std::size_t>(-1); constexpr std::size_t dynamic_extent = static_cast<std::size_t>(-1);
template <class ElementType, std::size_t Extent = dynamic_extent> template <class ElementType, std::size_t Extent = dynamic_extent>
class span; class span;
@ -122,25 +122,30 @@ namespace details
{ {
}; };
template <class type> template <class Type>
class span_iterator class span_iterator
{ {
public: public:
using iterator_category = std::random_access_iterator_tag; using iterator_category = std::random_access_iterator_tag;
using value_type = std::remove_cv_t<type>; using value_type = std::remove_cv_t<Type>;
using difference_type = ptrdiff_t; using difference_type = std::ptrdiff_t;
using pointer = std::add_pointer_t<type>; using pointer = Type*;
using reference = std::add_lvalue_reference_t<type>; using reference = Type&;
#ifdef _MSC_VER #ifdef _MSC_VER
using _Unchecked_type = typename pointer; using _Unchecked_type = pointer;
#endif #endif
constexpr operator span_iterator<const type>() const noexcept constexpr operator span_iterator<const Type>() const noexcept
{ {
return {begin_, end_, current_}; return {begin_, end_, current_};
} }
constexpr reference operator*() const noexcept { return *operator->(); } constexpr reference operator*() const noexcept
{
Expects(begin_ && current_ && end_);
Expects(current_ < end_);
return *current_;
}
constexpr pointer operator->() const noexcept constexpr pointer operator->() const noexcept
{ {
@ -194,7 +199,7 @@ namespace details
} }
friend constexpr span_iterator operator+(const difference_type n, friend constexpr span_iterator operator+(const difference_type n,
span_iterator const& rhs) noexcept const span_iterator& rhs) noexcept
{ {
return rhs + n; return rhs + n;
} }
@ -214,18 +219,12 @@ namespace details
return ret -= n; return ret -= n;
} }
friend constexpr span_iterator operator-(const difference_type n,
span_iterator const& rhs) noexcept
{
return rhs - n;
}
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr difference_type operator-(const span_iterator<type2>& rhs) const noexcept constexpr difference_type operator-(const span_iterator<Type2>& rhs) const noexcept
{ {
Expects(begin_ == rhs.begin_); Expects(begin_ == rhs.begin_ && end_ == rhs.end_);
return current_ - rhs.current_; return current_ - rhs.current_;
} }
@ -235,52 +234,52 @@ namespace details
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator==(const span_iterator<type2>& rhs) const noexcept constexpr bool operator==(const span_iterator<Type2>& rhs) const noexcept
{ {
return begin_ == rhs.begin_ && current_ == rhs.current_; return begin_ == rhs.begin_ && end_ == rhs.end_ && current_ == rhs.current_;
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator!=(const span_iterator<type2>& rhs) const noexcept constexpr bool operator!=(const span_iterator<Type2>& rhs) const noexcept
{ {
return !(*this == rhs); return !(*this == rhs);
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator<(const span_iterator<type2>& rhs) const noexcept constexpr bool operator<(const span_iterator<Type2>& rhs) const noexcept
{ {
Expects(begin_ == rhs.begin_); Expects(begin_ == rhs.begin_ && end_ == rhs.end_);
return current_ < rhs.current_; return current_ < rhs.current_;
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator>(const span_iterator<type2>& rhs) const noexcept constexpr bool operator>(const span_iterator<Type2>& rhs) const noexcept
{ {
return !(*this < rhs); return !(*this < rhs);
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator<=(const span_iterator<type2>& rhs) const noexcept constexpr bool operator<=(const span_iterator<Type2>& rhs) const noexcept
{ {
return *this < rhs || *this == rhs; return !(*this > rhs);
} }
template < template <
class type2, class Type2,
std::enable_if_t<std::is_same<std::remove_cv_t<type2>, value_type>::value, int> = 0> std::enable_if_t<std::is_same<std::remove_cv_t<Type2>, value_type>::value, int> = 0>
constexpr bool operator>=(const span_iterator<type2>& rhs) const noexcept constexpr bool operator>=(const span_iterator<Type2>& rhs) const noexcept
{ {
return *this > rhs || *this == rhs; return *!(this < rhs);
} }
#ifdef _MSC_VER #ifdef _MSC_VER
@ -290,7 +289,8 @@ namespace details
friend constexpr void _Verify_range(span_iterator lhs, span_iterator rhs) noexcept friend constexpr void _Verify_range(span_iterator lhs, span_iterator rhs) noexcept
{ // test that [lhs, rhs) forms a valid range inside an STL algorithm { // test that [lhs, rhs) forms a valid range inside an STL algorithm
Expects(lhs.begin_ == rhs.begin_ // range spans have to match Expects(lhs.begin_ == rhs.begin_ // range spans have to match
&& lhs.end_ <= rhs.end_); // range must not be transposed && lhs.end_ == rhs.end_ &&
lhs.current_ <= rhs.current_); // range must not be transposed
} }
constexpr void _Verify_offset(const difference_type n) const noexcept constexpr void _Verify_offset(const difference_type n) const noexcept
@ -499,8 +499,7 @@ public:
constexpr auto subspan() const noexcept -> constexpr auto subspan() const noexcept ->
typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type
{ {
Expects((size() >= Offset) && Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
(Count == dynamic_extent || (Count <= size() - Offset)));
return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count}; return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
} }
@ -569,7 +568,10 @@ public:
constexpr iterator end() const noexcept { return {data(), data() + size(), data() + size()}; } constexpr iterator end() const noexcept { return {data(), data() + size(), data() + size()}; }
constexpr const_iterator cbegin() const noexcept { return {data(), data() + size(), data()}; } constexpr const_iterator cbegin() const noexcept { return {data(), data() + size(), data()}; }
constexpr const_iterator cend() const noexcept { return {data(), data() + size(), data() + size()}; } constexpr const_iterator cend() const noexcept
{
return {data(), data() + size(), data() + size()};
}
constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; } constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator{end()}; }
constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; } constexpr reverse_iterator rend() const noexcept { return reverse_iterator{begin()}; }