aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRian Quinn <rianquinn@gmail.com>2016-10-26 15:11:24 -0600
committerNeil MacIntosh <neilmac@microsoft.com>2016-10-26 14:11:24 -0700
commit6cffe0d14cbc0540e16939aaffbee3451fa0a131 (patch)
tree23b2a56605bc8cb9fa8fa30d012e32554d661208
parentb07383ead13d46ead9090fcd80dbd79ae6154bac (diff)
downloadplatform_external_Microsoft-GSL-6cffe0d14cbc0540e16939aaffbee3451fa0a131.tar.gz
platform_external_Microsoft-GSL-6cffe0d14cbc0540e16939aaffbee3451fa0a131.tar.bz2
platform_external_Microsoft-GSL-6cffe0d14cbc0540e16939aaffbee3451fa0a131.zip
Adds gsl::span::at()
As per this discussion: https://github.com/Microsoft/GSL/issues/402 This patch adds support for at() to gsl::span
-rw-r--r--gsl/span2
-rw-r--r--tests/span_tests.cpp19
2 files changed, 21 insertions, 0 deletions
diff --git a/gsl/span b/gsl/span
index 6f74dc5..cf90e86 100644
--- a/gsl/span
+++ b/gsl/span
@@ -503,6 +503,8 @@ public:
Expects(idx >= 0 && idx < storage_.size());
return data()[idx];
}
+
+ constexpr reference at(index_type idx) const { return this->operator[](idx); }
constexpr reference operator()(index_type idx) const { return this->operator[](idx); }
constexpr pointer data() const noexcept { return storage_.data(); }
diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp
index a1dd64d..35e6b03 100644
--- a/tests/span_tests.cpp
+++ b/tests/span_tests.cpp
@@ -769,6 +769,25 @@ SUITE(span_tests)
}
}
+ TEST(at_call)
+ {
+ int arr[4] = {1, 2, 3, 4};
+
+ {
+ span<int> s = arr;
+ CHECK(s.at(0) == 1);
+ CHECK_THROW(s.at(5), fail_fast);
+ }
+
+ {
+ int arr2d[2] = {1, 6};
+ span<int, 2> s = arr2d;
+ CHECK(s.at(0) == 1);
+ CHECK(s.at(1) == 6);
+ CHECK_THROW(s.at(2) ,fail_fast);
+ }
+ }
+
TEST(operator_function_call)
{
int arr[4] = {1, 2, 3, 4};