From ef6cc65053c804738840007cba2f0448ae52656f Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 21:26:17 +0000 Subject: [PATCH 1/6] Fixed compilation issues with Clang and GCC on Linux. --- include/array_view.h | 33 +++-- include/fail_fast.h | 11 +- tests/array_view_tests.cpp | 274 ++++++++++++++++--------------------- 3 files changed, 141 insertions(+), 177 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index 6af4d8d..097d20a 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -290,7 +290,8 @@ public: } _CONSTEXPR static index shift_left(const index& other) _NOEXCEPT { - return (value_type(&)[rank])other.elems[1]; + value_type (&arr)[rank] = (value_type(&)[rank])(*(other.elems + 1)); + return index(arr); } using Base::operator[]; @@ -1647,7 +1648,8 @@ public: using typename Base::index_type; using typename Base::iterator; using typename Base::const_iterator; - using Base::rank; + using typename Base::reference; + using Base::rank; public: // basic @@ -1848,14 +1850,16 @@ public: // section _CONSTEXPR strided_array_view section(index_type origin, index_type extents) const { - size_type size = bounds().total_size() - bounds().linearize(origin); + size_type size = this->bounds().total_size() - this->bounds().linearize(origin); return{ &this->operator[](origin), size, strided_bounds {extents, details::make_stride(Base::bounds())} }; } - _CONSTEXPR reference operator[](const index_type& idx) const + + _CONSTEXPR reference operator[](const index_type& idx) const { return Base::operator[](idx); } - template 1), typename Dummy = std::enable_if_t> + + template 1), typename Dummy = std::enable_if_t> _CONSTEXPR array_view operator[](size_type idx) const { auto ret = Base::operator[](idx); @@ -1936,6 +1940,7 @@ public: using typename Base::index_type; using typename Base::iterator; using typename Base::const_iterator; + using typename Base::reference; // from static array of size N template @@ -1968,26 +1973,26 @@ public: } // convert from bytes - template ::value>> - strided_array_view as_strided_array_view() const + template + strided_array_view::value, OtherValueType>::type, rank> as_strided_array_view() const { static_assert((sizeof(OtherValueType) >= sizeof(value_type)) && (sizeof(OtherValueType) % sizeof(value_type) == 0), "OtherValueType should have a size to contain a multiple of ValueTypes"); auto d = sizeof(OtherValueType) / sizeof(value_type); - size_type size = bounds().total_size() / d; - return{ (OtherValueType*)data(), size, bounds_type{ resize_extent(bounds().index_bounds(), d), resize_stride(bounds().strides(), d)} }; + size_type size = this->bounds().total_size() / d; + return{ (OtherValueType*)this->data(), size, bounds_type{ resize_extent(this->bounds().index_bounds(), d), resize_stride(this->bounds().strides(), d)} }; } strided_array_view section(index_type origin, index_type extents) const { - size_type size = bounds().total_size() - bounds().linearize(origin); + size_type size = this->bounds().total_size() - this->bounds().linearize(origin); return { &this->operator[](origin), size, bounds_type {extents, details::make_stride(Base::bounds())}}; } _CONSTEXPR reference operator[](const index_type& idx) const - { - return Base::operator[](idx); - } + { + return Base::operator[](idx); + } template 1), typename Dummy = std::enable_if_t> _CONSTEXPR strided_array_view operator[](size_type idx) const @@ -2048,7 +2053,7 @@ private: const ArrayView * m_validator; void validateThis() const { - fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size(), "iterator is out of range of the array"); + fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size()); } contiguous_array_view_iterator (const ArrayView *container, bool isbegin = false) : m_pdata(isbegin ? container->m_pdata : container->m_pdata + container->size()), m_validator(container) { } diff --git a/include/fail_fast.h b/include/fail_fast.h index ff5dbc4..a7385ca 100644 --- a/include/fail_fast.h +++ b/include/fail_fast.h @@ -27,13 +27,10 @@ namespace Guide // #if defined(SAFER_CPP_TESTING) -struct fail_fast : public std::exception +struct fail_fast : public std::runtime_error { - fail_fast() = default; - - explicit fail_fast(char const* const message) : - std::exception(message) - {} + fail_fast() : std::runtime_error("") {} + explicit fail_fast(char const* const message) : std::runtime_error(message) {} }; inline void fail_fast_assert(bool cond) { if (!cond) throw fail_fast(); } @@ -46,4 +43,4 @@ inline void fail_fast_assert(bool cond, const char* const message) { if (!cond) #endif // SAFER_CPP_TESTING -} \ No newline at end of file +} diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 6b35ab9..60f26d4 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -100,7 +100,7 @@ SUITE(array_view_tests) // out of bounds CHECK_THROW(av[1][3] = 3, fail_fast); - CHECK_THROW((av[index<2>{1, 3}] = 3), fail_fast); + CHECK_THROW((av[{1, 3}] = 3), fail_fast); CHECK_THROW(av[10][2], fail_fast); CHECK_THROW((av[{10,2}]), fail_fast); @@ -621,14 +621,18 @@ SUITE(array_view_tests) // stride initializer list size should match the rank of the array CHECK_THROW((index<1>{ 0,1 }), fail_fast); CHECK_THROW((strided_array_view{ arr, {1, {1,1}} }), fail_fast); +#ifdef _MSC_VER CHECK_THROW((strided_array_view{ arr, {{1,1 }, {1,1}} }), fail_fast); - +#endif CHECK_THROW((strided_array_view{ av, {1, {1,1}} }), fail_fast); +#ifdef _MSC_VER CHECK_THROW((strided_array_view{ av, {{1,1 }, {1,1}} }), fail_fast); - +#endif CHECK_THROW((strided_array_view{ av.as_array_view(dim<2>(), dim<2>()), {{1}, {1}} }), fail_fast); CHECK_THROW((strided_array_view{ av.as_array_view(dim<2>(), dim<2>()), {{1}, {1,1,1}} }), fail_fast); +#ifdef _MSC_VER CHECK_THROW((strided_array_view{ av.as_array_view(dim<2>(), dim<2>()), {{1,1,1}, {1}} }), fail_fast); +#endif } } @@ -726,69 +730,27 @@ SUITE(array_view_tests) TEST(empty_arrays) { #ifdef CONFIRM_COMPILATION_ERRORS - { - array_view empty; - strided_array_view empty2; - strided_array_view empty3{ nullptr,{ 0, 1 } }; - } + { + array_view empty; + strided_array_view empty2; + strided_array_view empty3{ nullptr,{ 0, 1 } }; + } #endif - { - array_view empty_av(nullptr); + array_view empty_av(nullptr); - CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_av[0], fail_fast); - CHECK_THROW(empty_av.begin()[0], fail_fast); - CHECK_THROW(empty_av.cbegin()[0], fail_fast); + CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_av[0], fail_fast); - for (auto& v : empty_av) - { - CHECK(false); - } - } + strided_array_view empty_sav{ empty_av, { 0, 1 } }; - { - array_view empty_av = {}; + CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_sav[0], fail_fast); - CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_av[0], fail_fast); - CHECK_THROW(empty_av.begin()[0], fail_fast); - CHECK_THROW(empty_av.cbegin()[0], fail_fast); + strided_array_view empty_sav2{ nullptr, 0, { 0, 1 } }; - for (auto& v : empty_av) - { - CHECK(false); - } - } - - { - array_view empty_av(nullptr); - strided_array_view empty_sav{ empty_av, { 0, 1 } }; - - CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_sav[0], fail_fast); - CHECK_THROW(empty_sav.begin()[0], fail_fast); - CHECK_THROW(empty_sav.cbegin()[0], fail_fast); - - for (auto& v : empty_sav) - { - CHECK(false); - } - } - - { - strided_array_view empty_sav{ nullptr, 0, { 0, 1 } }; - - CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_sav[0], fail_fast); - CHECK_THROW(empty_sav.begin()[0], fail_fast); - CHECK_THROW(empty_sav.cbegin()[0], fail_fast); - - for (auto& v : empty_sav) - { - CHECK(false); - } - } + CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_sav[0], fail_fast); } TEST(index_constructor) @@ -803,13 +765,13 @@ SUITE(array_view_tests) array_view av(arr, 8); size_t a[1] = { 0 }; - index<1> i = index<1>(a); + index<1> i = a; CHECK(av[i] == 4); auto av2 = av.as_array_view(dim<4>(), dim<>(2)); size_t a2[2] = { 0, 1 }; - index<2> i2 = index<2>(a2); + index<2> i2 = a2; CHECK(av2[i2] == 0); CHECK(av2[0][i] == 4); @@ -890,7 +852,7 @@ SUITE(array_view_tests) } } - unsigned int idx = 0; + size_t idx = 0; for (auto num : section) { CHECK(num == av[idx][1]); @@ -1498,114 +1460,114 @@ SUITE(array_view_tests) TEST(ArrayViewComparison) { - { - int arr[10][2]; - auto av1 = as_array_view(arr); - array_view av2 = av1; + { + int arr[10][2]; + auto av1 = as_array_view(arr); + array_view av2 = av1; - CHECK(av1 == av2); + CHECK(av1 == av2); - array_view, 20> av3 = av1.as_array_view(dim<>(20)); - CHECK(av3 == av2 && av3 == av1); - } + array_view, 20> av3 = av1.as_array_view(dim<>(20)); + CHECK(av3 == av2 && av3 == av1); + } - { - auto av1 = nullptr; - auto av2 = nullptr; - CHECK(av1 == av2); - CHECK(!(av1 != av2)); - CHECK(!(av1 < av2)); - CHECK(av1 <= av2); - CHECK(!(av1 > av2)); - CHECK(av1 >= av2); - CHECK(av2 == av1); - CHECK(!(av2 != av1)); - CHECK(!(av2 < av1)); - CHECK(av2 <= av1); - CHECK(!(av2 > av1)); - CHECK(av2 >= av1); - } + { + auto av1 = nullptr; + auto av2 = nullptr; + CHECK(av1 == av2); + CHECK(!(av1 != av2)); + CHECK(!(av1 < av2)); + CHECK(av1 <= av2); + CHECK(!(av1 > av2)); + CHECK(av1 >= av2); + CHECK(av2 == av1); + CHECK(!(av2 != av1)); + CHECK(!(av2 < av1)); + CHECK(av2 <= av1); + CHECK(!(av2 > av1)); + CHECK(av2 >= av1); + } - { - int arr[] = { 2, 1 }; // bigger + { + int arr[] = { 2, 1 }; // bigger - array_view av1 = nullptr; - array_view av2 = arr; + array_view av1 = nullptr; + array_view av2 = arr; - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } - { - int arr1[] = { 1, 2 }; - int arr2[] = { 1, 2 }; - array_view av1 = arr1; - array_view av2 = arr2; + { + int arr1[] = { 1, 2 }; + int arr2[] = { 1, 2 }; + array_view av1 = arr1; + array_view av2 = arr2; - CHECK(av1 == av2); - CHECK(!(av1 != av2)); - CHECK(!(av1 < av2)); - CHECK(av1 <= av2); - CHECK(!(av1 > av2)); - CHECK(av1 >= av2); - CHECK(av2 == av1); - CHECK(!(av2 != av1)); - CHECK(!(av2 < av1)); - CHECK(av2 <= av1); - CHECK(!(av2 > av1)); - CHECK(av2 >= av1); - } + CHECK(av1 == av2); + CHECK(!(av1 != av2)); + CHECK(!(av1 < av2)); + CHECK(av1 <= av2); + CHECK(!(av1 > av2)); + CHECK(av1 >= av2); + CHECK(av2 == av1); + CHECK(!(av2 != av1)); + CHECK(!(av2 < av1)); + CHECK(av2 <= av1); + CHECK(!(av2 > av1)); + CHECK(av2 >= av1); + } - { - int arr[] = { 1, 2, 3 }; + { + int arr[] = { 1, 2, 3 }; - array_view av1 = { &arr[0], 2 }; // shorter - array_view av2 = arr; // longer + array_view av1 = { &arr[0], 2 }; // shorter + array_view av2 = arr; // longer - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } - { - int arr1[] = { 1, 2 }; // smaller - int arr2[] = { 2, 1 }; // bigger + { + int arr1[] = { 1, 2 }; // smaller + int arr2[] = { 2, 1 }; // bigger - array_view av1 = arr1; - array_view av2 = arr2; + array_view av1 = arr1; + array_view av2 = arr2; - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } } } From 9a297120227979ad8fa53525178f8edf806634de Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 15:11:07 -0700 Subject: [PATCH 2/6] Ensuring compilation works for VS 2013. --- include/array_view.h | 10 ++++++++++ tests/array_view_tests.cpp | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index 097d20a..9c58ab2 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -52,6 +52,11 @@ #endif // _NOEXCEPT +#if _MSC_VER <= 1800 +#pragma warning(push) +#pragma warning(disable: 4351) // warns about newly introduced aggregate initializer behavior +#endif // _MSC_VER <= 1800 + namespace Guide { /* @@ -2275,4 +2280,9 @@ general_array_view_iterator operator+(typename general_array_view_ite } // namespace Guide +#if _MSC_VER <= 1800 +#pragma warning(pop) +#endif // _MSC_VER <= 1800 + + #pragma pop_macro("_NOEXCEPT") diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 60f26d4..ec1d31d 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -320,17 +320,29 @@ SUITE(array_view_tests) CHECK(sav.bounds().strides() == index<1>{ 1 }); CHECK(sav[1] == 2); - strided_array_view sav_c{ {src}, {2, 1} }; +#if _MSC_VER > 1800 + strided_array_view sav_c{ array_view{src}, strided_bounds<1>{2, 1} }; +#else + strided_array_view sav_c{ array_view{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); +#if _MSC_VER > 1800 strided_array_view sav_v{ {src}, {2, 1} }; +#else + strided_array_view sav_v{ array_view{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); +#if _MSC_VER > 1800 strided_array_view sav_cv{ {src}, {2, 1} }; +#else + strided_array_view sav_cv{ array_view{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); @@ -345,7 +357,12 @@ SUITE(array_view_tests) CHECK(sav_c.bounds().strides() == index<1>{ 1 }); CHECK(sav_c[1] == 2); +#if _MSC_VER > 1800 strided_array_view sav_cv{ {src}, {2, 1} }; +#else + strided_array_view sav_cv{ array_view{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); @@ -360,7 +377,11 @@ SUITE(array_view_tests) CHECK(sav_v.bounds().strides() == index<1>{ 1 }); CHECK(sav_v[1] == 2); +#if _MSC_VER > 1800 strided_array_view sav_cv{ {src}, {2, 1} }; +#else + strided_array_view sav_cv{ array_view{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); @@ -839,7 +860,8 @@ SUITE(array_view_tests) for (unsigned int i = 0; i < section.size(); ++i) { - CHECK(section[index<2>({ i,0 })] == av[i][1]); + auto idx = index<2>{ i,0 }; // avoid braces inside the CHECK macro + CHECK(section[idx] == av[i][1]); } CHECK(section.bounds().index_bounds()[0] == length); @@ -848,7 +870,8 @@ SUITE(array_view_tests) { for (unsigned int j = 0; j < section.bounds().index_bounds()[1]; ++j) { - CHECK(section[index<2>({ i,j })] == av[i][1]); + auto idx = index<2>{ i,j }; // avoid braces inside the CHECK macro + CHECK(section[idx] == av[i][1]); } } @@ -923,7 +946,11 @@ SUITE(array_view_tests) // pick every other element auto length = av.size() / 2; +#if _MSC_VER > 1800 auto bounds = strided_bounds<1>({ length }, { 2 }); +#else + auto bounds = strided_bounds<1>(index<1>{ length }, index<1>{ 2 }); +#endif strided_array_view strided(&av.data()[1], av.size() - 1, bounds); CHECK(strided.size() == length); @@ -982,7 +1009,10 @@ SUITE(array_view_tests) { for (unsigned int j = 0; j < section.extent<1>(); ++j) for (unsigned int k = 0; k < section.extent<2>(); ++k) - CHECK(section[index<3>({ i,j,k })] == expected[2 * i + 2 * j + k]); + { + auto idx = index<3>{ i,j,k }; // avoid braces in the CHECK macro + CHECK(section[idx] == expected[2 * i + 2 * j + k]); + } } for (unsigned int i = 0; i < section.extent<0>(); ++i) From 383dc507a4b9385d24218fed70a4fd0be74df4a0 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 15:41:40 -0700 Subject: [PATCH 3/6] Fixes for review feedback. --- include/array_view.h | 4 ++-- tests/array_view_tests.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index 9c58ab2..ddf6677 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -1654,7 +1654,7 @@ public: using typename Base::iterator; using typename Base::const_iterator; using typename Base::reference; - using Base::rank; + using Base::rank; public: // basic @@ -2058,7 +2058,7 @@ private: const ArrayView * m_validator; void validateThis() const { - fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size()); + fail_fast_assert(m_pdata >= m_validator->m_pdata && m_pdata < m_validator->m_pdata + m_validator->size(), "iterator is out of range of the array"); } contiguous_array_view_iterator (const ArrayView *container, bool isbegin = false) : m_pdata(isbegin ? container->m_pdata : container->m_pdata + container->size()), m_validator(container) { } diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index ec1d31d..12344d9 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -321,9 +321,9 @@ SUITE(array_view_tests) CHECK(sav[1] == 2); #if _MSC_VER > 1800 - strided_array_view sav_c{ array_view{src}, strided_bounds<1>{2, 1} }; + strided_array_view sav_c{ {src}, {2, 1} }; #else - strided_array_view sav_c{ array_view{src}, strided_bounds<1>{2, 1} }; + strided_array_view sav_c{ array_view{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_c.bounds().strides() == index<1>{ 1 }); @@ -341,7 +341,7 @@ SUITE(array_view_tests) #if _MSC_VER > 1800 strided_array_view sav_cv{ {src}, {2, 1} }; #else - strided_array_view sav_cv{ array_view{src}, strided_bounds<1>{2, 1} }; + strided_array_view sav_cv{ array_view{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_cv.bounds().strides() == index<1>{ 1 }); From c6a2f8c086aaa2f344c3d14504ef4b1cde310254 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 17:51:31 -0700 Subject: [PATCH 4/6] Testing tab fixup. --- tests/array_view_tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 12344d9..4537ce8 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -751,11 +751,11 @@ SUITE(array_view_tests) TEST(empty_arrays) { #ifdef CONFIRM_COMPILATION_ERRORS - { - array_view empty; - strided_array_view empty2; - strided_array_view empty3{ nullptr,{ 0, 1 } }; - } + { + array_view empty; + strided_array_view empty2; + strided_array_view empty3{ nullptr,{ 0, 1 } }; + } #endif array_view empty_av(nullptr); From 3ff9b17a9f82225c99d9312ccc0227b8f8b594e6 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 17:57:29 -0700 Subject: [PATCH 5/6] Restoring empty_array_view tests. --- tests/array_view_tests.cpp | 60 ++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 4537ce8..63909fa 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -758,20 +758,62 @@ SUITE(array_view_tests) } #endif - array_view empty_av(nullptr); + { + array_view empty_av(nullptr); - CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_av[0], fail_fast); + CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_av[0], fail_fast); + CHECK_THROW(empty_av.begin()[0], fail_fast); + CHECK_THROW(empty_av.cbegin()[0], fail_fast); + + for (auto& v : empty_av) + { + CHECK(false); + } + } - strided_array_view empty_sav{ empty_av, { 0, 1 } }; + { + array_view empty_av = {}; + + CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_av[0], fail_fast); + CHECK_THROW(empty_av.begin()[0], fail_fast); + CHECK_THROW(empty_av.cbegin()[0], fail_fast); + + for (auto& v : empty_av) + { + CHECK(false); + } + } - CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_sav[0], fail_fast); + { + array_view empty_av(nullptr); + strided_array_view empty_sav{ empty_av, { 0, 1 } }; - strided_array_view empty_sav2{ nullptr, 0, { 0, 1 } }; + CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_sav[0], fail_fast); + CHECK_THROW(empty_sav.begin()[0], fail_fast); + CHECK_THROW(empty_sav.cbegin()[0], fail_fast); - CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); - CHECK_THROW(empty_sav[0], fail_fast); + for (auto& v : empty_sav) + { + CHECK(false); + } + } + + { + strided_array_view empty_sav{ nullptr, 0, { 0, 1 } }; + + CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); + CHECK_THROW(empty_sav[0], fail_fast); + CHECK_THROW(empty_sav.begin()[0], fail_fast); + CHECK_THROW(empty_sav.cbegin()[0], fail_fast); + + for (auto& v : empty_sav) + { + CHECK(false); + } + } } TEST(index_constructor) From 54ec02fef6070c55a8fbbfbc82a161d0060b3114 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 18:04:40 -0700 Subject: [PATCH 6/6] Fixing misformatting of ArrayViewComparison. --- tests/array_view_tests.cpp | 193 ++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 98 deletions(-) diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 63909fa..0525f9d 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -765,7 +765,6 @@ SUITE(array_view_tests) CHECK_THROW(empty_av[0], fail_fast); CHECK_THROW(empty_av.begin()[0], fail_fast); CHECK_THROW(empty_av.cbegin()[0], fail_fast); - for (auto& v : empty_av) { CHECK(false); @@ -774,12 +773,10 @@ SUITE(array_view_tests) { array_view empty_av = {}; - CHECK(empty_av.bounds().index_bounds() == index<1>{ 0 }); CHECK_THROW(empty_av[0], fail_fast); CHECK_THROW(empty_av.begin()[0], fail_fast); - CHECK_THROW(empty_av.cbegin()[0], fail_fast); - + CHECK_THROW(empty_av.cbegin()[0], fail_fast); for (auto& v : empty_av) { CHECK(false); @@ -1532,114 +1529,114 @@ SUITE(array_view_tests) TEST(ArrayViewComparison) { - { - int arr[10][2]; - auto av1 = as_array_view(arr); - array_view av2 = av1; + { + int arr[10][2]; + auto av1 = as_array_view(arr); + array_view av2 = av1; - CHECK(av1 == av2); + CHECK(av1 == av2); - array_view, 20> av3 = av1.as_array_view(dim<>(20)); - CHECK(av3 == av2 && av3 == av1); - } + array_view, 20> av3 = av1.as_array_view(dim<>(20)); + CHECK(av3 == av2 && av3 == av1); + } - { - auto av1 = nullptr; - auto av2 = nullptr; - CHECK(av1 == av2); - CHECK(!(av1 != av2)); - CHECK(!(av1 < av2)); - CHECK(av1 <= av2); - CHECK(!(av1 > av2)); - CHECK(av1 >= av2); - CHECK(av2 == av1); - CHECK(!(av2 != av1)); - CHECK(!(av2 < av1)); - CHECK(av2 <= av1); - CHECK(!(av2 > av1)); - CHECK(av2 >= av1); - } + { + auto av1 = nullptr; + auto av2 = nullptr; + CHECK(av1 == av2); + CHECK(!(av1 != av2)); + CHECK(!(av1 < av2)); + CHECK(av1 <= av2); + CHECK(!(av1 > av2)); + CHECK(av1 >= av2); + CHECK(av2 == av1); + CHECK(!(av2 != av1)); + CHECK(!(av2 < av1)); + CHECK(av2 <= av1); + CHECK(!(av2 > av1)); + CHECK(av2 >= av1); + } - { - int arr[] = { 2, 1 }; // bigger + { + int arr[] = { 2, 1 }; // bigger - array_view av1 = nullptr; - array_view av2 = arr; + array_view av1 = nullptr; + array_view av2 = arr; - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } - { - int arr1[] = { 1, 2 }; - int arr2[] = { 1, 2 }; - array_view av1 = arr1; - array_view av2 = arr2; + { + int arr1[] = { 1, 2 }; + int arr2[] = { 1, 2 }; + array_view av1 = arr1; + array_view av2 = arr2; - CHECK(av1 == av2); - CHECK(!(av1 != av2)); - CHECK(!(av1 < av2)); - CHECK(av1 <= av2); - CHECK(!(av1 > av2)); - CHECK(av1 >= av2); - CHECK(av2 == av1); - CHECK(!(av2 != av1)); - CHECK(!(av2 < av1)); - CHECK(av2 <= av1); - CHECK(!(av2 > av1)); - CHECK(av2 >= av1); - } + CHECK(av1 == av2); + CHECK(!(av1 != av2)); + CHECK(!(av1 < av2)); + CHECK(av1 <= av2); + CHECK(!(av1 > av2)); + CHECK(av1 >= av2); + CHECK(av2 == av1); + CHECK(!(av2 != av1)); + CHECK(!(av2 < av1)); + CHECK(av2 <= av1); + CHECK(!(av2 > av1)); + CHECK(av2 >= av1); + } - { - int arr[] = { 1, 2, 3 }; + { + int arr[] = { 1, 2, 3 }; - array_view av1 = { &arr[0], 2 }; // shorter - array_view av2 = arr; // longer + array_view av1 = { &arr[0], 2 }; // shorter + array_view av2 = arr; // longer - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } - { - int arr1[] = { 1, 2 }; // smaller - int arr2[] = { 2, 1 }; // bigger + { + int arr1[] = { 1, 2 }; // smaller + int arr2[] = { 2, 1 }; // bigger - array_view av1 = arr1; - array_view av2 = arr2; + array_view av1 = arr1; + array_view av2 = arr2; - CHECK(av1 != av2); - CHECK(av2 != av1); - CHECK(!(av1 == av2)); - CHECK(!(av2 == av1)); - CHECK(av1 < av2); - CHECK(!(av2 < av1)); - CHECK(av1 <= av2); - CHECK(!(av2 <= av1)); - CHECK(av2 > av1); - CHECK(!(av1 > av2)); - CHECK(av2 >= av1); - CHECK(!(av1 >= av2)); - } + CHECK(av1 != av2); + CHECK(av2 != av1); + CHECK(!(av1 == av2)); + CHECK(!(av2 == av1)); + CHECK(av1 < av2); + CHECK(!(av2 < av1)); + CHECK(av1 <= av2); + CHECK(!(av2 <= av1)); + CHECK(av2 > av1); + CHECK(!(av1 > av2)); + CHECK(av2 >= av1); + CHECK(!(av1 >= av2)); + } } }