mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
adding front and back
This commit is contained in:
parent
7e99e76c97
commit
7004ef506c
@ -512,6 +512,19 @@ public:
|
|||||||
|
|
||||||
constexpr reference at(index_type idx) const { return this->operator[](idx); }
|
constexpr reference at(index_type idx) const { return this->operator[](idx); }
|
||||||
constexpr reference operator()(index_type idx) const { return this->operator[](idx); }
|
constexpr reference operator()(index_type idx) const { return this->operator[](idx); }
|
||||||
|
|
||||||
|
constexpr reference front() const
|
||||||
|
{
|
||||||
|
Expects(size() > 0);
|
||||||
|
return data()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr reference back() const
|
||||||
|
{
|
||||||
|
Expects(size() > 0);
|
||||||
|
return data()[size() - 1];
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -893,7 +893,7 @@ TEST_CASE("subspan")
|
|||||||
{
|
{
|
||||||
span<int, 5> av = arr;
|
span<int, 5> av = arr;
|
||||||
CHECK((av.subspan<1>().size() == 4));
|
CHECK((av.subspan<1>().size() == 4));
|
||||||
CHECK(decltype(av.subspan<1>())::extent == 4);
|
CHECK(decltype(av.subspan<1>())::extent == 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -1562,3 +1562,16 @@ TEST_CASE("default_constructible")
|
|||||||
CHECK((!std::is_default_constructible<span<int, 42>>::value));
|
CHECK((!std::is_default_constructible<span<int, 42>>::value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST_CASE("front_back")
|
||||||
|
{
|
||||||
|
int arr[5] = {1,2,3,4,5};
|
||||||
|
span<int> s{arr};
|
||||||
|
CHECK(s.front() == 1);
|
||||||
|
CHECK(s.back() == 5);
|
||||||
|
|
||||||
|
span<int> s2;
|
||||||
|
CHECK_THROWS_AS(s2.front(), fail_fast);
|
||||||
|
CHECK_THROWS_AS(s2.back(), fail_fast);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user