mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Remove inline added for the now unsupported MSVC 2013. (#585)
This commit is contained in:
parent
f8f265be84
commit
73db6ef98f
@ -74,63 +74,63 @@ enum class byte : unsigned char
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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>>
|
||||
inline constexpr IntegerType to_integer(byte b) noexcept
|
||||
constexpr IntegerType to_integer(byte b) noexcept
|
||||
{
|
||||
return static_cast<IntegerType>(b);
|
||||
}
|
||||
@ -138,7 +138,7 @@ inline constexpr IntegerType to_integer(byte b) noexcept
|
||||
#endif // GSL_USE_STD_BYTE
|
||||
|
||||
template <bool E, typename T>
|
||||
inline constexpr byte to_byte_impl(T t) noexcept
|
||||
constexpr byte to_byte_impl(T t) noexcept
|
||||
{
|
||||
static_assert(
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
template <int I>
|
||||
inline constexpr byte to_byte() noexcept
|
||||
constexpr byte to_byte() noexcept
|
||||
{
|
||||
static_assert(I >= 0 && I <= 255,
|
||||
"gsl::byte only has 8 bits of storage, values must be in range 0-255");
|
||||
|
@ -70,20 +70,21 @@ private:
|
||||
|
||||
// finally() - convenience function to generate a final_action
|
||||
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);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
// narrow_cast(): a searchable way to do narrowing casts of values
|
||||
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));
|
||||
}
|
||||
@ -103,7 +104,7 @@ namespace details
|
||||
|
||||
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
||||
template <class T, class U>
|
||||
inline T narrow(U u)
|
||||
T narrow(U u)
|
||||
{
|
||||
T t = narrow_cast<T>(u);
|
||||
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
|
||||
//
|
||||
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));
|
||||
return arr[static_cast<std::size_t>(index)];
|
||||
}
|
||||
|
||||
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()));
|
||||
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>
|
||||
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()));
|
||||
return *(cont.begin() + index);
|
||||
|
@ -498,7 +498,7 @@ namespace details
|
||||
|
||||
template <std::size_t Rank, bool Enabled = (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{};
|
||||
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
|
||||
{
|
||||
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,
|
||||
typename Bounds::index_type>
|
||||
make_stride(const Bounds& bnd) GSL_NOEXCEPT
|
||||
@ -1006,7 +1006,7 @@ namespace details
|
||||
|
||||
// Make a stride vector from bounds, assuming contiguous memory.
|
||||
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,
|
||||
typename Bounds::index_type>
|
||||
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)>>
|
||||
inline constexpr dim_t<N> dim() GSL_NOEXCEPT
|
||||
constexpr dim_t<N> dim() GSL_NOEXCEPT
|
||||
{
|
||||
return dim_t<N>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -1599,7 +1599,7 @@ public:
|
||||
// DimCount and Enabled here are workarounds for a bug in MSVC 2015
|
||||
template <typename SpanType, typename... Dimensions2, std::size_t DimCount = sizeof...(Dimensions2),
|
||||
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...>
|
||||
{
|
||||
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
|
||||
// to the standard GSL interface.
|
||||
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<
|
||||
const U, static_cast<std::ptrdiff_t>(
|
||||
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
|
||||
// to the standard GSL interface.
|
||||
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<byte, Dimensions...>::bounds_type::static_size != dynamic_range
|
||||
? 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>
|
||||
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...>
|
||||
{
|
||||
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>
|
||||
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
|
||||
{
|
||||
return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len};
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
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>
|
||||
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};
|
||||
}
|
||||
|
||||
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};
|
||||
}
|
||||
|
||||
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,
|
||||
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>
|
||||
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,
|
||||
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
|
||||
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>
|
||||
{
|
||||
Expects(str.size() < PTRDIFF_MAX);
|
||||
|
@ -253,7 +253,7 @@ namespace details
|
||||
};
|
||||
|
||||
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,
|
||||
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
|
||||
{
|
||||
@ -261,7 +261,7 @@ namespace details
|
||||
}
|
||||
|
||||
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,
|
||||
span_iterator<Span, IsConst> rhs) GSL_NOEXCEPT
|
||||
{
|
||||
@ -535,42 +535,42 @@ private:
|
||||
|
||||
// [span.comparison], span comparison operators
|
||||
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)
|
||||
{
|
||||
return std::equal(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return !(l == r);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return std::lexicographical_compare(l.begin(), l.end(), r.begin(), r.end());
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return !(l > r);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return r < l;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return !(l < r);
|
||||
@ -662,7 +662,7 @@ span<typename Ptr::element_type> make_span(Ptr& cont)
|
||||
|
||||
// Specialization of gsl::at for span
|
||||
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
|
||||
return s[index];
|
||||
|
@ -130,7 +130,7 @@ span<T, dynamic_extent> ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX
|
||||
// the limit of size_type.
|
||||
//
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user