Building clean with MSVC12.

This commit is contained in:
Neil MacIntosh 2016-07-29 11:16:06 -07:00
parent a0cf1ecc49
commit 8e31f53f8a
5 changed files with 34 additions and 28 deletions

View File

@ -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 <typename SpanType, typename... Dimensions2, size_t DimCount = sizeof...(Dimensions2),
bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>>
constexpr multi_span<typename SpanType::value_type, Dimensions2::value...>
as_multi_span(SpanType s, Dimensions2... dims)
bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled> >
constexpr auto
as_multi_span(SpanType s, Dimensions2... dims) -> multi_span<typename SpanType::value_type, Dimensions2::value...>
{
static_assert(details::is_multi_span<SpanType>::value,
"Variadic as_multi_span() is for reshaping existing spans.");

View File

@ -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 <std::ptrdiff_t Count>
constexpr span<element_type, Count> first() const
@ -669,7 +681,11 @@ template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondEx
constexpr bool operator==(const span<ElementType, FirstExtent>& l,
const span<ElementType, SecondExtent>& 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 <class ElementType, std::ptrdiff_t Extent>
@ -756,6 +772,8 @@ as_writeable_bytes(span<ElementType, Extent> 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

View File

@ -24,6 +24,7 @@
#include "span.h"
#include <cstring>
#include <string>
#include <cstdint>
#ifdef _MSC_VER
@ -313,7 +314,6 @@ public:
template <class Container,
class = std::enable_if_t<
!details::is_basic_string_span<Container>::value &&
!details::is_span<Container>::value &&
std::is_convertible<typename Container::pointer, pointer>::value &&
std::is_convertible<typename Container::pointer,
decltype(std::declval<Container>().data())>::value>>
@ -324,7 +324,6 @@ public:
template <class Container,
class = std::enable_if_t<
!details::is_basic_string_span<Container>::value &&
!details::is_span<Container>::value &&
std::is_convertible<typename Container::pointer, pointer>::value &&
std::is_convertible<typename Container::pointer,
decltype(std::declval<Container>().data())>::value>>
@ -332,26 +331,6 @@ public:
{
}
#ifndef GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE
// from span
template <typename OtherValueType, std::ptrdiff_t OtherExtent,
typename Dummy = std::enable_if_t<
std::is_convertible<span<OtherValueType, OtherExtent>, impl_type>::value>>
constexpr basic_string_span(const span<OtherValueType, OtherExtent>& other) : span_(other)
{
}
#else
// from span
constexpr basic_string_span(span<element_type, Extent> other) : span_(other) {}
template <typename = std::enable_if_t<
!std::is_same<std::remove_const_t<element_type>, value_type>::value>>
constexpr basic_string_span(const span<std::remove_const_t<element_type>, Extent>& other)
: span_(other)
{
}
#endif
// from string_span
template <
class OtherValueType, std::ptrdiff_t OtherExtent,

View File

@ -839,9 +839,11 @@ SUITE(span_tests)
CHECK(it - beyond == 0);
for (auto& n : s)
{
CHECK(n == 5);
}
}
}
TEST(cbegin_cend)
{
@ -881,9 +883,11 @@ SUITE(span_tests)
CHECK(it - beyond == 0);
for (auto& n : s)
{
CHECK(n == 5);
}
}
}
TEST(rbegin_rend)
{
@ -923,9 +927,11 @@ SUITE(span_tests)
CHECK(it - beyond == 0);
for (auto& n : s)
{
CHECK(n == 5);
}
}
}
TEST(crbegin_crend)
{
@ -965,9 +971,11 @@ SUITE(span_tests)
CHECK(it - beyond == 0);
for (auto& n : s)
{
CHECK(n == 5);
}
}
}
TEST(comparison_operators)
{

View File

@ -103,7 +103,7 @@ SUITE(utils_tests)
CHECK(narrow<uint32_t>(int32_t(0)) == 0);
CHECK(narrow<uint32_t>(int32_t(1)) == 1);
CHECK(narrow<uint32_t>(int32_max) == int32_max);
CHECK(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max));
CHECK_THROW(narrow<uint32_t>(int32_t(-1)), narrowing_error);
CHECK_THROW(narrow<uint32_t>(int32_min), narrowing_error);