mirror of
https://github.com/microsoft/GSL.git
synced 2025-04-02 09:18:33 -04:00
check for dynamic_extent
This commit is contained in:
parent
e8fa8b189d
commit
e31f8d76e5
@ -582,7 +582,7 @@ public:
|
|||||||
template <std::size_t Count>
|
template <std::size_t Count>
|
||||||
constexpr span<element_type, Count> first() const noexcept
|
constexpr span<element_type, Count> first() const noexcept
|
||||||
{
|
{
|
||||||
static_assert(Count <= Extent,
|
static_assert(Extent == dynamic_extent || Count <= Extent,
|
||||||
"first() cannot extract more elements from a span than it contains.");
|
"first() cannot extract more elements from a span than it contains.");
|
||||||
Expects(Count <= size());
|
Expects(Count <= size());
|
||||||
return span<element_type, Count>{data(), Count};
|
return span<element_type, Count>{data(), Count};
|
||||||
@ -594,7 +594,7 @@ public:
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
constexpr span<element_type, Count> last() const noexcept
|
constexpr span<element_type, Count> last() const noexcept
|
||||||
{
|
{
|
||||||
static_assert(Count <= Extent,
|
static_assert(Extent == dynamic_extent || Count <= Extent,
|
||||||
"last() cannot extract more elements from a span than it contains.");
|
"last() cannot extract more elements from a span than it contains.");
|
||||||
Expects(Count <= size());
|
Expects(Count <= size());
|
||||||
return span<element_type, Count>{data() + (size() - Count), Count};
|
return span<element_type, Count>{data() + (size() - Count), Count};
|
||||||
@ -607,7 +607,8 @@ 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
|
||||||
{
|
{
|
||||||
static_assert(Extent >= Offset && (Count == dynamic_extent || Count <= Extent - Offset),
|
static_assert(Extent == dynamic_extent || (Extent >= Offset && (Count == dynamic_extent ||
|
||||||
|
Count <= Extent - Offset)),
|
||||||
"subspan() cannot extract more elements from a span than it contains.");
|
"subspan() cannot extract more elements from a span than it contains.");
|
||||||
Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
|
Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
|
||||||
using type =
|
using type =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user