Remove inline added for the now unsupported MSVC 2013. (#585)

This commit is contained in:
Johel Ernesto Guerrero Peña 2018-02-20 18:46:37 -04:00 committed by Neil MacIntosh
parent f8f265be84
commit 73db6ef98f
5 changed files with 58 additions and 57 deletions

View File

@ -74,63 +74,63 @@ enum class byte : unsigned char
}; };
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
inline constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept constexpr byte& operator<<=(byte& b, IntegerType shift) noexcept
{ {
return b = byte(static_cast<unsigned char>(b) << shift); return b = byte(static_cast<unsigned char>(b) << shift);
} }
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
inline constexpr byte operator<<(byte b, IntegerType shift) noexcept constexpr byte operator<<(byte b, IntegerType shift) noexcept
{ {
return byte(static_cast<unsigned char>(b) << shift); return byte(static_cast<unsigned char>(b) << shift);
} }
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
inline constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept constexpr byte& operator>>=(byte& b, IntegerType shift) noexcept
{ {
return b = byte(static_cast<unsigned char>(b) >> shift); return b = byte(static_cast<unsigned char>(b) >> shift);
} }
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
inline constexpr byte operator>>(byte b, IntegerType shift) noexcept constexpr byte operator>>(byte b, IntegerType shift) noexcept
{ {
return byte(static_cast<unsigned char>(b) >> shift); return byte(static_cast<unsigned char>(b) >> shift);
} }
inline constexpr byte& operator|=(byte& l, byte r) noexcept constexpr byte& operator|=(byte& l, byte r) noexcept
{ {
return l = byte(static_cast<unsigned char>(l) | static_cast<unsigned char>(r)); return l = byte(static_cast<unsigned char>(l) | static_cast<unsigned char>(r));
} }
inline constexpr byte operator|(byte l, byte r) noexcept constexpr byte operator|(byte l, byte r) noexcept
{ {
return byte(static_cast<unsigned char>(l) | static_cast<unsigned char>(r)); return byte(static_cast<unsigned char>(l) | static_cast<unsigned char>(r));
} }
inline constexpr byte& operator&=(byte& l, byte r) noexcept constexpr byte& operator&=(byte& l, byte r) noexcept
{ {
return l = byte(static_cast<unsigned char>(l) & static_cast<unsigned char>(r)); return l = byte(static_cast<unsigned char>(l) & static_cast<unsigned char>(r));
} }
inline constexpr byte operator&(byte l, byte r) noexcept constexpr byte operator&(byte l, byte r) noexcept
{ {
return byte(static_cast<unsigned char>(l) & static_cast<unsigned char>(r)); return byte(static_cast<unsigned char>(l) & static_cast<unsigned char>(r));
} }
inline constexpr byte& operator^=(byte& l, byte r) noexcept constexpr byte& operator^=(byte& l, byte r) noexcept
{ {
return l = byte(static_cast<unsigned char>(l) ^ static_cast<unsigned char>(r)); return l = byte(static_cast<unsigned char>(l) ^ static_cast<unsigned char>(r));
} }
inline constexpr byte operator^(byte l, byte r) noexcept constexpr byte operator^(byte l, byte r) noexcept
{ {
return byte(static_cast<unsigned char>(l) ^ static_cast<unsigned char>(r)); return byte(static_cast<unsigned char>(l) ^ static_cast<unsigned char>(r));
} }
inline constexpr byte operator~(byte b) noexcept { return byte(~static_cast<unsigned char>(b)); } constexpr byte operator~(byte b) noexcept { return byte(~static_cast<unsigned char>(b)); }
template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>> template <class IntegerType, class = std::enable_if_t<std::is_integral<IntegerType>::value>>
inline constexpr IntegerType to_integer(byte b) noexcept constexpr IntegerType to_integer(byte b) noexcept
{ {
return static_cast<IntegerType>(b); return static_cast<IntegerType>(b);
} }
@ -138,7 +138,7 @@ inline constexpr IntegerType to_integer(byte b) noexcept
#endif // GSL_USE_STD_BYTE #endif // GSL_USE_STD_BYTE
template <bool E, typename T> template <bool E, typename T>
inline constexpr byte to_byte_impl(T t) noexcept constexpr byte to_byte_impl(T t) noexcept
{ {
static_assert( static_assert(
E, "gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. " E, "gsl::to_byte(t) must be provided an unsigned char, otherwise data loss may occur. "
@ -146,19 +146,19 @@ inline constexpr byte to_byte_impl(T t) noexcept
return static_cast<byte>(t); return static_cast<byte>(t);
} }
template <> template <>
inline constexpr byte to_byte_impl<true, unsigned char>(unsigned char t) noexcept constexpr byte to_byte_impl<true, unsigned char>(unsigned char t) noexcept
{ {
return byte(t); return byte(t);
} }
template <typename T> template <typename T>
inline constexpr byte to_byte(T t) noexcept constexpr byte to_byte(T t) noexcept
{ {
return to_byte_impl<std::is_same<T, unsigned char>::value, T>(t); return to_byte_impl<std::is_same<T, unsigned char>::value, T>(t);
} }
template <int I> template <int I>
inline constexpr byte to_byte() noexcept constexpr byte to_byte() noexcept
{ {
static_assert(I >= 0 && I <= 255, static_assert(I >= 0 && I <= 255,
"gsl::byte only has 8 bits of storage, values must be in range 0-255"); "gsl::byte only has 8 bits of storage, values must be in range 0-255");

View File

@ -70,20 +70,21 @@ private:
// finally() - convenience function to generate a final_action // finally() - convenience function to generate a final_action
template <class F> template <class F>
inline final_action<F> finally(const F& f) noexcept
final_action<F> finally(const F& f) noexcept
{ {
return final_action<F>(f); return final_action<F>(f);
} }
template <class F> template <class F>
inline final_action<F> finally(F&& f) noexcept final_action<F> finally(F&& f) noexcept
{ {
return final_action<F>(std::forward<F>(f)); return final_action<F>(std::forward<F>(f));
} }
// narrow_cast(): a searchable way to do narrowing casts of values // narrow_cast(): a searchable way to do narrowing casts of values
template <class T, class U> template <class T, class U>
inline constexpr T narrow_cast(U&& u) noexcept constexpr T narrow_cast(U&& u) noexcept
{ {
return static_cast<T>(std::forward<U>(u)); return static_cast<T>(std::forward<U>(u));
} }
@ -103,7 +104,7 @@ namespace details
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value // narrow() : a checked version of narrow_cast() that throws if the cast changed the value
template <class T, class U> template <class T, class U>
inline T narrow(U u) T narrow(U u)
{ {
T t = narrow_cast<T>(u); T t = narrow_cast<T>(u);
if (static_cast<U>(t) != u) throw narrowing_error(); if (static_cast<U>(t) != u) throw narrowing_error();
@ -116,14 +117,14 @@ inline T narrow(U u)
// at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector // at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector
// //
template <class T, std::size_t N> template <class T, std::size_t N>
inline constexpr T& at(T (&arr)[N], const std::ptrdiff_t index) constexpr T& at(T (&arr)[N], const std::ptrdiff_t index)
{ {
Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(N)); Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(N));
return arr[static_cast<std::size_t>(index)]; return arr[static_cast<std::size_t>(index)];
} }
template <class Cont> template <class Cont>
inline constexpr auto at(Cont& cont, const std::ptrdiff_t index) -> decltype(cont[cont.size()]) constexpr auto at(Cont& cont, const std::ptrdiff_t index) -> decltype(cont[cont.size()])
{ {
Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(cont.size())); Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(cont.size()));
using size_type = decltype(cont.size()); using size_type = decltype(cont.size());
@ -131,7 +132,7 @@ inline constexpr auto at(Cont& cont, const std::ptrdiff_t index) -> decltype(con
} }
template <class T> template <class T>
inline constexpr T at(const std::initializer_list<T> cont, const std::ptrdiff_t index) constexpr T at(const std::initializer_list<T> cont, const std::ptrdiff_t index)
{ {
Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(cont.size())); Expects(index >= 0 && index < narrow_cast<std::ptrdiff_t>(cont.size()));
return *(cont.begin() + index); return *(cont.begin() + index);

View File

@ -498,7 +498,7 @@ namespace details
template <std::size_t Rank, bool Enabled = (Rank > 1), template <std::size_t Rank, bool Enabled = (Rank > 1),
typename Ret = std::enable_if_t<Enabled, index<Rank - 1>>> typename Ret = std::enable_if_t<Enabled, index<Rank - 1>>>
inline constexpr Ret shift_left(const index<Rank>& other) GSL_NOEXCEPT constexpr Ret shift_left(const index<Rank>& other) GSL_NOEXCEPT
{ {
Ret ret{}; Ret ret{};
for (std::size_t i = 0; i < Rank - 1; ++i) { for (std::size_t i = 0; i < Rank - 1; ++i) {
@ -996,7 +996,7 @@ bounds_iterator<IndexType> operator+(typename bounds_iterator<IndexType>::differ
namespace details namespace details
{ {
template <typename Bounds> template <typename Bounds>
inline constexpr std::enable_if_t< constexpr std::enable_if_t<
std::is_same<typename Bounds::mapping_type, generalized_mapping_tag>::value, std::is_same<typename Bounds::mapping_type, generalized_mapping_tag>::value,
typename Bounds::index_type> typename Bounds::index_type>
make_stride(const Bounds& bnd) GSL_NOEXCEPT make_stride(const Bounds& bnd) GSL_NOEXCEPT
@ -1006,7 +1006,7 @@ namespace details
// Make a stride vector from bounds, assuming contiguous memory. // Make a stride vector from bounds, assuming contiguous memory.
template <typename Bounds> template <typename Bounds>
inline constexpr std::enable_if_t< constexpr std::enable_if_t<
std::is_same<typename Bounds::mapping_type, contiguous_mapping_tag>::value, std::is_same<typename Bounds::mapping_type, contiguous_mapping_tag>::value,
typename Bounds::index_type> typename Bounds::index_type>
make_stride(const Bounds& bnd) GSL_NOEXCEPT make_stride(const Bounds& bnd) GSL_NOEXCEPT
@ -1056,13 +1056,13 @@ struct dim_t<dynamic_range>
}; };
template <std::ptrdiff_t N, class = std::enable_if_t<(N >= 0)>> template <std::ptrdiff_t N, class = std::enable_if_t<(N >= 0)>>
inline constexpr dim_t<N> dim() GSL_NOEXCEPT constexpr dim_t<N> dim() GSL_NOEXCEPT
{ {
return dim_t<N>(); return dim_t<N>();
} }
template <std::ptrdiff_t N = dynamic_range, class = std::enable_if_t<N == dynamic_range>> template <std::ptrdiff_t N = dynamic_range, class = std::enable_if_t<N == dynamic_range>>
inline constexpr dim_t<N> dim(std::ptrdiff_t n) GSL_NOEXCEPT constexpr dim_t<N> dim(std::ptrdiff_t n) GSL_NOEXCEPT
{ {
return dim_t<>(n); return dim_t<>(n);
} }
@ -1599,7 +1599,7 @@ public:
// DimCount and Enabled here are workarounds for a bug in MSVC 2015 // DimCount and Enabled here are workarounds for a bug in MSVC 2015
template <typename SpanType, typename... Dimensions2, std::size_t DimCount = sizeof...(Dimensions2), template <typename SpanType, typename... Dimensions2, std::size_t DimCount = sizeof...(Dimensions2),
bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>> bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>>
inline constexpr auto as_multi_span(SpanType s, Dimensions2... dims) constexpr auto as_multi_span(SpanType s, Dimensions2... dims)
-> multi_span<typename SpanType::value_type, Dimensions2::value...> -> multi_span<typename SpanType::value_type, Dimensions2::value...>
{ {
static_assert(details::is_multi_span<SpanType>::value, static_assert(details::is_multi_span<SpanType>::value,
@ -1637,7 +1637,7 @@ multi_span<byte> as_writeable_bytes(multi_span<U, Dimensions...> s) GSL_NOEXCEPT
// on all implementations. It should be considered an experimental extension // on all implementations. It should be considered an experimental extension
// to the standard GSL interface. // to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions> template <typename U, std::ptrdiff_t... Dimensions>
inline constexpr auto constexpr auto
as_multi_span(multi_span<const byte, Dimensions...> s) GSL_NOEXCEPT -> multi_span< as_multi_span(multi_span<const byte, Dimensions...> s) GSL_NOEXCEPT -> multi_span<
const U, static_cast<std::ptrdiff_t>( const U, static_cast<std::ptrdiff_t>(
multi_span<const byte, Dimensions...>::bounds_type::static_size != dynamic_range multi_span<const byte, Dimensions...>::bounds_type::static_size != dynamic_range
@ -1664,7 +1664,7 @@ as_multi_span(multi_span<const byte, Dimensions...> s) GSL_NOEXCEPT -> multi_spa
// on all implementations. It should be considered an experimental extension // on all implementations. It should be considered an experimental extension
// to the standard GSL interface. // to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions> template <typename U, std::ptrdiff_t... Dimensions>
inline constexpr auto as_multi_span(multi_span<byte, Dimensions...> s) GSL_NOEXCEPT constexpr auto as_multi_span(multi_span<byte, Dimensions...> s) GSL_NOEXCEPT
-> multi_span<U, narrow_cast<std::ptrdiff_t>( -> multi_span<U, narrow_cast<std::ptrdiff_t>(
multi_span<byte, Dimensions...>::bounds_type::static_size != dynamic_range multi_span<byte, Dimensions...>::bounds_type::static_size != dynamic_range
? static_cast<std::size_t>( ? static_cast<std::size_t>(
@ -1685,7 +1685,7 @@ inline constexpr auto as_multi_span(multi_span<byte, Dimensions...> s) GSL_NOEXC
} }
template <typename T, std::ptrdiff_t... Dimensions> template <typename T, std::ptrdiff_t... Dimensions>
inline constexpr auto as_multi_span(T* const& ptr, dim_t<Dimensions>... args) constexpr auto as_multi_span(T* const& ptr, dim_t<Dimensions>... args)
-> multi_span<std::remove_all_extents_t<T>, Dimensions...> -> multi_span<std::remove_all_extents_t<T>, Dimensions...>
{ {
return {reinterpret_cast<std::remove_all_extents_t<T>*>(ptr), return {reinterpret_cast<std::remove_all_extents_t<T>*>(ptr),
@ -1694,41 +1694,41 @@ inline constexpr auto as_multi_span(T* const& ptr, dim_t<Dimensions>... args)
} }
template <typename T> template <typename T>
inline constexpr auto as_multi_span(T* arr, std::ptrdiff_t len) -> constexpr auto as_multi_span(T* arr, std::ptrdiff_t len) ->
typename details::SpanArrayTraits<T, dynamic_range>::type typename details::SpanArrayTraits<T, dynamic_range>::type
{ {
return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len}; return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len};
} }
template <typename T, std::size_t N> template <typename T, std::size_t N>
inline constexpr auto as_multi_span(T (&arr)[N]) -> typename details::SpanArrayTraits<T, N>::type constexpr auto as_multi_span(T (&arr)[N]) -> typename details::SpanArrayTraits<T, N>::type
{ {
return {arr}; return {arr};
} }
template <typename T, std::size_t N> template <typename T, std::size_t N>
inline constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>& arr) constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>& arr)
{ {
return {arr}; return {arr};
} }
template <typename T, std::size_t N> template <typename T, std::size_t N>
inline constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>&&) = delete; constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>&&) = delete;
template <typename T, std::size_t N> template <typename T, std::size_t N>
inline constexpr multi_span<T, N> as_multi_span(std::array<T, N>& arr) constexpr multi_span<T, N> as_multi_span(std::array<T, N>& arr)
{ {
return {arr}; return {arr};
} }
template <typename T> template <typename T>
inline constexpr multi_span<T, dynamic_range> as_multi_span(T* begin, T* end) constexpr multi_span<T, dynamic_range> as_multi_span(T* begin, T* end)
{ {
return {begin, end}; return {begin, end};
} }
template <typename Cont> template <typename Cont>
inline constexpr auto as_multi_span(Cont& arr) -> std::enable_if_t< constexpr auto as_multi_span(Cont& arr) -> std::enable_if_t<
!details::is_multi_span<std::decay_t<Cont>>::value, !details::is_multi_span<std::decay_t<Cont>>::value,
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>>
{ {
@ -1737,13 +1737,13 @@ inline constexpr auto as_multi_span(Cont& arr) -> std::enable_if_t<
} }
template <typename Cont> template <typename Cont>
inline constexpr auto as_multi_span(Cont&& arr) -> std::enable_if_t< constexpr auto as_multi_span(Cont&& arr) -> std::enable_if_t<
!details::is_multi_span<std::decay_t<Cont>>::value, !details::is_multi_span<std::decay_t<Cont>>::value,
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete; multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete;
// from basic_string which doesn't have nonconst .data() member like other contiguous containers // from basic_string which doesn't have nonconst .data() member like other contiguous containers
template <typename CharT, typename Traits, typename Allocator> template <typename CharT, typename Traits, typename Allocator>
inline constexpr auto as_multi_span(std::basic_string<CharT, Traits, Allocator>& str) constexpr auto as_multi_span(std::basic_string<CharT, Traits, Allocator>& str)
-> multi_span<CharT, dynamic_range> -> multi_span<CharT, dynamic_range>
{ {
Expects(str.size() < PTRDIFF_MAX); Expects(str.size() < PTRDIFF_MAX);

View File

@ -253,7 +253,7 @@ namespace details
}; };
template <class Span, bool IsConst> template <class Span, bool IsConst>
inline constexpr span_iterator<Span, IsConst> constexpr span_iterator<Span, IsConst>
operator+(typename span_iterator<Span, IsConst>::difference_type n, operator+(typename span_iterator<Span, IsConst>::difference_type n,
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
{ {
@ -261,7 +261,7 @@ namespace details
} }
template <class Span, bool IsConst> template <class Span, bool IsConst>
inline constexpr span_iterator<Span, IsConst> constexpr span_iterator<Span, IsConst>
operator-(typename span_iterator<Span, IsConst>::difference_type n, operator-(typename span_iterator<Span, IsConst>::difference_type n,
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
{ {
@ -535,42 +535,42 @@ private:
// [span.comparison], span comparison operators // [span.comparison], span comparison operators
template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent> template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent>
inline constexpr bool operator==(span<ElementType, FirstExtent> l, constexpr bool operator==(span<ElementType, FirstExtent> l,
span<ElementType, SecondExtent> r) span<ElementType, SecondExtent> r)
{ {
return std::equal(l.begin(), l.end(), r.begin(), r.end()); return std::equal(l.begin(), l.end(), r.begin(), r.end());
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator!=(span<ElementType, Extent> l, constexpr bool operator!=(span<ElementType, Extent> l,
span<ElementType, Extent> r) span<ElementType, Extent> r)
{ {
return !(l == r); return !(l == r);
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator<(span<ElementType, Extent> l, constexpr bool operator<(span<ElementType, Extent> l,
span<ElementType, Extent> r) span<ElementType, Extent> r)
{ {
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end()); return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator<=(span<ElementType, Extent> l, constexpr bool operator<=(span<ElementType, Extent> l,
span<ElementType, Extent> r) span<ElementType, Extent> r)
{ {
return !(l > r); return !(l > r);
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>(span<ElementType, Extent> l, constexpr bool operator>(span<ElementType, Extent> l,
span<ElementType, Extent> r) span<ElementType, Extent> r)
{ {
return r < l; return r < l;
} }
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>=(span<ElementType, Extent> l, constexpr bool operator>=(span<ElementType, Extent> l,
span<ElementType, Extent> r) span<ElementType, Extent> r)
{ {
return !(l < r); return !(l < r);
@ -662,7 +662,7 @@ span<typename Ptr::element_type> make_span(Ptr& cont)
// Specialization of gsl::at for span // Specialization of gsl::at for span
template <class ElementType, std::ptrdiff_t Extent> template <class ElementType, std::ptrdiff_t Extent>
inline constexpr ElementType& at(span<ElementType, Extent> s, std::ptrdiff_t index) constexpr ElementType& at(span<ElementType, Extent> s, std::ptrdiff_t index)
{ {
// No bounds checking here because it is done in span::operator[] called below // No bounds checking here because it is done in span::operator[] called below
return s[index]; return s[index];

View File

@ -130,7 +130,7 @@ span<T, dynamic_extent> ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX
// the limit of size_type. // the limit of size_type.
// //
template <typename CharT> template <typename CharT>
inline span<CharT, dynamic_extent> ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRDIFF_MAX) span<CharT, dynamic_extent> ensure_z(CharT* const& sz, std::ptrdiff_t max = PTRDIFF_MAX)
{ {
return ensure_sentinel<CharT, CharT(0)>(sz, max); return ensure_sentinel<CharT, CharT(0)>(sz, max);
} }