| 1 |
// { dg-do run { target c++26 } } |
| 2 |
|
| 3 |
#include <span> |
| 4 |
#include <stdexcept> |
| 5 |
#include <testsuite_hooks.h> |
| 6 |
|
| 7 |
void |
| 8 |
test_at() |
| 9 |
{ |
| 10 |
int arr[4]{0, 1, 2, 3}; |
| 11 |
std::span<int> s(arr); |
| 12 |
VERIFY(s.at(2) == 2); |
| 13 |
#if __cpp_exceptions |
| 14 |
try { |
| 15 |
s.at(4); // { dg-warning "ignoring return value" "" { target exceptions_enabled } } |
| 16 |
VERIFY(false); |
| 17 |
} catch (const std::out_of_range&) { |
| 18 |
} |
| 19 |
#endif |
| 20 |
|
| 21 |
auto s2 = s.subspan(1, 2); |
| 22 |
VERIFY(s2.at(0) == 1); |
| 23 |
VERIFY(s2.at(1) == 2); |
| 24 |
#if __cpp_exceptions |
| 25 |
try { |
| 26 |
s2.at(2); // { dg-warning "ignoring return value" "" { target exceptions_enabled } } |
| 27 |
VERIFY(false); |
| 28 |
} catch (const std::out_of_range&) { |
| 29 |
} |
| 30 |
#endif |
| 31 |
} |
| 32 |
|
| 33 |
int main() |
| 34 |
{ |
| 35 |
test_at(); |
| 36 |
} |