Skip to content

Commit

Permalink
Remove inline added for the now unsupported MSVC 2013. (microsoft#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohelEGP authored and neilmacintosh committed Feb 20, 2018
1 parent f8f265b commit 73db6ef
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 57 deletions.
32 changes: 16 additions & 16 deletions include/gsl/gsl_byte
Original file line number Diff line number Diff line change
Expand Up @@ -74,91 +74,91 @@ 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);
}

#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. "
"If you are calling to_byte with an integer contant use: gsl::to_byte<t>() version.");
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");
Expand Down
15 changes: 8 additions & 7 deletions include/gsl/gsl_util
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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();
Expand All @@ -116,22 +117,22 @@ 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());
return cont[static_cast<size_type>(index)];
}

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);
Expand Down
36 changes: 18 additions & 18 deletions include/gsl/multi_span
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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>(
Expand All @@ -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),
Expand All @@ -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>>
{
Expand All @@ -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);
Expand Down
30 changes: 15 additions & 15 deletions include/gsl/span
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ 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
{
return rhs + n;
}

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
{
Expand Down Expand Up @@ -535,43 +535,43 @@ 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,
span<ElementType, SecondExtent> r)
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,
span<ElementType, Extent> r)
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,
span<ElementType, Extent> r)
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,
span<ElementType, Extent> r)
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,
span<ElementType, Extent> r)
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,
span<ElementType, Extent> r)
constexpr bool operator>=(span<ElementType, Extent> l,
span<ElementType, Extent> r)
{
return !(l < r);
}
Expand Down Expand Up @@ -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];
Expand Down
Loading

0 comments on commit 73db6ef

Please sign in to comment.