diff --git a/.travis.yml b/.travis.yml
index 5c69187..53d110d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -93,7 +93,7 @@ install:
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
if [[ -z "$(ls -A ${DEPS_DIR}/cmake/bin)" ]]; then
- CMAKE_URL="https://cmake.org/files/v3.6/cmake-3.6.2-Linux-x86_64.tar.gz"
+ CMAKE_URL="https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz"
mkdir -p cmake && travis_retry wget --no-check-certificate --quiet -O - "${CMAKE_URL}" | tar --strip-components=1 -xz -C cmake
fi
export PATH="${DEPS_DIR}/cmake/bin:${PATH}"
diff --git a/README.md b/README.md
index 25c92cf..120e2b1 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
## Supported Platforms
The test suite that exercises GSL has been built and passes successfully on the following platforms:1)
-* Windows using Visual Studio 2013
* Windows using Visual Studio 2015
* Windows using Visual Studio 2017
* Windows using Clang/LLVM 3.6
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..5acfd11
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,48 @@
+shallow_clone: true
+
+platform:
+ - x86
+ - x64
+
+configuration:
+ - Debug
+ - Release
+
+image:
+ - Visual Studio 2015
+ - Visual Studio 2017
+
+cache:
+ - C:\cmake-3.7.2-win32-x86
+
+install:
+ - git clone --quiet --depth=1 https://github.com/Microsoft/unittest-cpp.git tests/unittest-cpp
+ - ps: |
+ if (![IO.File]::Exists("C:\cmake-3.7.2-win32-x86\bin\cmake.exe")) {
+ Start-FileDownload 'https://cmake.org/files/v3.7/cmake-3.7.2-win32-x86.zip'
+ 7z x -y cmake-3.7.2-win32-x86.zip -oC:\
+ }
+ $env:PATH="C:\cmake-3.7.2-win32-x86\bin;$env:PATH"
+
+before_build:
+ - ps: |
+ mkdir build
+ cd build
+ if ("$env:APPVEYOR_JOB_NAME" -match "Image: Visual Studio 2015") {
+ $env:generator="Visual Studio 14 2015"
+ } else {
+ $env:generator="Visual Studio 15 2017"
+ }
+ if ($env:PLATFORM -eq "x64") {
+ $env:generator="$env:generator Win64"
+ }
+ echo generator="$env:generator"
+ cmake .. -G "$env:generator"
+
+build_script:
+ - cmake --build . --config %CONFIGURATION% -- /m /v:minimal
+
+test_script:
+ - ctest -j2
+
+deploy: off
diff --git a/include/gsl/gsl_assert b/include/gsl/gsl_assert
index 1b7b810..fdfe0b0 100644
--- a/include/gsl/gsl_assert
+++ b/include/gsl/gsl_assert
@@ -68,9 +68,9 @@
namespace gsl
{
-struct fail_fast : public std::runtime_error
+struct fail_fast : public std::logic_error
{
- explicit fail_fast(char const* const message) : std::runtime_error(message) {}
+ explicit fail_fast(char const* const message) : std::logic_error(message) {}
};
}
diff --git a/include/gsl/string_span b/include/gsl/string_span
index 9e75ae8..d79acca 100644
--- a/include/gsl/string_span
+++ b/include/gsl/string_span
@@ -577,7 +577,7 @@ template >>::value>>
bool operator==(const gsl::basic_string_span& one, const T& other) GSL_NOEXCEPT
{
- gsl::basic_string_span> tmp(other);
+ const gsl::basic_string_span> tmp(other);
#ifdef GSL_MSVC_NO_CPP14_STD_EQUAL
return (one.size() == tmp.size()) && std::equal(one.begin(), one.end(), tmp.begin());
#else
@@ -624,7 +624,7 @@ template , Extent>>::value>>
bool operator<(gsl::basic_string_span one, const T& other) GSL_NOEXCEPT
{
- gsl::basic_string_span, Extent> tmp(other);
+ const gsl::basic_string_span, Extent> tmp(other);
return std::lexicographical_compare(one.begin(), one.end(), tmp.begin(), tmp.end());
}
diff --git a/tests/bounds_tests.cpp b/tests/bounds_tests.cpp
index 57f358e..98babb2 100644
--- a/tests/bounds_tests.cpp
+++ b/tests/bounds_tests.cpp
@@ -45,7 +45,7 @@ SUITE(bounds_test)
TEST(bounds_basic)
{
static_bounds<3, 4, 5> b;
- auto a = b.slice();
+ const auto a = b.slice();
(void)a;
static_bounds<4, dynamic_range, 2> x{ 4 };
x.slice().slice();
@@ -55,7 +55,7 @@ SUITE(bounds_test)
{
static_bounds<4, dynamic_range, 2> bounds{ 3 };
- auto itr = bounds.begin();
+ const auto itr = bounds.begin();
(void)itr;
#ifdef CONFIRM_COMPILATION_ERRORS
multi_span av(nullptr, bounds);
diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp
index 8cb0da8..82fdcc0 100644
--- a/tests/byte_tests.cpp
+++ b/tests/byte_tests.cpp
@@ -35,22 +35,22 @@ SUITE(byte_tests)
TEST(construction)
{
{
- byte b = static_cast(4);
+ const byte b = static_cast(4);
CHECK(static_cast(b) == 4);
}
{
- byte b = byte(12);
+ const byte b = byte(12);
CHECK(static_cast(b) == 12);
}
{
- byte b = to_byte<12>();
+ const byte b = to_byte<12>();
CHECK(static_cast(b) == 12);
}
{
- unsigned char uc = 12;
- byte b = to_byte(uc);
+ const unsigned char uc = 12;
+ const byte b = to_byte(uc);
CHECK(static_cast(b) == 12);
}
@@ -63,7 +63,7 @@ SUITE(byte_tests)
TEST(bitwise_operations)
{
- byte b = to_byte<0xFF>();
+ const byte b = to_byte<0xFF>();
byte a = to_byte<0x00>();
CHECK((b | a) == to_byte<0xFF>());
@@ -79,7 +79,7 @@ SUITE(byte_tests)
CHECK(a == to_byte<0x01>());
CHECK((b ^ a) == to_byte<0xFE>());
-
+
CHECK(a == to_byte<0x01>());
a ^= b;
CHECK(a == to_byte<0xFE>());
@@ -99,7 +99,7 @@ SUITE(byte_tests)
TEST(to_integer)
{
- byte b = to_byte<0x12>();
+ const byte b = to_byte<0x12>();
CHECK(0x12 == gsl::to_integer(b));
CHECK(0x12 == gsl::to_integer(b));
@@ -125,7 +125,7 @@ SUITE(byte_tests)
TEST(aliasing)
{
int i{ 0 };
- int res = modify_both(reinterpret_cast(i), i);
+ const int res = modify_both(reinterpret_cast(i), i);
CHECK(res == i);
}
}
diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp
index 18c18b1..08947cf 100644
--- a/tests/span_tests.cpp
+++ b/tests/span_tests.cpp
@@ -930,7 +930,7 @@ SUITE(span_tests)
CHECK(av.subspan(4).length() == 1);
CHECK(av.subspan(5).length() == 0);
CHECK_THROW(av.subspan(6).length(), fail_fast);
- auto av2 = av.subspan(1);
+ const auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) CHECK(av2[i] == i + 2);
}
@@ -941,7 +941,7 @@ SUITE(span_tests)
CHECK(av.subspan(4).length() == 1);
CHECK(av.subspan(5).length() == 0);
CHECK_THROW(av.subspan(6).length(), fail_fast);
- auto av2 = av.subspan(1);
+ const auto av2 = av.subspan(1);
for (int i = 0; i < 4; ++i) CHECK(av2[i] == i + 2);
}
}
@@ -1117,7 +1117,7 @@ SUITE(span_tests)
CHECK(it == beyond);
CHECK(it - beyond == 0);
- for (auto& n : s)
+ for (const auto& n : s)
{
CHECK(n == 5);
}
@@ -1214,7 +1214,7 @@ SUITE(span_tests)
CHECK(it == beyond);
CHECK(it - beyond == 0);
- for (auto& n : s)
+ for (const auto& n : s)
{
CHECK(n == 5);
}
@@ -1386,16 +1386,16 @@ SUITE(span_tests)
int a[] = {1, 2, 3, 4};
{
- span s = a;
+ const span s = a;
CHECK(s.length() == 4);
- span bs = as_bytes(s);
+ const span bs = as_bytes(s);
CHECK(static_cast(bs.data()) == static_cast(s.data()));
CHECK(bs.length() == s.length_bytes());
}
{
span s;
- auto bs = as_bytes(s);
+ const auto bs = as_bytes(s);
CHECK(bs.length() == s.length());
CHECK(bs.length() == 0);
CHECK(bs.size_bytes() == 0);
@@ -1405,7 +1405,7 @@ SUITE(span_tests)
{
span s = a;
- auto bs = as_bytes(s);
+ const auto bs = as_bytes(s);
CHECK(static_cast(bs.data()) == static_cast(s.data()));
CHECK(bs.length() == s.length_bytes());
}
@@ -1428,7 +1428,7 @@ SUITE(span_tests)
{
span s;
- auto bs = as_writeable_bytes(s);
+ const auto bs = as_writeable_bytes(s);
CHECK(bs.length() == s.length());
CHECK(bs.length() == 0);
CHECK(bs.size_bytes() == 0);
@@ -1438,7 +1438,7 @@ SUITE(span_tests)
{
span s = a;
- auto bs = as_writeable_bytes(s);
+ const auto bs = as_writeable_bytes(s);
CHECK(static_cast(bs.data()) == static_cast(s.data()));
CHECK(bs.length() == s.length_bytes());
}
@@ -1484,11 +1484,11 @@ SUITE(span_tests)
// you can convert statically
{
- span s2 = {arr, 2};
+ const span s2 = {arr, 2};
static_cast(s2);
}
{
- span s1 = s4.first<1>();
+ const span s1 = s4.first<1>();
static_cast(s1);
}
@@ -1532,7 +1532,7 @@ SUITE(span_tests)
{
char lat[] = { '1', '2', '3', '4', '5', '6', 'E', 'F', 'G' };
span s = lat;
- auto f_it = s.begin() + 7;
+ const auto f_it = s.begin() + 7;
std::match_results::iterator> match;
diff --git a/tests/strided_span_tests.cpp b/tests/strided_span_tests.cpp
index 471f839..fe94449 100644
--- a/tests/strided_span_tests.cpp
+++ b/tests/strided_span_tests.cpp
@@ -29,529 +29,529 @@ using namespace gsl;
namespace
{
- struct BaseClass {};
- struct DerivedClass : BaseClass {};
+ struct BaseClass {};
+ struct DerivedClass : BaseClass {};
}
SUITE(strided_span_tests)
{
- TEST (span_section_test)
- {
- int a[30][4][5];
+ TEST (span_section_test)
+ {
+ int a[30][4][5];
- auto av = as_multi_span(a);
- auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2});
- auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1});
- (void)subsub;
- }
+ const auto av = as_multi_span(a);
+ const auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2});
+ const auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1});
+ (void)subsub;
+ }
- TEST(span_section)
- {
- std::vector data(5 * 10);
- std::iota(begin(data), end(data), 0);
+ TEST(span_section)
+ {
+ std::vector data(5 * 10);
+ std::iota(begin(data), end(data), 0);
const multi_span av = as_multi_span(multi_span{data}, dim<5>(), dim<10>());
- strided_span av_section_1 = av.section({ 1, 2 }, { 3, 4 });
- CHECK((av_section_1[{0, 0}] == 12));
- CHECK((av_section_1[{0, 1}] == 13));
- CHECK((av_section_1[{1, 0}] == 22));
- CHECK((av_section_1[{2, 3}] == 35));
+ const strided_span av_section_1 = av.section({ 1, 2 }, { 3, 4 });
+ CHECK((av_section_1[{0, 0}] == 12));
+ CHECK((av_section_1[{0, 1}] == 13));
+ CHECK((av_section_1[{1, 0}] == 22));
+ CHECK((av_section_1[{2, 3}] == 35));
- strided_span av_section_2 = av_section_1.section({ 1, 2 }, { 2,2 });
- CHECK((av_section_2[{0, 0}] == 24));
- CHECK((av_section_2[{0, 1}] == 25));
- CHECK((av_section_2[{1, 0}] == 34));
- }
+ const strided_span av_section_2 = av_section_1.section({ 1, 2 }, { 2,2 });
+ CHECK((av_section_2[{0, 0}] == 24));
+ CHECK((av_section_2[{0, 1}] == 25));
+ CHECK((av_section_2[{1, 0}] == 34));
+ }
- TEST(strided_span_constructors)
- {
- // Check stride constructor
- {
- int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- const int carr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ TEST(strided_span_constructors)
+ {
+ // Check stride constructor
+ {
+ int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ const int carr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- strided_span sav1{ arr, {{9}, {1}} }; // T -> T
- CHECK(sav1.bounds().index_bounds() == index<1>{ 9 });
- CHECK(sav1.bounds().stride() == 1);
- CHECK(sav1[0] == 1 && sav1[8] == 9);
+ strided_span sav1{ arr, {{9}, {1}} }; // T -> T
+ CHECK(sav1.bounds().index_bounds() == index<1>{ 9 });
+ CHECK(sav1.bounds().stride() == 1);
+ CHECK(sav1[0] == 1 && sav1[8] == 9);
- strided_span sav2{ carr, {{ 4 }, { 2 }} }; // const T -> const T
- CHECK(sav2.bounds().index_bounds() == index<1>{ 4 });
- CHECK(sav2.bounds().strides() == index<1>{2});
- CHECK(sav2[0] == 1 && sav2[3] == 7);
+ strided_span sav2{ carr, {{ 4 }, { 2 }} }; // const T -> const T
+ CHECK(sav2.bounds().index_bounds() == index<1>{ 4 });
+ CHECK(sav2.bounds().strides() == index<1>{2});
+ CHECK(sav2[0] == 1 && sav2[3] == 7);
- strided_span sav3{ arr, {{ 2, 2 },{ 6, 2 }} }; // T -> const T
- CHECK((sav3.bounds().index_bounds() == index<2>{ 2, 2 }));
- CHECK((sav3.bounds().strides() == index<2>{ 6, 2 }));
- CHECK((sav3[{0, 0}] == 1 && sav3[{0, 1}] == 3 && sav3[{1, 0}] == 7));
- }
+ strided_span sav3{ arr, {{ 2, 2 },{ 6, 2 }} }; // T -> const T
+ CHECK((sav3.bounds().index_bounds() == index<2>{ 2, 2 }));
+ CHECK((sav3.bounds().strides() == index<2>{ 6, 2 }));
+ CHECK((sav3[{0, 0}] == 1 && sav3[{0, 1}] == 3 && sav3[{1, 0}] == 7));
+ }
- // Check multi_span constructor
- {
- int arr[] = { 1, 2 };
+ // Check multi_span constructor
+ {
+ int arr[] = { 1, 2 };
- // From non-cv-qualified source
- {
- const multi_span src = arr;
+ // From non-cv-qualified source
+ {
+ const multi_span src = arr;
- strided_span sav{ src, {2, 1} };
- CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav.bounds().strides() == index<1>{ 1 });
- CHECK(sav[1] == 2);
+ strided_span sav{ src, {2, 1} };
+ CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav.bounds().strides() == index<1>{ 1 });
+ CHECK(sav[1] == 2);
#if _MSC_VER > 1800
- //strided_span sav_c{ {src}, {2, 1} };
- strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} };
+ //strided_span sav_c{ {src}, {2, 1} };
+ strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} };
#else
- strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} };
+ strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} };
#endif
- CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_c.bounds().strides() == index<1>{ 1 });
- CHECK(sav_c[1] == 2);
+ CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_c.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_c[1] == 2);
#if _MSC_VER > 1800
- strided_span sav_v{ src, {2, 1} };
+ strided_span sav_v{ src, {2, 1} };
#else
- strided_span sav_v{ multi_span{src}, strided_bounds<1>{2, 1} };
+ strided_span sav_v{ multi_span{src}, strided_bounds<1>{2, 1} };
#endif
- CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_v.bounds().strides() == index<1>{ 1 });
- CHECK(sav_v[1] == 2);
+ CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_v.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_v[1] == 2);
#if _MSC_VER > 1800
- strided_span sav_cv{ src, {2, 1} };
+ strided_span sav_cv{ src, {2, 1} };
#else
- strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
+ strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
#endif
- CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
- CHECK(sav_cv[1] == 2);
- }
+ CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_cv[1] == 2);
+ }
- // From const-qualified source
- {
- const multi_span src{ arr };
+ // From const-qualified source
+ {
+ const multi_span src{ arr };
- strided_span sav_c{ src, {2, 1} };
- CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_c.bounds().strides() == index<1>{ 1 });
- CHECK(sav_c[1] == 2);
+ strided_span sav_c{ src, {2, 1} };
+ CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_c.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_c[1] == 2);
#if _MSC_VER > 1800
- strided_span sav_cv{ src, {2, 1} };
+ strided_span sav_cv{ src, {2, 1} };
#else
- strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
+ strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
#endif
- CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
- CHECK(sav_cv[1] == 2);
- }
+ CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_cv[1] == 2);
+ }
- // From volatile-qualified source
- {
- const multi_span src{ arr };
+ // From volatile-qualified source
+ {
+ const multi_span src{ arr };
- strided_span sav_v{ src, {2, 1} };
- CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_v.bounds().strides() == index<1>{ 1 });
- CHECK(sav_v[1] == 2);
+ strided_span sav_v{ src, {2, 1} };
+ CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_v.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_v[1] == 2);
#if _MSC_VER > 1800
- strided_span sav_cv{ src, {2, 1} };
+ strided_span sav_cv{ src, {2, 1} };
#else
- strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
+ strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} };
#endif
- CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
- CHECK(sav_cv[1] == 2);
- }
+ CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_cv[1] == 2);
+ }
- // From cv-qualified source
- {
- const multi_span src{ arr };
+ // From cv-qualified source
+ {
+ const multi_span src{ arr };
- strided_span sav_cv{ src, {2, 1} };
- CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
- CHECK(sav_cv[1] == 2);
- }
- }
+ strided_span sav_cv{ src, {2, 1} };
+ CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav_cv.bounds().strides() == index<1>{ 1 });
+ CHECK(sav_cv[1] == 2);
+ }
+ }
- // Check const-casting constructor
- {
- int arr[2] = { 4, 5 };
+ // Check const-casting constructor
+ {
+ int arr[2] = { 4, 5 };
- const multi_span av(arr, 2);
- multi_span av2{ av };
- CHECK(av2[1] == 5);
+ const multi_span av(arr, 2);
+ multi_span av2{ av };
+ CHECK(av2[1] == 5);
- static_assert(std::is_convertible, multi_span>::value, "ctor is not implicit!");
+ static_assert(std::is_convertible, multi_span>::value, "ctor is not implicit!");
- const strided_span src{ arr, {2, 1} };
- strided_span sav{ src };
- CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav.bounds().stride() == 1);
- CHECK(sav[1] == 5);
+ const strided_span src{ arr, {2, 1} };
+ strided_span sav{ src };
+ CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav.bounds().stride() == 1);
+ CHECK(sav[1] == 5);
- static_assert(std::is_convertible, strided_span>::value, "ctor is not implicit!");
- }
+ static_assert(std::is_convertible, strided_span>::value, "ctor is not implicit!");
+ }
- // Check copy constructor
- {
- int arr1[2] = { 3, 4 };
- const strided_span src1{ arr1, {2, 1} };
- strided_span sav1{ src1 };
+ // Check copy constructor
+ {
+ int arr1[2] = { 3, 4 };
+ const strided_span src1{ arr1, {2, 1} };
+ strided_span sav1{ src1 };
- CHECK(sav1.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav1.bounds().stride() == 1);
- CHECK(sav1[0] == 3);
+ CHECK(sav1.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav1.bounds().stride() == 1);
+ CHECK(sav1[0] == 3);
- int arr2[6] = { 1, 2, 3, 4, 5, 6 };
- const strided_span src2{ arr2, {{ 3, 2 }, { 2, 1 }} };
- strided_span sav2{ src2 };
- CHECK((sav2.bounds().index_bounds() == index<2>{ 3, 2 }));
- CHECK((sav2.bounds().strides() == index<2>{ 2, 1 }));
- CHECK((sav2[{0, 0}] == 1 && sav2[{2, 0}] == 5));
- }
+ int arr2[6] = { 1, 2, 3, 4, 5, 6 };
+ const strided_span src2{ arr2, {{ 3, 2 }, { 2, 1 }} };
+ strided_span sav2{ src2 };
+ CHECK((sav2.bounds().index_bounds() == index<2>{ 3, 2 }));
+ CHECK((sav2.bounds().strides() == index<2>{ 2, 1 }));
+ CHECK((sav2[{0, 0}] == 1 && sav2[{2, 0}] == 5));
+ }
- // Check const-casting assignment operator
- {
- int arr1[2] = { 1, 2 };
- int arr2[6] = { 3, 4, 5, 6, 7, 8 };
+ // Check const-casting assignment operator
+ {
+ int arr1[2] = { 1, 2 };
+ int arr2[6] = { 3, 4, 5, 6, 7, 8 };
- const strided_span src{ arr1, {{2}, {1}} };
- strided_span sav{ arr2, {{3}, {2}} };
- strided_span& sav_ref = (sav = src);
- CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav.bounds().strides() == index<1>{ 1 });
- CHECK(sav[0] == 1);
- CHECK(&sav_ref == &sav);
- }
+ const strided_span src{ arr1, {{2}, {1}} };
+ strided_span sav{ arr2, {{3}, {2}} };
+ strided_span& sav_ref = (sav = src);
+ CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav.bounds().strides() == index<1>{ 1 });
+ CHECK(sav[0] == 1);
+ CHECK(&sav_ref == &sav);
+ }
- // Check copy assignment operator
- {
- int arr1[2] = { 3, 4 };
- int arr1b[1] = { 0 };
- const strided_span src1{ arr1, {2, 1} };
- strided_span sav1{ arr1b, {1, 1} };
- strided_span& sav1_ref = (sav1 = src1);
- CHECK(sav1.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav1.bounds().strides() == index<1>{ 1 });
- CHECK(sav1[0] == 3);
- CHECK(&sav1_ref == &sav1);
+ // Check copy assignment operator
+ {
+ int arr1[2] = { 3, 4 };
+ int arr1b[1] = { 0 };
+ const strided_span src1{ arr1, {2, 1} };
+ strided_span sav1{ arr1b, {1, 1} };
+ strided_span& sav1_ref = (sav1 = src1);
+ CHECK(sav1.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav1.bounds().strides() == index<1>{ 1 });
+ CHECK(sav1[0] == 3);
+ CHECK(&sav1_ref == &sav1);
- const int arr2[6] = { 1, 2, 3, 4, 5, 6 };
- const int arr2b[1] = { 0 };
- const strided_span src2{ arr2, {{ 3, 2 },{ 2, 1 }} };
- strided_span sav2{ arr2b, {{ 1, 1 },{ 1, 1 }} };
- strided_span& sav2_ref = (sav2 = src2);
- CHECK((sav2.bounds().index_bounds() == index<2>{ 3, 2 }));
- CHECK((sav2.bounds().strides() == index<2>{ 2, 1 }));
- CHECK((sav2[{0, 0}] == 1 && sav2[{2, 0}] == 5));
- CHECK(&sav2_ref == &sav2);
- }
- }
+ const int arr2[6] = { 1, 2, 3, 4, 5, 6 };
+ const int arr2b[1] = { 0 };
+ const strided_span src2{ arr2, {{ 3, 2 },{ 2, 1 }} };
+ strided_span sav2{ arr2b, {{ 1, 1 },{ 1, 1 }} };
+ strided_span& sav2_ref = (sav2 = src2);
+ CHECK((sav2.bounds().index_bounds() == index<2>{ 3, 2 }));
+ CHECK((sav2.bounds().strides() == index<2>{ 2, 1 }));
+ CHECK((sav2[{0, 0}] == 1 && sav2[{2, 0}] == 5));
+ CHECK(&sav2_ref == &sav2);
+ }
+ }
- TEST(strided_span_slice)
- {
- std::vector data(5 * 10);
- std::iota(begin(data), end(data), 0);
+ TEST(strided_span_slice)
+ {
+ std::vector data(5 * 10);
+ std::iota(begin(data), end(data), 0);
const multi_span src = as_multi_span(multi_span{data}, dim<5>(), dim<10>());
- const strided_span sav{ src, {{5, 10}, {10, 1}} };
+ const strided_span sav{ src, {{5, 10}, {10, 1}} };
#ifdef CONFIRM_COMPILATION_ERRORS
- const strided_span csav{ {src},{ { 5, 10 },{ 10, 1 } } };
+ const strided_span csav{ {src},{ { 5, 10 },{ 10, 1 } } };
#endif
- const strided_span csav{ multi_span{ src }, { { 5, 10 },{ 10, 1 } } };
+ const strided_span csav{ multi_span{ src }, { { 5, 10 },{ 10, 1 } } };
- strided_span sav_sl = sav[2];
- CHECK(sav_sl[0] == 20);
- CHECK(sav_sl[9] == 29);
+ strided_span sav_sl = sav[2];
+ CHECK(sav_sl[0] == 20);
+ CHECK(sav_sl[9] == 29);
- strided_span csav_sl = sav[3];
- CHECK(csav_sl[0] == 30);
- CHECK(csav_sl[9] == 39);
+ strided_span csav_sl = sav[3];
+ CHECK(csav_sl[0] == 30);
+ CHECK(csav_sl[9] == 39);
- CHECK(sav[4][0] == 40);
- CHECK(sav[4][9] == 49);
- }
+ CHECK(sav[4][0] == 40);
+ CHECK(sav[4][9] == 49);
+ }
- TEST(strided_span_column_major)
- {
- // strided_span may be used to accomodate more peculiar
- // use cases, such as column-major multidimensional array
- // (aka. "FORTRAN" layout).
+ TEST(strided_span_column_major)
+ {
+ // strided_span may be used to accomodate more peculiar
+ // use cases, such as column-major multidimensional array
+ // (aka. "FORTRAN" layout).
- int cm_array[3 * 5] = {
- 1, 4, 7, 10, 13,
- 2, 5, 8, 11, 14,
- 3, 6, 9, 12, 15
- };
- strided_span cm_sav{ cm_array, {{ 5, 3 },{ 1, 5 }} };
+ int cm_array[3 * 5] = {
+ 1, 4, 7, 10, 13,
+ 2, 5, 8, 11, 14,
+ 3, 6, 9, 12, 15
+ };
+ strided_span cm_sav{ cm_array, {{ 5, 3 },{ 1, 5 }} };
- // Accessing elements
- CHECK((cm_sav[{0, 0}] == 1));
- CHECK((cm_sav[{0, 1}] == 2));
- CHECK((cm_sav[{1, 0}] == 4));
- CHECK((cm_sav[{4, 2}] == 15));
+ // Accessing elements
+ CHECK((cm_sav[{0, 0}] == 1));
+ CHECK((cm_sav[{0, 1}] == 2));
+ CHECK((cm_sav[{1, 0}] == 4));
+ CHECK((cm_sav[{4, 2}] == 15));
- // Slice
- strided_span cm_sl = cm_sav[3];
+ // Slice
+ strided_span cm_sl = cm_sav[3];
- CHECK(cm_sl[0] == 10);
- CHECK(cm_sl[1] == 11);
- CHECK(cm_sl[2] == 12);
+ CHECK(cm_sl[0] == 10);
+ CHECK(cm_sl[1] == 11);
+ CHECK(cm_sl[2] == 12);
- // Section
- strided_span cm_sec = cm_sav.section( { 2, 1 }, { 3, 2 });
+ // Section
+ strided_span cm_sec = cm_sav.section( { 2, 1 }, { 3, 2 });
- CHECK((cm_sec.bounds().index_bounds() == index<2>{3, 2}));
- CHECK((cm_sec[{0, 0}] == 8));
- CHECK((cm_sec[{0, 1}] == 9));
- CHECK((cm_sec[{1, 0}] == 11));
- CHECK((cm_sec[{2, 1}] == 15));
- }
+ CHECK((cm_sec.bounds().index_bounds() == index<2>{3, 2}));
+ CHECK((cm_sec[{0, 0}] == 8));
+ CHECK((cm_sec[{0, 1}] == 9));
+ CHECK((cm_sec[{1, 0}] == 11));
+ CHECK((cm_sec[{2, 1}] == 15));
+ }
- TEST(strided_span_bounds)
- {
- int arr[] = { 0, 1, 2, 3 };
- multi_span av(arr);
+ TEST(strided_span_bounds)
+ {
+ int arr[] = { 0, 1, 2, 3 };
+ multi_span av(arr);
- {
- // incorrect sections
+ {
+ // incorrect sections
- CHECK_THROW(av.section(0, 0)[0], fail_fast);
- CHECK_THROW(av.section(1, 0)[0], fail_fast);
- CHECK_THROW(av.section(1, 1)[1], fail_fast);
+ CHECK_THROW(av.section(0, 0)[0], fail_fast);
+ CHECK_THROW(av.section(1, 0)[0], fail_fast);
+ CHECK_THROW(av.section(1, 1)[1], fail_fast);
- CHECK_THROW(av.section(2, 5), fail_fast);
- CHECK_THROW(av.section(5, 2), fail_fast);
- CHECK_THROW(av.section(5, 0), fail_fast);
- CHECK_THROW(av.section(0, 5), fail_fast);
- CHECK_THROW(av.section(5, 5), fail_fast);
- }
+ CHECK_THROW(av.section(2, 5), fail_fast);
+ CHECK_THROW(av.section(5, 2), fail_fast);
+ CHECK_THROW(av.section(5, 0), fail_fast);
+ CHECK_THROW(av.section(0, 5), fail_fast);
+ CHECK_THROW(av.section(5, 5), fail_fast);
+ }
- {
- // zero stride
- strided_span sav{ av,{ { 4 },{} } };
- CHECK(sav[0] == 0);
- CHECK(sav[3] == 0);
- CHECK_THROW(sav[4], fail_fast);
- }
+ {
+ // zero stride
+ strided_span sav{ av,{ { 4 },{} } };
+ CHECK(sav[0] == 0);
+ CHECK(sav[3] == 0);
+ CHECK_THROW(sav[4], fail_fast);
+ }
- {
- // zero extent
- strided_span sav{ av,{ {},{ 1 } } };
- CHECK_THROW(sav[0], fail_fast);
- }
+ {
+ // zero extent
+ strided_span sav{ av,{ {},{ 1 } } };
+ CHECK_THROW(sav[0], fail_fast);
+ }
- {
- // zero extent and stride
- strided_span sav{ av,{ {},{} } };
- CHECK_THROW(sav[0], fail_fast);
- }
+ {
+ // zero extent and stride
+ strided_span sav{ av,{ {},{} } };
+ CHECK_THROW(sav[0], fail_fast);
+ }
- {
- // strided array ctor with matching strided bounds
- strided_span sav{ arr,{ 4, 1 } };
- CHECK(sav.bounds().index_bounds() == index<1>{ 4 });
- CHECK(sav[3] == 3);
- CHECK_THROW(sav[4], fail_fast);
- }
+ {
+ // strided array ctor with matching strided bounds
+ strided_span sav{ arr,{ 4, 1 } };
+ CHECK(sav.bounds().index_bounds() == index<1>{ 4 });
+ CHECK(sav[3] == 3);
+ CHECK_THROW(sav[4], fail_fast);
+ }
- {
- // strided array ctor with smaller strided bounds
- strided_span sav{ arr,{ 2, 1 } };
- CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav[1] == 1);
- CHECK_THROW(sav[2], fail_fast);
- }
+ {
+ // strided array ctor with smaller strided bounds
+ strided_span sav{ arr,{ 2, 1 } };
+ CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav[1] == 1);
+ CHECK_THROW(sav[2], fail_fast);
+ }
- {
- // strided array ctor with fitting irregular bounds
- strided_span sav{ arr,{ 2, 3 } };
- CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
- CHECK(sav[0] == 0);
- CHECK(sav[1] == 3);
- CHECK_THROW(sav[2], fail_fast);
- }
+ {
+ // strided array ctor with fitting irregular bounds
+ strided_span sav{ arr,{ 2, 3 } };
+ CHECK(sav.bounds().index_bounds() == index<1>{ 2 });
+ CHECK(sav[0] == 0);
+ CHECK(sav[1] == 3);
+ CHECK_THROW(sav[2], fail_fast);
+ }
- {
- // bounds cross data boundaries - from static arrays
- CHECK_THROW((strided_span { arr, { 3, 2 } }), fail_fast);
- CHECK_THROW((strided_span { arr, { 3, 3 } }), fail_fast);
- CHECK_THROW((strided_span { arr, { 4, 5 } }), fail_fast);
- CHECK_THROW((strided_span { arr, { 5, 1 } }), fail_fast);
- CHECK_THROW((strided_span { arr, { 5, 5 } }), fail_fast);
- }
+ {
+ // bounds cross data boundaries - from static arrays
+ CHECK_THROW((strided_span { arr, { 3, 2 } }), fail_fast);
+ CHECK_THROW((strided_span { arr, { 3, 3 } }), fail_fast);
+ CHECK_THROW((strided_span { arr, { 4, 5 } }), fail_fast);
+ CHECK_THROW((strided_span { arr, { 5, 1 } }), fail_fast);
+ CHECK_THROW((strided_span { arr, { 5, 5 } }), fail_fast);
+ }
- {
- // bounds cross data boundaries - from array view
- CHECK_THROW((strided_span { av, { 3, 2 } }), fail_fast);
- CHECK_THROW((strided_span { av, { 3, 3 } }), fail_fast);
- CHECK_THROW((strided_span { av, { 4, 5 } }), fail_fast);
- CHECK_THROW((strided_span { av, { 5, 1 } }), fail_fast);
- CHECK_THROW((strided_span { av, { 5, 5 } }), fail_fast);
- }
+ {
+ // bounds cross data boundaries - from array view
+ CHECK_THROW((strided_span { av, { 3, 2 } }), fail_fast);
+ CHECK_THROW((strided_span { av, { 3, 3 } }), fail_fast);
+ CHECK_THROW((strided_span { av, { 4, 5 } }), fail_fast);
+ CHECK_THROW((strided_span { av, { 5, 1 } }), fail_fast);
+ CHECK_THROW((strided_span { av, { 5, 5 } }), fail_fast);
+ }
- {
- // bounds cross data boundaries - from dynamic arrays
- CHECK_THROW((strided_span { av.data(), 4, { 3, 2 } }), fail_fast);
- CHECK_THROW((strided_span { av.data(), 4, { 3, 3 } }), fail_fast);
- CHECK_THROW((strided_span { av.data(), 4, { 4, 5 } }), fail_fast);
- CHECK_THROW((strided_span { av.data(), 4, { 5, 1 } }), fail_fast);
- CHECK_THROW((strided_span { av.data(), 4, { 5, 5 } }), fail_fast);
- CHECK_THROW((strided_span { av.data(), 2, { 2, 2 } }), fail_fast);
- }
+ {
+ // bounds cross data boundaries - from dynamic arrays
+ CHECK_THROW((strided_span { av.data(), 4, { 3, 2 } }), fail_fast);
+ CHECK_THROW((strided_span { av.data(), 4, { 3, 3 } }), fail_fast);
+ CHECK_THROW((strided_span { av.data(), 4, { 4, 5 } }), fail_fast);
+ CHECK_THROW((strided_span { av.data(), 4, { 5, 1 } }), fail_fast);
+ CHECK_THROW((strided_span { av.data(), 4, { 5, 5 } }), fail_fast);
+ CHECK_THROW((strided_span { av.data(), 2, { 2, 2 } }), fail_fast);
+ }
#ifdef CONFIRM_COMPILATION_ERRORS
- {
- strided_span sav0{ av.data(), { 3, 2 } };
- strided_span sav1{ arr, { 1 } };
- strided_span sav2{ arr, { 1,1,1 } };
- strided_span sav3{ av, { 1 } };
- strided_span sav4{ av, { 1,1,1 } };
- strided_span sav5{ av.as_multi_span(dim<2>(), dim<2>()), { 1 } };
- strided_span sav6{ av.as_multi_span(dim<2>(), dim<2>()), { 1,1,1 } };
- strided_span sav7{ av.as_multi_span(dim<2>(), dim<2>()), { { 1,1 },{ 1,1 },{ 1,1 } } };
+ {
+ strided_span sav0{ av.data(), { 3, 2 } };
+ strided_span sav1{ arr, { 1 } };
+ strided_span sav2{ arr, { 1,1,1 } };
+ strided_span sav3{ av, { 1 } };
+ strided_span sav4{ av, { 1,1,1 } };
+ strided_span sav5{ av.as_multi_span(dim<2>(), dim<2>()), { 1 } };
+ strided_span sav6{ av.as_multi_span(dim<2>(), dim<2>()), { 1,1,1 } };
+ strided_span sav7{ av.as_multi_span(dim<2>(), dim<2>()), { { 1,1 },{ 1,1 },{ 1,1 } } };
- index<1> index{ 0, 1 };
- strided_span sav8{ arr,{ 1,{ 1,1 } } };
- strided_span sav9{ arr,{ { 1,1 },{ 1,1 } } };
- strided_span sav10{ av,{ 1,{ 1,1 } } };
- strided_span sav11{ av,{ { 1,1 },{ 1,1 } } };
- strided_span sav12{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1 } } };
- strided_span sav13{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1,1,1 } } };
- strided_span sav14{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1,1,1 },{ 1 } } };
- }
+ index<1> index{ 0, 1 };
+ strided_span sav8{ arr,{ 1,{ 1,1 } } };
+ strided_span sav9{ arr,{ { 1,1 },{ 1,1 } } };
+ strided_span sav10{ av,{ 1,{ 1,1 } } };
+ strided_span sav11{ av,{ { 1,1 },{ 1,1 } } };
+ strided_span sav12{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1 } } };
+ strided_span sav13{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1,1,1 } } };
+ strided_span sav14{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1,1,1 },{ 1 } } };
+ }
#endif
- }
+ }
- TEST(strided_span_type_conversion)
- {
- int arr[] = { 0, 1, 2, 3 };
- multi_span av(arr);
+ TEST(strided_span_type_conversion)
+ {
+ int arr[] = { 0, 1, 2, 3 };
+ multi_span av(arr);
- {
- strided_span sav{ av.data(), av.size(), { av.size() / 2, 2 } };
+ {
+ strided_span sav{ av.data(), av.size(), { av.size() / 2, 2 } };
#ifdef CONFIRM_COMPILATION_ERRORS
- strided_span lsav1 = sav.as_strided_span();
+ strided_span lsav1 = sav.as_strided_span();
#endif
- }
- {
- strided_span sav{ av, { av.size() / 2, 2 } };
+ }
+ {
+ strided_span