mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge pull request #830 from JordanMaples/dev/jomaples/add_missing_span_functions
Add span::front and span::back. See #828.
This commit is contained in:
commit
888b9b9723
@ -509,13 +509,27 @@ public:
|
|||||||
Expects(CheckRange(idx, storage_.size()));
|
Expects(CheckRange(idx, storage_.size()));
|
||||||
return data()[idx];
|
return data()[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr reference front() const noexcept
|
||||||
|
{
|
||||||
|
Expects(size() > 0);
|
||||||
|
return data()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr reference back() const noexcept
|
||||||
|
{
|
||||||
|
Expects(size() > 0);
|
||||||
|
return data()[size() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
// at and operator() are deprecated to align to the public member functions of std::span
|
// at and operator() are deprecated to align to the public member functions of std::span
|
||||||
[[deprecated("Use operator[]")]]
|
[[deprecated("Use operator[]")]]
|
||||||
constexpr reference at(index_type idx) const noexcept{ return this->operator[](idx); }
|
constexpr reference at(index_type idx) const noexcept{ return this->operator[](idx); }
|
||||||
[[deprecated("Use operator[]")]]
|
[[deprecated("Use operator[]")]]
|
||||||
constexpr reference operator()(index_type idx) const noexcept{ return this->operator[](idx); }
|
constexpr reference operator()(index_type idx) const noexcept{ return this->operator[](idx); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constexpr pointer data() const noexcept { return storage_.data(); }
|
constexpr pointer data() const noexcept { return storage_.data(); }
|
||||||
|
|
||||||
// [span.iter], span iterator support
|
// [span.iter], span iterator support
|
||||||
|
@ -1683,6 +1683,22 @@ TEST(span_test, from_array_constructor)
|
|||||||
EXPECT_FALSE((std::is_default_constructible<span<int, 42>>::value));
|
EXPECT_FALSE((std::is_default_constructible<span<int, 42>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(span_test, front_back)
|
||||||
|
{
|
||||||
|
int arr[5] = {1,2,3,4,5};
|
||||||
|
span<int> s{arr};
|
||||||
|
EXPECT_TRUE(s.front() == 1);
|
||||||
|
EXPECT_TRUE(s.back() == 5);
|
||||||
|
|
||||||
|
std::set_terminate([] {
|
||||||
|
std::cerr << "Expected Death. front_back";
|
||||||
|
std::abort();
|
||||||
|
});
|
||||||
|
span<int> s2;
|
||||||
|
EXPECT_DEATH(s2.front(), deathstring);
|
||||||
|
EXPECT_DEATH(s2.back(), deathstring);
|
||||||
|
}
|
||||||
|
|
||||||
#if __clang__ || __GNUC__
|
#if __clang__ || __GNUC__
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif // __clang__ || __GNUC__
|
#endif // __clang__ || __GNUC__
|
||||||
|
Loading…
Reference in New Issue
Block a user