From 8e31f53f8a3132c497363bd87f03204d3d7969af Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Fri, 29 Jul 2016 11:16:06 -0700 Subject: [PATCH] Building clean with MSVC12. --- include/multi_span.h | 7 ++++--- include/span.h | 22 ++++++++++++++++++++-- include/string_span.h | 23 +---------------------- tests/span_tests.cpp | 8 ++++++++ tests/utils_tests.cpp | 2 +- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/include/multi_span.h b/include/multi_span.h index a59c4dc..e35fc33 100644 --- a/include/multi_span.h +++ b/include/multi_span.h @@ -1594,12 +1594,13 @@ public: // Free functions for manipulating spans // + // reshape a multi_span into a different dimensionality // DimCount and Enabled here are workarounds for a bug in MSVC 2015 template 0), typename = std::enable_if_t> -constexpr multi_span -as_multi_span(SpanType s, Dimensions2... dims) + bool Enabled = (DimCount > 0), typename = std::enable_if_t > +constexpr auto +as_multi_span(SpanType s, Dimensions2... dims) -> multi_span { static_assert(details::is_multi_span::value, "Variadic as_multi_span() is for reshaping existing spans."); diff --git a/include/span.h b/include/span.h index 4d8e877..44e1b8d 100644 --- a/include/span.h +++ b/include/span.h @@ -49,7 +49,8 @@ #if _MSC_VER <= 1800 #define GSL_MSVC_HAS_VARIADIC_CTOR_BUG -#define GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT +#define GSL_MSVC_NO_DEFAULT_MOVE_CTOR +#define GSL_MSVC_NO_CPP14_STD_EQUAL // noexcept is not understood #ifndef GSL_THROW_ON_CONTRACT_VIOLATION @@ -57,6 +58,9 @@ #define noexcept /* nothing */ #endif +#pragma push_macro("alignof") +#define alignof __alignof + // turn off some misguided warnings #pragma warning(push) #pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior @@ -541,7 +545,11 @@ public: } constexpr span(const span& other) noexcept = default; +#ifndef GSL_MSVC_NO_DEFAULT_MOVE_CTOR constexpr span(span&& other) noexcept = default; +#else + constexpr span(span&& other) noexcept : storage_(std::move(other.storage_)) {} +#endif template < class OtherElementType, std::ptrdiff_t OtherExtent, @@ -567,8 +575,12 @@ public: ~span() noexcept = default; constexpr span& operator=(const span& other) noexcept = default; - constexpr span& operator=(span&& other) noexcept = default; +#ifndef GSL_MSVC_NO_DEFAULT_MOVE_CTOR + constexpr span& operator=(span&& other) noexcept = default; +#else + constexpr span& operator=(span&& other) noexcept { storage_ = std::move(other.storage_); return *this; } +#endif // [span.sub], span subviews template constexpr span first() const @@ -669,7 +681,11 @@ template & l, const span& r) { +#ifdef GSL_MSVC_NO_CPP14_STD_EQUAL + return (l.size() == r.size()) && std::equal(l.begin(), l.end(), r.begin()); +#else return std::equal(l.begin(), l.end(), r.begin(), r.end()); +#endif } template @@ -756,6 +772,8 @@ as_writeable_bytes(span s) noexcept #pragma pop_macro("noexcept") #endif // GSL_THROW_ON_CONTRACT_VIOLATION +#pragma pop_macro("alignof") + #undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG #endif // _MSC_VER <= 1800 diff --git a/include/string_span.h b/include/string_span.h index 0ca3c51..3fe826f 100644 --- a/include/string_span.h +++ b/include/string_span.h @@ -24,6 +24,7 @@ #include "span.h" #include #include +#include #ifdef _MSC_VER @@ -313,7 +314,6 @@ public: template ::value && - !details::is_span::value && std::is_convertible::value && std::is_convertible().data())>::value>> @@ -324,7 +324,6 @@ public: template ::value && - !details::is_span::value && std::is_convertible::value && std::is_convertible().data())>::value>> @@ -332,26 +331,6 @@ public: { } -#ifndef GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE - // from span - template , impl_type>::value>> - constexpr basic_string_span(const span& other) : span_(other) - { - } -#else - // from span - constexpr basic_string_span(span other) : span_(other) {} - - template , value_type>::value>> - constexpr basic_string_span(const span, Extent>& other) - : span_(other) - { - } -#endif - // from string_span template < class OtherValueType, std::ptrdiff_t OtherExtent, diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 77b799a..8c9829d 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -839,7 +839,9 @@ SUITE(span_tests) CHECK(it - beyond == 0); for (auto& n : s) + { CHECK(n == 5); + } } } @@ -881,7 +883,9 @@ SUITE(span_tests) CHECK(it - beyond == 0); for (auto& n : s) + { CHECK(n == 5); + } } } @@ -923,7 +927,9 @@ SUITE(span_tests) CHECK(it - beyond == 0); for (auto& n : s) + { CHECK(n == 5); + } } } @@ -965,7 +971,9 @@ SUITE(span_tests) CHECK(it - beyond == 0); for (auto& n : s) + { CHECK(n == 5); + } } } diff --git a/tests/utils_tests.cpp b/tests/utils_tests.cpp index a46d6e4..11582de 100644 --- a/tests/utils_tests.cpp +++ b/tests/utils_tests.cpp @@ -103,7 +103,7 @@ SUITE(utils_tests) CHECK(narrow(int32_t(0)) == 0); CHECK(narrow(int32_t(1)) == 1); - CHECK(narrow(int32_max) == int32_max); + CHECK(narrow(int32_max) == static_cast(int32_max)); CHECK_THROW(narrow(int32_t(-1)), narrowing_error); CHECK_THROW(narrow(int32_min), narrowing_error);