diff options
author | Neil MacIntosh <neilmac@microsoft.com> | 2016-08-25 08:35:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 08:35:52 -0700 |
commit | 5e2618b034069fa5d991339a8db14118d12ad831 (patch) | |
tree | e728b3e44dd6d5583991ff6a78865d0397e846ff | |
parent | deda5e6c46574dc99b4e1431ec85ff5e964e58bd (diff) | |
parent | 134f2db5d9c9039b04cb2da1513c7ffdd7906fb8 (diff) | |
download | platform_external_Microsoft-GSL-5e2618b034069fa5d991339a8db14118d12ad831.tar.gz platform_external_Microsoft-GSL-5e2618b034069fa5d991339a8db14118d12ad831.tar.bz2 platform_external_Microsoft-GSL-5e2618b034069fa5d991339a8db14118d12ad831.zip |
Specialize gsl::at for span
-rw-r--r-- | gsl/span | 8 | ||||
-rw-r--r-- | tests/span_tests.cpp | 7 |
2 files changed, 15 insertions, 0 deletions
@@ -653,6 +653,14 @@ as_writeable_bytes(span<ElementType, Extent> s) noexcept return {reinterpret_cast<byte*>(s.data()), s.size_bytes()}; } +// Specialization of gsl::at for span +template <class ElementType, std::ptrdiff_t Extent> +constexpr ElementType& at(const span<ElementType ,Extent>& s, size_t index) +{ + // No bounds checking here because it is done in span::operator[] called below + return s[index]; +} + } // namespace gsl #ifdef _MSC_VER diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 712492f..571a821 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -1354,6 +1354,13 @@ SUITE(span_tests) CHECK(match[0].first == f_it); CHECK(match[0].second == (f_it + 1)); } + + TEST(interop_with_gsl_at) + { + int arr[5] = {1, 2, 3, 4, 5}; + span<int> s{arr}; + CHECK(at(s,0) == 1 && at(s,1) == 2); + } } int main(int, const char* []) { return UnitTest::RunAllTests(); } |