From 9a297120227979ad8fa53525178f8edf806634de Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 14 Sep 2015 15:11:07 -0700 Subject: [PATCH] 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)