mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
change span from signed to unsigned to align to std
This commit is contained in:
parent
b4dd39615a
commit
8579165d0a
182
include/gsl/span
182
include/gsl/span
@ -26,16 +26,18 @@
|
||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||
#include <iterator> // for reverse_iterator, distance, random_access_...
|
||||
#include <limits>
|
||||
#include <memory> // for std::addressof
|
||||
#include <stdexcept>
|
||||
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
|
||||
#include <utility>
|
||||
#include <memory> // for std::addressof
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#pragma warning(push)
|
||||
|
||||
// turn off some warnings that are noisy about our Expects statements
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
#pragma warning( \
|
||||
disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||
#pragma warning(disable : 4702) // unreachable code
|
||||
|
||||
// Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool.
|
||||
@ -70,9 +72,9 @@ namespace gsl
|
||||
{
|
||||
|
||||
// [views.constants], constants
|
||||
constexpr const std::ptrdiff_t dynamic_extent = -1;
|
||||
constexpr const std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <class ElementType, std::size_t Extent = dynamic_extent>
|
||||
class span;
|
||||
|
||||
// implementation details
|
||||
@ -83,7 +85,7 @@ namespace details
|
||||
{
|
||||
};
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
struct is_span_oracle<gsl::span<ElementType, Extent>> : std::true_type
|
||||
{
|
||||
};
|
||||
@ -108,7 +110,7 @@ namespace details
|
||||
{
|
||||
};
|
||||
|
||||
template <std::ptrdiff_t From, std::ptrdiff_t To>
|
||||
template <std::size_t From, std::size_t To>
|
||||
struct is_allowed_extent_conversion
|
||||
: public std::integral_constant<bool, From == To || From == gsl::dynamic_extent ||
|
||||
To == gsl::dynamic_extent>
|
||||
@ -154,7 +156,7 @@ namespace details
|
||||
GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute
|
||||
constexpr reference operator*() const
|
||||
{
|
||||
Expects(index_ != span_->size());
|
||||
Expects(static_cast<size_t>(index_) != span_->size());
|
||||
return *(span_->data() + index_);
|
||||
}
|
||||
|
||||
@ -166,7 +168,7 @@ namespace details
|
||||
|
||||
constexpr span_iterator& operator++() noexcept
|
||||
{
|
||||
Expects(0 <= index_ && index_ != span_->size());
|
||||
Expects(0 <= index_ && static_cast<size_t>(index_) != span_->size());
|
||||
++index_;
|
||||
return *this;
|
||||
}
|
||||
@ -180,7 +182,7 @@ namespace details
|
||||
|
||||
constexpr span_iterator& operator--() noexcept
|
||||
{
|
||||
Expects(index_ != 0 && index_ <= span_->size());
|
||||
Expects(index_ != 0 && static_cast<size_t>(index_) <= span_->size());
|
||||
--index_;
|
||||
return *this;
|
||||
}
|
||||
@ -198,7 +200,8 @@ namespace details
|
||||
return ret += n;
|
||||
}
|
||||
|
||||
friend constexpr span_iterator operator+(difference_type n, span_iterator const& rhs) noexcept
|
||||
friend constexpr span_iterator operator+(difference_type n,
|
||||
span_iterator const& rhs) noexcept
|
||||
{
|
||||
return rhs + n;
|
||||
}
|
||||
@ -300,11 +303,11 @@ namespace details
|
||||
std::ptrdiff_t index_ = 0;
|
||||
};
|
||||
|
||||
template <std::ptrdiff_t Ext>
|
||||
template <std::size_t Ext>
|
||||
class extent_type
|
||||
{
|
||||
public:
|
||||
using index_type = std::ptrdiff_t;
|
||||
using index_type = std::size_t;
|
||||
|
||||
static_assert(Ext >= 0, "A fixed-size span must be >= 0 in size.");
|
||||
|
||||
@ -327,13 +330,16 @@ namespace details
|
||||
class extent_type<dynamic_extent>
|
||||
{
|
||||
public:
|
||||
using index_type = std::ptrdiff_t;
|
||||
using index_type = std::size_t;
|
||||
|
||||
template <index_type Other>
|
||||
explicit constexpr extent_type(extent_type<Other> ext) : size_(ext.size())
|
||||
{}
|
||||
|
||||
explicit constexpr extent_type(index_type size) : size_(size) { Expects(size >= 0); }
|
||||
explicit constexpr extent_type(index_type size) : size_(size)
|
||||
{
|
||||
Expects(size != dynamic_extent);
|
||||
}
|
||||
|
||||
constexpr index_type size() const noexcept { return size_; }
|
||||
|
||||
@ -341,7 +347,7 @@ namespace details
|
||||
index_type size_;
|
||||
};
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent, std::ptrdiff_t Offset, std::ptrdiff_t Count>
|
||||
template <class ElementType, std::size_t Extent, std::size_t Offset, std::size_t Count>
|
||||
struct calculate_subspan_type
|
||||
{
|
||||
using type = span<ElementType, Count != dynamic_extent
|
||||
@ -351,16 +357,17 @@ namespace details
|
||||
} // namespace details
|
||||
|
||||
// [span], class template span
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
class span
|
||||
{
|
||||
public:
|
||||
// constants and types
|
||||
using element_type = ElementType;
|
||||
using value_type = std::remove_cv_t<ElementType>;
|
||||
using index_type = std::ptrdiff_t;
|
||||
using index_type = std::size_t;
|
||||
using pointer = element_type*;
|
||||
using reference = element_type&;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
using iterator = details::span_iterator<span<ElementType, Extent>, false>;
|
||||
using const_iterator = details::span_iterator<span<ElementType, Extent>, true>;
|
||||
@ -379,7 +386,7 @@ public:
|
||||
template <bool Dependent = false,
|
||||
// "Dependent" is needed to make "std::enable_if_t<Dependent || Extent <= 0>" SFINAE,
|
||||
// since "std::enable_if_t<Extent <= 0>" is ill-formed when Extent is greater than 0.
|
||||
class = std::enable_if_t<(Dependent || Extent <= 0)>>
|
||||
class = std::enable_if_t<(Dependent || Extent == 0 || Extent == dynamic_extent)>>
|
||||
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>())
|
||||
{}
|
||||
|
||||
@ -397,24 +404,20 @@ public:
|
||||
template <std::size_t N, class = std::enable_if_t<(N > 0)>>
|
||||
constexpr span(std::array<std::remove_const_t<element_type>, N>& arr) noexcept
|
||||
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
constexpr span(std::array<std::remove_const_t<element_type>, 0>&) noexcept
|
||||
: storage_(static_cast<pointer>(nullptr), details::extent_type<0>())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
template <std::size_t N, class = std::enable_if_t<(N > 0)>>
|
||||
constexpr span(const std::array<std::remove_const_t<element_type>, N>& arr) noexcept
|
||||
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
constexpr span(const std::array<std::remove_const_t<element_type>, 0>&) noexcept
|
||||
: storage_(static_cast<pointer>(nullptr), details::extent_type<0>())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
|
||||
// on Container to be a contiguous sequence container.
|
||||
@ -433,13 +436,14 @@ public:
|
||||
std::is_convertible<typename Container::pointer, pointer>::value &&
|
||||
std::is_convertible<typename Container::pointer,
|
||||
decltype(std::declval<Container>().data())>::value>>
|
||||
constexpr span(const Container& cont) noexcept : span(cont.data(), narrow<index_type>(cont.size()))
|
||||
constexpr span(const Container& cont) noexcept
|
||||
: span(cont.data(), narrow<index_type>(cont.size()))
|
||||
{}
|
||||
|
||||
constexpr span(const span& other) noexcept = default;
|
||||
|
||||
template <
|
||||
class OtherElementType, std::ptrdiff_t OtherExtent,
|
||||
class OtherElementType, std::size_t OtherExtent,
|
||||
class = std::enable_if_t<
|
||||
details::is_allowed_extent_conversion<OtherExtent, Extent>::value &&
|
||||
details::is_allowed_element_type_conversion<OtherElementType, element_type>::value>>
|
||||
@ -451,27 +455,27 @@ public:
|
||||
constexpr span& operator=(const span& other) noexcept = default;
|
||||
|
||||
// [span.sub], span subviews
|
||||
template <std::ptrdiff_t Count>
|
||||
template <std::size_t Count>
|
||||
constexpr span<element_type, Count> first() const noexcept
|
||||
{
|
||||
Expects(Count >= 0 && Count <= size());
|
||||
Expects(Count <= size());
|
||||
return {data(), Count};
|
||||
}
|
||||
|
||||
template <std::ptrdiff_t Count>
|
||||
template <std::size_t Count>
|
||||
GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute
|
||||
constexpr span<element_type, Count> last() const noexcept
|
||||
{
|
||||
Expects(Count >= 0 && size() - Count >= 0);
|
||||
Expects(size() >= Count);
|
||||
return {data() + (size() - Count), Count};
|
||||
}
|
||||
|
||||
template <std::ptrdiff_t Offset, std::ptrdiff_t Count = dynamic_extent>
|
||||
template <std::size_t Offset, std::size_t Count = dynamic_extent>
|
||||
GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute
|
||||
constexpr auto subspan() const noexcept ->
|
||||
typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type
|
||||
{
|
||||
Expects((Offset >= 0 && size() - Offset >= 0) &&
|
||||
Expects((size() >= Offset) &&
|
||||
(Count == dynamic_extent || (Count >= 0 && Offset + Count <= size())));
|
||||
|
||||
return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
|
||||
@ -479,17 +483,19 @@ public:
|
||||
|
||||
constexpr span<element_type, dynamic_extent> first(index_type count) const noexcept
|
||||
{
|
||||
Expects(count >= 0 && count <= size());
|
||||
Expects(count <= size());
|
||||
return {data(), count};
|
||||
}
|
||||
|
||||
constexpr span<element_type, dynamic_extent> last(index_type count) const noexcept
|
||||
{
|
||||
Expects(count <= size());
|
||||
return make_subspan(size() - count, dynamic_extent, subspan_selector<Extent>{});
|
||||
}
|
||||
|
||||
constexpr span<element_type, dynamic_extent> subspan(index_type offset,
|
||||
index_type count = dynamic_extent) const noexcept
|
||||
index_type count = dynamic_extent) const
|
||||
noexcept
|
||||
{
|
||||
return make_subspan(offset, count, subspan_selector<Extent>{});
|
||||
}
|
||||
@ -512,23 +518,25 @@ public:
|
||||
|
||||
constexpr reference front() const noexcept
|
||||
{
|
||||
Expects(size() > 0);
|
||||
Expects(size() != dynamic_extent && size() > 0);
|
||||
return data()[0];
|
||||
}
|
||||
|
||||
constexpr reference back() const noexcept
|
||||
{
|
||||
Expects(size() > 0);
|
||||
Expects(size() != dynamic_extent && size() > 0);
|
||||
return data()[size() - 1];
|
||||
}
|
||||
|
||||
// at and operator() are deprecated to align to the public member functions of std::span
|
||||
[[deprecated("Use operator[]")]]
|
||||
constexpr reference at(index_type idx) const noexcept{ return this->operator[](idx); }
|
||||
[[deprecated("Use operator[]")]]
|
||||
constexpr reference operator()(index_type idx) const noexcept{ return this->operator[](idx); }
|
||||
|
||||
|
||||
[[deprecated("Use operator[]")]] constexpr reference at(index_type idx) const noexcept
|
||||
{
|
||||
return this->operator[](idx);
|
||||
}
|
||||
[[deprecated("Use operator[]")]] constexpr reference operator()(index_type idx) const noexcept
|
||||
{
|
||||
return this->operator[](idx);
|
||||
}
|
||||
|
||||
constexpr pointer data() const noexcept { return storage_.data(); }
|
||||
|
||||
@ -607,13 +615,13 @@ private:
|
||||
constexpr storage_type(KnownNotNull data, OtherExtentType ext)
|
||||
: ExtentType(ext), data_(data.p)
|
||||
{
|
||||
Expects(ExtentType::size() >= 0);
|
||||
Expects(ExtentType::size() != dynamic_extent);
|
||||
}
|
||||
|
||||
template <class OtherExtentType>
|
||||
constexpr storage_type(pointer data, OtherExtentType ext) : ExtentType(ext), data_(data)
|
||||
{
|
||||
Expects(ExtentType::size() >= 0);
|
||||
Expects(ExtentType::size() != dynamic_extent);
|
||||
Expects(data || ExtentType::size() == 0);
|
||||
}
|
||||
|
||||
@ -629,12 +637,12 @@ private:
|
||||
// in subspans and constructors from arrays
|
||||
constexpr span(KnownNotNull ptr, index_type count) : storage_(ptr, count) {}
|
||||
|
||||
template <std::ptrdiff_t CallerExtent>
|
||||
template <std::size_t CallerExtent>
|
||||
class subspan_selector
|
||||
{
|
||||
};
|
||||
|
||||
template <std::ptrdiff_t CallerExtent>
|
||||
template <std::size_t CallerExtent>
|
||||
span<element_type, dynamic_extent> make_subspan(index_type offset, index_type count,
|
||||
subspan_selector<CallerExtent>) const
|
||||
{
|
||||
@ -646,52 +654,52 @@ private:
|
||||
span<element_type, dynamic_extent> make_subspan(index_type offset, index_type count,
|
||||
subspan_selector<dynamic_extent>) const
|
||||
{
|
||||
Expects(offset >= 0 && size() - offset >= 0);
|
||||
Expects(offset >= 0 && size() >= offset && size() != dynamic_extent);
|
||||
|
||||
if (count == dynamic_extent) { return {KnownNotNull{data() + offset}, size() - offset}; }
|
||||
|
||||
Expects(count >= 0 && size() - offset >= count);
|
||||
Expects(size() - offset >= count);
|
||||
return {KnownNotNull{data() + offset}, count};
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr const typename span<ElementType, Extent>::index_type span<ElementType, Extent>::extent;
|
||||
#endif
|
||||
|
||||
// [span.comparison], span comparison operators
|
||||
template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent>
|
||||
template <class ElementType, std::size_t FirstExtent, std::size_t SecondExtent>
|
||||
constexpr bool operator==(span<ElementType, FirstExtent> l, span<ElementType, SecondExtent> r)
|
||||
{
|
||||
return std::equal(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr bool operator!=(span<ElementType, Extent> l, span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l == r);
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr bool operator<(span<ElementType, Extent> l, span<ElementType, Extent> r)
|
||||
{
|
||||
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr bool operator<=(span<ElementType, Extent> l, span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l > r);
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr bool operator>(span<ElementType, Extent> l, span<ElementType, Extent> r)
|
||||
{
|
||||
return r < l;
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr bool operator>=(span<ElementType, Extent> l, span<ElementType, Extent> r)
|
||||
{
|
||||
return !(l < r);
|
||||
@ -705,23 +713,20 @@ namespace details
|
||||
// we should use a narrow_cast<> to go to std::size_t, but older compilers may not see it as
|
||||
// constexpr
|
||||
// and so will fail compilation of the template
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
struct calculate_byte_size
|
||||
: std::integral_constant<std::ptrdiff_t,
|
||||
static_cast<std::ptrdiff_t>(sizeof(ElementType) *
|
||||
static_cast<std::size_t>(Extent))>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
struct calculate_byte_size : std::integral_constant<std::size_t, sizeof(ElementType) * Extent>
|
||||
{
|
||||
};
|
||||
|
||||
template <class ElementType>
|
||||
struct calculate_byte_size<ElementType, dynamic_extent>
|
||||
: std::integral_constant<std::ptrdiff_t, dynamic_extent>
|
||||
: std::integral_constant<std::size_t, dynamic_extent>
|
||||
{
|
||||
};
|
||||
} // namespace details
|
||||
|
||||
// [span.objectrep], views of object representation
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
span<const byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_bytes(span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
@ -729,7 +734,7 @@ as_bytes(span<ElementType, Extent> s) noexcept
|
||||
return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent,
|
||||
template <class ElementType, std::size_t Extent,
|
||||
class = std::enable_if_t<!std::is_const<ElementType>::value>>
|
||||
span<byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_writeable_bytes(span<ElementType, Extent> s) noexcept
|
||||
@ -773,7 +778,7 @@ constexpr span<const typename Container::value_type> make_span(const Container&
|
||||
}
|
||||
|
||||
template <class Ptr>
|
||||
constexpr span<typename Ptr::element_type> make_span(Ptr& cont, std::ptrdiff_t count)
|
||||
constexpr span<typename Ptr::element_type> make_span(Ptr& cont, std::size_t count)
|
||||
{
|
||||
return span<typename Ptr::element_type>(cont, count);
|
||||
}
|
||||
@ -785,7 +790,7 @@ constexpr span<typename Ptr::element_type> make_span(Ptr& cont)
|
||||
}
|
||||
|
||||
// Specialization of gsl::at for span
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr ElementType& at(span<ElementType, Extent> s, index i)
|
||||
{
|
||||
// No bounds checking here because it is done in span::operator[] called below
|
||||
@ -793,57 +798,66 @@ constexpr ElementType& at(span<ElementType, Extent> s, index i)
|
||||
}
|
||||
|
||||
// [span.obs] Free observer functions
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::index_type ssize(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::index_type
|
||||
ssize(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.size();
|
||||
}
|
||||
|
||||
// [span.iter] Free functions for begin/end functions
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::iterator begin(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::iterator
|
||||
begin(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.begin();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent = dynamic_extent>
|
||||
constexpr typename span<ElementType, Extent>::iterator end(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent = dynamic_extent>
|
||||
constexpr typename span<ElementType, Extent>::iterator
|
||||
end(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.end();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_iterator cbegin(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_iterator
|
||||
cbegin(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.cbegin();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_iterator cend(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_iterator
|
||||
cend(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.cend();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::reverse_iterator rbegin(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::reverse_iterator
|
||||
rbegin(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.rbegin();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::reverse_iterator rend(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::reverse_iterator
|
||||
rend(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.rend();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_reverse_iterator crbegin(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_reverse_iterator
|
||||
crbegin(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.crbegin();
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_reverse_iterator crend(const span<ElementType, Extent> &span) noexcept
|
||||
template <class ElementType, std::size_t Extent>
|
||||
constexpr typename span<ElementType, Extent>::const_reverse_iterator
|
||||
crend(const span<ElementType, Extent>& span) noexcept
|
||||
{
|
||||
return span.crend();
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <algorithm> // for equal, lexicographical_compare
|
||||
#include <array> // for array
|
||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||
#include <cstddef> // for size_t, nullptr_t
|
||||
#include <cstdint> // for PTRDIFF_MAX
|
||||
#include <cstring>
|
||||
#include <string> // for basic_string, allocator, char_traits
|
||||
@ -56,43 +56,43 @@ namespace gsl
|
||||
// (sometimes needlessly) break existing programs when introduced.
|
||||
//
|
||||
|
||||
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
using basic_zstring = CharT*;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using czstring = basic_zstring<const char, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cwzstring = basic_zstring<const wchar_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu16zstring = basic_zstring<const char16_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu32zstring = basic_zstring<const char32_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using zstring = basic_zstring<char, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using wzstring = basic_zstring<wchar_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u16zstring = basic_zstring<char16_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u32zstring = basic_zstring<char32_t, Extent>;
|
||||
|
||||
namespace details
|
||||
{
|
||||
template <class CharT>
|
||||
std::ptrdiff_t string_length(const CharT* str, std::ptrdiff_t n)
|
||||
std::size_t string_length(const CharT* str, std::size_t n)
|
||||
{
|
||||
if (str == nullptr || n <= 0) return 0;
|
||||
if (str == nullptr || n == dynamic_extent) return 0;
|
||||
|
||||
const span<const CharT> str_span{str, n};
|
||||
|
||||
std::ptrdiff_t len = 0;
|
||||
std::size_t len = 0;
|
||||
while (len < n && str_span[len]) len++;
|
||||
|
||||
return len;
|
||||
@ -108,18 +108,20 @@ namespace details
|
||||
// Will fail-fast if sentinel cannot be found before max elements are examined.
|
||||
//
|
||||
template <typename T, const T Sentinel>
|
||||
span<T, dynamic_extent> ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX)
|
||||
span<T, dynamic_extent> ensure_sentinel(T* seq,
|
||||
std::size_t max = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
Ensures(seq != nullptr);
|
||||
|
||||
GSL_SUPPRESS(f.23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work
|
||||
GSL_SUPPRESS(
|
||||
f .23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work
|
||||
auto cur = seq;
|
||||
Ensures(cur != nullptr); // workaround for removing the warning
|
||||
|
||||
GSL_SUPPRESS(bounds .1) // NO-FORMAT: attribute // TODO: suppress does not work
|
||||
while ((cur - seq) < max && *cur != Sentinel) ++cur;
|
||||
while (static_cast<std::size_t>(cur - seq) < max && *cur != Sentinel) ++cur;
|
||||
Ensures(*cur == Sentinel);
|
||||
return {seq, cur - seq};
|
||||
return {seq, static_cast<std::size_t>(cur - seq)};
|
||||
}
|
||||
|
||||
//
|
||||
@ -128,7 +130,8 @@ span<T, dynamic_extent> ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX
|
||||
// the limit of size_type.
|
||||
//
|
||||
template <typename CharT>
|
||||
span<CharT, dynamic_extent> ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRDIFF_MAX)
|
||||
span<CharT, dynamic_extent> ensure_z(CharT* const& sz,
|
||||
std::size_t max = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return ensure_sentinel<CharT, CharT(0)>(sz, max);
|
||||
}
|
||||
@ -136,26 +139,27 @@ span<CharT, dynamic_extent> ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRD
|
||||
template <typename CharT, std::size_t N>
|
||||
span<CharT, dynamic_extent> ensure_z(CharT (&sz)[N])
|
||||
{
|
||||
return ensure_z(&sz[0], narrow_cast<std::ptrdiff_t>(N));
|
||||
return ensure_z(&sz[0], N);
|
||||
}
|
||||
|
||||
template <class Cont>
|
||||
span<typename std::remove_pointer<typename Cont::pointer>::type, dynamic_extent>
|
||||
ensure_z(Cont& cont)
|
||||
{
|
||||
return ensure_z(cont.data(), narrow_cast<std::ptrdiff_t>(cont.size()));
|
||||
return ensure_z(cont.data(), cont.size());
|
||||
}
|
||||
|
||||
template <typename CharT, std::ptrdiff_t>
|
||||
template <typename CharT, std::size_t>
|
||||
class basic_string_span;
|
||||
|
||||
namespace details {
|
||||
namespace details
|
||||
{
|
||||
template <typename T>
|
||||
struct is_basic_string_span_oracle : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename CharT, std::ptrdiff_t Extent>
|
||||
template <typename CharT, std::size_t Extent>
|
||||
struct is_basic_string_span_oracle<basic_string_span<CharT, Extent>> : std::true_type
|
||||
{
|
||||
};
|
||||
@ -169,7 +173,7 @@ namespace details {
|
||||
//
|
||||
// string_span and relatives
|
||||
//
|
||||
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
class basic_string_span
|
||||
{
|
||||
public:
|
||||
@ -218,7 +222,7 @@ public:
|
||||
template <class Traits, class Allocator>
|
||||
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
|
||||
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator>& str)
|
||||
: span_(&str[0], narrow_cast<std::ptrdiff_t>(str.length()))
|
||||
: span_(&str[0], str.length())
|
||||
{}
|
||||
|
||||
template <class Traits, class Allocator>
|
||||
@ -247,7 +251,7 @@ public:
|
||||
|
||||
// from string_span
|
||||
template <
|
||||
class OtherValueType, std::ptrdiff_t OtherExtent,
|
||||
class OtherValueType, std::size_t OtherExtent,
|
||||
class = std::enable_if_t<std::is_convertible<
|
||||
typename basic_string_span<OtherValueType, OtherExtent>::impl_type, impl_type>::value>>
|
||||
constexpr basic_string_span(basic_string_span<OtherValueType, OtherExtent> other)
|
||||
@ -312,7 +316,7 @@ public:
|
||||
constexpr const_reverse_iterator crend() const noexcept { return span_.crend(); }
|
||||
|
||||
private:
|
||||
static impl_type remove_z(pointer const& sz, std::ptrdiff_t max)
|
||||
static impl_type remove_z(pointer const& sz, std::size_t max)
|
||||
{
|
||||
return {sz, details::string_length(sz, max)};
|
||||
}
|
||||
@ -320,41 +324,41 @@ private:
|
||||
template <std::size_t N>
|
||||
static impl_type remove_z(element_type (&sz)[N])
|
||||
{
|
||||
return remove_z(&sz[0], narrow_cast<std::ptrdiff_t>(N));
|
||||
return remove_z(&sz[0], N);
|
||||
}
|
||||
|
||||
impl_type span_;
|
||||
};
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using string_span = basic_string_span<char, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cstring_span = basic_string_span<const char, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using wstring_span = basic_string_span<wchar_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cwstring_span = basic_string_span<const wchar_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u16string_span = basic_string_span<char16_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu16string_span = basic_string_span<const char16_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u32string_span = basic_string_span<char32_t, Extent>;
|
||||
|
||||
template <std::ptrdiff_t Extent = dynamic_extent>
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu32string_span = basic_string_span<const char32_t, Extent>;
|
||||
|
||||
//
|
||||
// to_string() allow (explicit) conversions from string_span to string
|
||||
//
|
||||
|
||||
template <typename CharT, std::ptrdiff_t Extent>
|
||||
template <typename CharT, std::size_t Extent>
|
||||
std::basic_string<typename std::remove_const<CharT>::type>
|
||||
to_string(basic_string_span<CharT, Extent> view)
|
||||
{
|
||||
@ -362,13 +366,13 @@ to_string(basic_string_span<CharT, Extent> view)
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits = typename std::char_traits<CharT>,
|
||||
typename Allocator = std::allocator<CharT>, typename gCharT, std::ptrdiff_t Extent>
|
||||
typename Allocator = std::allocator<CharT>, typename gCharT, std::size_t Extent>
|
||||
std::basic_string<CharT, Traits, Allocator> to_basic_string(basic_string_span<gCharT, Extent> view)
|
||||
{
|
||||
return {view.data(), narrow_cast<std::size_t>(view.length())};
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent>
|
||||
template <class ElementType, std::size_t Extent>
|
||||
basic_string_span<const byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
@ -376,7 +380,7 @@ as_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
template <class ElementType, std::ptrdiff_t Extent,
|
||||
template <class ElementType, std::size_t Extent,
|
||||
class = std::enable_if_t<!std::is_const<ElementType>::value>>
|
||||
basic_string_span<byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_writeable_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
@ -387,8 +391,9 @@ as_writeable_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
|
||||
// zero-terminated string span, used to convert
|
||||
// zero-terminated spans to legacy strings
|
||||
template <typename CharT, std::ptrdiff_t Extent = dynamic_extent>
|
||||
class basic_zstring_span {
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
class basic_zstring_span
|
||||
{
|
||||
public:
|
||||
using value_type = CharT;
|
||||
using const_value_type = std::add_const_t<CharT>;
|
||||
@ -435,32 +440,32 @@ private:
|
||||
impl_type span_;
|
||||
};
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using zstring_span = basic_zstring_span<char, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using wzstring_span = basic_zstring_span<wchar_t, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using u16zstring_span = basic_zstring_span<char16_t, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using u32zstring_span = basic_zstring_span<char32_t, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using czstring_span = basic_zstring_span<const char, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cwzstring_span = basic_zstring_span<const wchar_t, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cu16zstring_span = basic_zstring_span<const char16_t, Max>;
|
||||
|
||||
template <std::ptrdiff_t Max = dynamic_extent>
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cu32zstring_span = basic_zstring_span<const char32_t, Max>;
|
||||
|
||||
// operator ==
|
||||
template <class CharT, std::ptrdiff_t Extent, class T,
|
||||
template <class CharT, std::size_t Extent, class T,
|
||||
class = std::enable_if_t<
|
||||
details::is_basic_string_span<T>::value ||
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>>>::value>>
|
||||
@ -470,7 +475,7 @@ bool operator==(const gsl::basic_string_span<CharT, Extent>& one, const T& other
|
||||
return std::equal(one.begin(), one.end(), tmp.begin(), tmp.end());
|
||||
}
|
||||
|
||||
template <class CharT, std::ptrdiff_t Extent, class T,
|
||||
template <class CharT, std::size_t Extent, class T,
|
||||
class = std::enable_if_t<
|
||||
!details::is_basic_string_span<T>::value &&
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>>>::value>>
|
||||
@ -481,7 +486,7 @@ bool operator==(const T& one, const gsl::basic_string_span<CharT, Extent>& other
|
||||
}
|
||||
|
||||
// operator !=
|
||||
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator!=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@ -490,7 +495,7 @@ bool operator!=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@ -500,7 +505,7 @@ bool operator!=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
}
|
||||
|
||||
// operator<
|
||||
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@ -510,7 +515,7 @@ bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@ -526,7 +531,7 @@ bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -540,7 +545,7 @@ bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -555,7 +560,7 @@ bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator <=
|
||||
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@ -564,7 +569,7 @@ bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@ -579,7 +584,7 @@ bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -592,7 +597,7 @@ bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -606,7 +611,7 @@ bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator>
|
||||
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@ -615,7 +620,7 @@ bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@ -630,7 +635,7 @@ bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -643,7 +648,7 @@ bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -657,7 +662,7 @@ bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator >=
|
||||
template <typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@ -666,7 +671,7 @@ bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@ -681,7 +686,7 @@ bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@ -694,7 +699,7 @@ bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::ptrdiff_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
|
@ -158,14 +158,14 @@ TEST(span_test, from_pointer_length_constructor)
|
||||
int arr[4] = {1, 2, 3, 4};
|
||||
|
||||
{
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (std::size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
{
|
||||
span<int> s = {&arr[0], i};
|
||||
EXPECT_TRUE(s.size() == i);
|
||||
EXPECT_TRUE(s.data() == &arr[0]);
|
||||
EXPECT_TRUE(s.empty() == (i == 0));
|
||||
for (int j = 0; j < i; ++j)
|
||||
for (std::size_t j = 0; j < i; ++j)
|
||||
{
|
||||
EXPECT_TRUE(arr[j] == s[j]);
|
||||
EXPECT_TRUE(arr[j] == s.at(j));
|
||||
@ -173,12 +173,12 @@ TEST(span_test, from_pointer_length_constructor)
|
||||
}
|
||||
}
|
||||
{
|
||||
span<int> s = {&arr[i], 4 - narrow_cast<ptrdiff_t>(i)};
|
||||
span<int> s = {&arr[i], 4 - i};
|
||||
EXPECT_TRUE(s.size() == 4 - i);
|
||||
EXPECT_TRUE(s.data() == &arr[i]);
|
||||
EXPECT_TRUE(s.empty() == ((4 - i) == 0));
|
||||
|
||||
for (int j = 0; j < 4 - i; ++j)
|
||||
for (std::size_t j = 0; j < 4 - i; ++j)
|
||||
{
|
||||
EXPECT_TRUE(arr[j + i] == s[j]);
|
||||
EXPECT_TRUE(arr[j + i] == s.at(j));
|
||||
@ -457,21 +457,21 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<int> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
|
||||
span<const int> cs{arr};
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(cs.size() == arr.size());
|
||||
EXPECT_TRUE(cs.data() == arr.data());
|
||||
}
|
||||
|
||||
{
|
||||
span<int, 4> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
|
||||
span<const int, 4> cs{arr};
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(cs.size() == arr.size());
|
||||
EXPECT_TRUE(cs.data() == arr.data());
|
||||
}
|
||||
|
||||
@ -486,7 +486,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<AddressOverloaded, 4> fs{ao_arr};
|
||||
EXPECT_TRUE(fs.size() == narrow_cast<ptrdiff_t>(ao_arr.size()));
|
||||
EXPECT_TRUE(fs.size() == ao_arr.size());
|
||||
EXPECT_TRUE(ao_arr.data() == fs.data());
|
||||
}
|
||||
|
||||
@ -532,7 +532,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
auto s = make_span(arr);
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
|
||||
@ -561,13 +561,13 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<const int> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
|
||||
{
|
||||
span<const int, 4> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
|
||||
@ -575,7 +575,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<const AddressOverloaded, 4> s{ao_arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(ao_arr.size()));
|
||||
EXPECT_TRUE(s.size() == ao_arr.size());
|
||||
EXPECT_TRUE(s.data() == ao_arr.data());
|
||||
}
|
||||
|
||||
@ -606,7 +606,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
auto s = make_span(arr);
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
}
|
||||
@ -617,13 +617,13 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<const int> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
|
||||
{
|
||||
span<const int, 4> s{arr};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
|
||||
@ -651,7 +651,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
auto s = make_span(arr);
|
||||
EXPECT_TRUE(s.size() == narrow_cast<ptrdiff_t>(arr.size()));
|
||||
EXPECT_TRUE(s.size() == arr.size());
|
||||
EXPECT_TRUE(s.data() == arr.data());
|
||||
}
|
||||
}
|
||||
@ -663,11 +663,11 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
span<int> s{v};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<std::ptrdiff_t>(v.size()));
|
||||
EXPECT_TRUE(s.size() == v.size());
|
||||
EXPECT_TRUE(s.data() == v.data());
|
||||
|
||||
span<const int> cs{v};
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<std::ptrdiff_t>(v.size()));
|
||||
EXPECT_TRUE(cs.size() == v.size());
|
||||
EXPECT_TRUE(cs.data() == v.data());
|
||||
}
|
||||
|
||||
@ -677,11 +677,11 @@ TEST(span_test, from_array_constructor)
|
||||
{
|
||||
#ifdef CONFIRM_COMPILATION_ERRORS
|
||||
span<char> s{str};
|
||||
EXPECT_TRUE(s.size() == narrow_cast<std::ptrdiff_t>(str.size()));
|
||||
EXPECT_TRUE(s.size() == str.size());
|
||||
EXPECT_TRUE(s.data() == str.data()));
|
||||
#endif
|
||||
span<const char> cs{str};
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<std::ptrdiff_t>(str.size()));
|
||||
EXPECT_TRUE(cs.size() == str.size());
|
||||
EXPECT_TRUE(cs.data() == str.data());
|
||||
}
|
||||
|
||||
@ -690,7 +690,7 @@ TEST(span_test, from_array_constructor)
|
||||
span<char> s{cstr};
|
||||
#endif
|
||||
span<const char> cs{cstr};
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<std::ptrdiff_t>(cstr.size()));
|
||||
EXPECT_TRUE(cs.size() == cstr.size());
|
||||
EXPECT_TRUE(cs.data() == cstr.data());
|
||||
}
|
||||
|
||||
@ -745,11 +745,11 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
{
|
||||
auto s = make_span(v);
|
||||
EXPECT_TRUE(s.size() == narrow_cast<std::ptrdiff_t>(v.size()));
|
||||
EXPECT_TRUE(s.size() == v.size());
|
||||
EXPECT_TRUE(s.data() == v.data());
|
||||
|
||||
auto cs = make_span(cv);
|
||||
EXPECT_TRUE(cs.size() == narrow_cast<std::ptrdiff_t>(cv.size()));
|
||||
EXPECT_TRUE(cs.size() == cv.size());
|
||||
EXPECT_TRUE(cs.data() == cv.data());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user