Reformat files to follow clang-format style (#492)

Project files were not following the clang-format style. For people
using IDEs were clang-format is always run after a save this would
cause unwanted changes.

This commit only applies "clang-format -i" to files.
This commit is contained in:
Tiago
2017-04-20 07:51:37 -07:00
committed by Neil MacIntosh
parent c5851a8161
commit ebe7ebfd85
20 changed files with 1965 additions and 1892 deletions
+29 -23
View File
@@ -24,24 +24,25 @@
#include <gsl/multi_span> // multi_span, strided_span...
#include <gsl/span> // span
#include <gsl/string_span> // zstring, string_span, zstring_builder...
#include <memory>
#include <iostream>
#include <memory>
#if defined(_MSC_VER) && _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// turn off some misguided warnings
#pragma warning(push)
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#endif // _MSC_VER <= 1800
#endif // defined(_MSC_VER) && _MSC_VER < 1910
// turn off some misguided warnings
#pragma warning(push)
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#endif // _MSC_VER <= 1800
#endif // defined(_MSC_VER) && _MSC_VER < 1910
namespace gsl
{
@@ -76,10 +77,15 @@ public:
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
constexpr not_null(U&& u) : ptr_(std::forward<U>(u)) { Expects(ptr_ != nullptr); }
constexpr not_null(U&& u) : ptr_(std::forward<U>(u))
{
Expects(ptr_ != nullptr);
}
template <typename U, typename Dummy = std::enable_if_t<std::is_convertible<U, T>::value>>
constexpr not_null(const not_null<U>& other) : not_null(other.get()) {}
constexpr not_null(const not_null<U>& other) : not_null(other.get())
{
}
not_null(const not_null& other) = default;
not_null& operator=(const not_null& other) = default;
@@ -157,7 +163,7 @@ auto operator>=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.
template <class T, class U>
std::ptrdiff_t operator-(const not_null<T>&, const not_null<U>&) = delete;
template <class T>
not_null<T> operator-(const not_null<T>&, std::ptrdiff_t) = delete;
not_null<T> operator-(const not_null<T>&, std::ptrdiff_t) = delete;
template <class T>
not_null<T> operator+(const not_null<T>&, std::ptrdiff_t) = delete;
template <class T>
@@ -176,15 +182,15 @@ struct hash<gsl::not_null<T>>
} // namespace std
#if defined(_MSC_VER) && _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#pragma warning(pop)
#endif // _MSC_VER <= 1800
#pragma warning(pop)
#endif // _MSC_VER <= 1800
#endif // defined(_MSC_VER) && _MSC_VER < 1910
#endif // GSL_GSL_H
+13 -11
View File
@@ -20,30 +20,32 @@
#define GSL_ALGORITHM_H
#include <gsl/span>
#include <algorithm>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(push)
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
#endif // _MSC_VER
namespace gsl
{
template <class SrcElementType, std::ptrdiff_t SrcExtent,
class DestElementType, std::ptrdiff_t DestExtent>
template <class SrcElementType, std::ptrdiff_t SrcExtent, class DestElementType,
std::ptrdiff_t DestExtent>
void copy(span<SrcElementType, SrcExtent> src, span<DestElementType, DestExtent> dest)
{
static_assert(std::is_assignable<decltype(*dest.data()), decltype(*src.data())>::value,
"Elements of source span can not be assigned to elements of destination span");
static_assert(SrcExtent == dynamic_extent || DestExtent == dynamic_extent || (SrcExtent <= DestExtent),
static_assert(SrcExtent == dynamic_extent || DestExtent == dynamic_extent ||
(SrcExtent <= DestExtent),
"Source range is longer than target range");
Expects(dest.size() >= src.size());
@@ -53,7 +55,7 @@ void copy(span<SrcElementType, SrcExtent> src, span<DestElementType, DestExtent>
} // namespace gsl
#ifdef _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
#endif // GSL_ALGORITHM_H
+15 -15
View File
@@ -32,18 +32,18 @@
//
#if !(defined(GSL_THROW_ON_CONTRACT_VIOLATION) || defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION) || \
defined(GSL_UNENFORCED_ON_CONTRACT_VIOLATION))
#define GSL_TERMINATE_ON_CONTRACT_VIOLATION
#define GSL_TERMINATE_ON_CONTRACT_VIOLATION
#endif
#define GSL_STRINGIFY_DETAIL(x) #x
#define GSL_STRINGIFY(x) GSL_STRINGIFY_DETAIL(x)
#if defined(__clang__) || defined(__GNUC__)
#define GSL_LIKELY(x) __builtin_expect (!!(x), 1)
#define GSL_UNLIKELY(x) __builtin_expect (!!(x), 0)
#define GSL_LIKELY(x) __builtin_expect(!!(x), 1)
#define GSL_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
#define GSL_LIKELY(x) (!!(x))
#define GSL_UNLIKELY(x) (!!(x))
#define GSL_LIKELY(x) (!!(x))
#define GSL_UNLIKELY(x) (!!(x))
#endif
//
@@ -53,13 +53,13 @@
// whether or not cond is actually evaluated.
//
#ifdef _MSC_VER
#define GSL_ASSUME(cond) __assume(cond)
#define GSL_ASSUME(cond) __assume(cond)
#elif defined(__clang__)
#define GSL_ASSUME(cond) __builtin_assume(cond)
#define GSL_ASSUME(cond) __builtin_assume(cond)
#elif defined(__GNUC__)
#define GSL_ASSUME(cond) ((cond) ? static_cast<void>(0) : __builtin_unreachable())
#define GSL_ASSUME(cond) ((cond) ? static_cast<void>(0) : __builtin_unreachable())
#else
#define GSL_ASSUME(cond) static_cast<void>(!!(cond))
#define GSL_ASSUME(cond) static_cast<void>(!!(cond))
#endif
//
@@ -76,18 +76,18 @@ struct fail_fast : public std::logic_error
#if defined(GSL_THROW_ON_CONTRACT_VIOLATION)
#define GSL_CONTRACT_CHECK(type, cond) \
(GSL_LIKELY(cond) ? static_cast<void>(0) : \
throw gsl::fail_fast("GSL: " type " failure at " __FILE__ ": " GSL_STRINGIFY(__LINE__)))
#define GSL_CONTRACT_CHECK(type, cond) \
(GSL_LIKELY(cond) ? static_cast<void>(0) \
: throw gsl::fail_fast("GSL: " type " failure at " __FILE__ \
": " GSL_STRINGIFY(__LINE__)))
#elif defined(GSL_TERMINATE_ON_CONTRACT_VIOLATION)
#define GSL_CONTRACT_CHECK(type, cond) \
(GSL_LIKELY(cond) ? static_cast<void>(0) : std::terminate())
#define GSL_CONTRACT_CHECK(type, cond) (GSL_LIKELY(cond) ? static_cast<void>(0) : std::terminate())
#elif defined(GSL_UNENFORCED_ON_CONTRACT_VIOLATION)
#define GSL_CONTRACT_CHECK(type, cond) GSL_ASSUME(cond)
#define GSL_CONTRACT_CHECK(type, cond) GSL_ASSUME(cond)
#endif
+29 -30
View File
@@ -22,22 +22,22 @@
#include <type_traits>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(push)
// don't warn about function style casts in byte related operators
#pragma warning(disable : 26493)
// don't warn about function style casts in byte related operators
#pragma warning(disable : 26493)
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// constexpr is not understood
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// constexpr is not understood
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#endif // _MSC_VER <= 1800
#endif // _MSC_VER
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#endif // _MSC_VER <= 1800
#endif // _MSC_VER
namespace gsl
{
@@ -109,47 +109,46 @@ inline constexpr IntegerType to_integer(byte b) noexcept
return static_cast<IntegerType>(b);
}
template<bool E, typename T>
template <bool E, typename T>
inline 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."
);
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<>
template <>
inline 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
{
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>
inline 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");
static_assert(I >= 0 && I <= 255,
"gsl::byte only has 8 bits of storage, values must be in range 0-255");
return static_cast<byte>(I);
}
} // namespace gsl
#ifdef _MSC_VER
#if _MSC_VER <= 1800
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER <= 1800
#undef constexpr
#pragma pop_macro("constexpr")
#undef noexcept
#pragma pop_macro("noexcept")
#endif // _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#endif // _MSC_VER <= 1800
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
#endif // GSL_BYTE_H
+25 -24
View File
@@ -20,28 +20,29 @@
#define GSL_UTIL_H
#include <gsl/gsl_assert> // Ensures/Expects
#include <array>
#include <exception>
#include <type_traits>
#include <utility>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// MSVC 2013 workarounds
#if _MSC_VER <= 1800
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
namespace gsl
{
@@ -154,16 +155,16 @@ inline constexpr T at(const std::initializer_list<T> cont, const std::ptrdiff_t
} // namespace gsl
#if defined(_MSC_VER)
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#pragma warning(pop)
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#pragma warning(pop)
#endif // _MSC_VER
#endif // GSL_UTIL_H
+120 -75
View File
@@ -22,6 +22,7 @@
#include <gsl/gsl_assert>
#include <gsl/gsl_byte>
#include <gsl/gsl_util>
#include <algorithm>
#include <array>
#include <cassert>
@@ -37,34 +38,34 @@
#include <utility>
#ifdef _MSC_VER
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
// turn off some warnings that are noisy about our Expects statements
#pragma warning(push)
#pragma warning(disable : 4127) // conditional expression is constant
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#define GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#define GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable : 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable : 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
#define GSL_NOEXCEPT /*noexcept*/
#define GSL_NOEXCEPT /*noexcept*/
#else
#define GSL_NOEXCEPT noexcept
#define GSL_NOEXCEPT noexcept
#endif // GSL_THROW_ON_CONTRACT_VIOLATION
namespace gsl
@@ -207,7 +208,10 @@ public:
return ret;
}
friend constexpr index operator*(value_type v, const index& rhs) GSL_NOEXCEPT { return rhs * v; }
friend constexpr index operator*(value_type v, const index& rhs) GSL_NOEXCEPT
{
return rhs * v;
}
constexpr index& operator*=(value_type v) GSL_NOEXCEPT
{
@@ -344,10 +348,11 @@ namespace details
static const std::size_t DynamicNum = Base::DynamicNum + 1;
static const size_type CurrentRange = dynamic_range;
static const size_type TotalSize = dynamic_range;
private:
size_type m_bound;
public:
public:
BoundsRanges(const std::ptrdiff_t* const arr)
: Base(arr + 1), m_bound(*arr * this->Base::totalSize())
{
@@ -492,7 +497,8 @@ namespace details
return obj_;
}
template <std::size_t N, typename MyChain = TypeChain, typename MyBase = typename MyChain::Base>
template <std::size_t N, typename MyChain = TypeChain,
typename MyBase = typename MyChain::Base>
auto getObj(std::false_type)
-> decltype(TypeListIndexer<MyBase>(static_cast<const MyBase&>(obj_)).template get<N>())
{
@@ -690,7 +696,10 @@ public:
return !(*this == rhs);
}
constexpr const_iterator begin() const GSL_NOEXCEPT { return const_iterator(*this, index_type{}); }
constexpr const_iterator begin() const GSL_NOEXCEPT
{
return const_iterator(*this, index_type{});
}
constexpr const_iterator end() const GSL_NOEXCEPT
{
@@ -790,9 +799,15 @@ public:
}
constexpr index_type index_bounds() const GSL_NOEXCEPT { return m_extents; }
constexpr const_iterator begin() const GSL_NOEXCEPT { return const_iterator{*this, index_type{}}; }
constexpr const_iterator begin() const GSL_NOEXCEPT
{
return const_iterator{*this, index_type{}};
}
constexpr const_iterator end() const GSL_NOEXCEPT { return const_iterator{*this, index_bounds()}; }
constexpr const_iterator end() const GSL_NOEXCEPT
{
return const_iterator{*this, index_bounds()};
}
private:
index_type m_extents;
@@ -931,18 +946,27 @@ public:
return curr_ == rhs.curr_;
}
constexpr bool operator!=(const bounds_iterator& rhs) const GSL_NOEXCEPT { return !(*this == rhs); }
constexpr bool operator!=(const bounds_iterator& rhs) const GSL_NOEXCEPT
{
return !(*this == rhs);
}
constexpr bool operator<(const bounds_iterator& rhs) const GSL_NOEXCEPT
{
return less(curr_, rhs.curr_);
}
constexpr bool operator<=(const bounds_iterator& rhs) const GSL_NOEXCEPT { return !(rhs < *this); }
constexpr bool operator<=(const bounds_iterator& rhs) const GSL_NOEXCEPT
{
return !(rhs < *this);
}
constexpr bool operator>(const bounds_iterator& rhs) const GSL_NOEXCEPT { return rhs < *this; }
constexpr bool operator>=(const bounds_iterator& rhs) const GSL_NOEXCEPT { return !(rhs > *this); }
constexpr bool operator>=(const bounds_iterator& rhs) const GSL_NOEXCEPT
{
return !(rhs > *this);
}
void swap(bounds_iterator& rhs) GSL_NOEXCEPT
{
@@ -1136,7 +1160,7 @@ namespace details
template <typename T, typename Arg, typename... Args>
std::enable_if_t<
!std::is_same<Arg, dim_t<dynamic_range>>::value && !std::is_same<Arg, Sep>::value, T>
static_as_multi_span_helper(Arg, Args... args)
static_as_multi_span_helper(Arg, Args... args)
{
return static_as_multi_span_helper<T>(args...);
}
@@ -1227,7 +1251,8 @@ public:
// construct from nullptr with size of 0 (helps with template function calls)
template <class IntType, typename = std::enable_if_t<std::is_integral<IntType>::value>>
constexpr multi_span(std::nullptr_t, IntType size) GSL_NOEXCEPT : multi_span(nullptr, bounds_type{})
constexpr multi_span(std::nullptr_t, IntType size) GSL_NOEXCEPT
: multi_span(nullptr, bounds_type{})
{
static_assert(bounds_type::dynamic_rank != 0 ||
(bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0),
@@ -1249,13 +1274,14 @@ public:
constexpr multi_span(value_type&&) = delete;
// construct from pointer + length
constexpr multi_span(pointer ptr, size_type size) GSL_NOEXCEPT : multi_span(ptr, bounds_type{size})
constexpr multi_span(pointer ptr, size_type size) GSL_NOEXCEPT
: multi_span(ptr, bounds_type{size})
{
}
// construct from pointer + length - multidimensional
constexpr multi_span(pointer data, bounds_type bounds) GSL_NOEXCEPT : data_(data),
bounds_(std::move(bounds))
bounds_(std::move(bounds))
{
Expects((bounds_.size() > 0 && data != nullptr) || bounds_.size() == 0);
}
@@ -1426,9 +1452,8 @@ public:
// subspan() - create a subview of count elements starting at offset
// supplying dynamic_range for count will consume all available elements from offset
constexpr multi_span<ValueType, dynamic_range> subspan(size_type offset,
size_type count = dynamic_range) const
GSL_NOEXCEPT
constexpr multi_span<ValueType, dynamic_range>
subspan(size_type offset, size_type count = dynamic_range) const GSL_NOEXCEPT
{
Expects((offset >= 0 && offset <= this->size()) &&
(count == dynamic_range || (count <= this->size() - offset)));
@@ -1436,8 +1461,8 @@ public:
}
// section - creates a non-contiguous, strided multi_span from a contiguous one
constexpr strided_span<ValueType, Rank> section(index_type origin, index_type extents) const
GSL_NOEXCEPT
constexpr strided_span<ValueType, Rank> section(index_type origin,
index_type extents) const GSL_NOEXCEPT
{
size_type size = this->bounds().total_size() - this->bounds().linearize(origin);
return {&this->operator[](origin), size,
@@ -1451,7 +1476,10 @@ public:
constexpr size_type length() const GSL_NOEXCEPT { return this->size(); }
// length of the multi_span in bytes
constexpr size_type size_bytes() const GSL_NOEXCEPT { return narrow_cast<size_type>(sizeof(value_type)) * this->size(); }
constexpr size_type size_bytes() const GSL_NOEXCEPT
{
return narrow_cast<size_type>(sizeof(value_type)) * this->size();
}
// length of the multi_span in bytes
constexpr size_type length_bytes() const GSL_NOEXCEPT { return this->size_bytes(); }
@@ -1539,8 +1567,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator==(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator==(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return bounds_.size() == other.bounds_.size() &&
(data_ == other.data_ || std::equal(this->begin(), this->end(), other.begin()));
@@ -1549,8 +1577,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator!=(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator!=(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return !(*this == other);
}
@@ -1558,8 +1586,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator<(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end());
}
@@ -1567,8 +1595,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<=(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator<=(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return !(other < *this);
}
@@ -1576,8 +1604,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator>(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return (other < *this);
}
@@ -1585,8 +1613,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t... OtherDimensions,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>=(const multi_span<OtherValueType, OtherDimensions...>& other) const
GSL_NOEXCEPT
constexpr bool
operator>=(const multi_span<OtherValueType, OtherDimensions...>& other) const GSL_NOEXCEPT
{
return !(*this < other);
}
@@ -1638,7 +1666,8 @@ 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 as_multi_span(multi_span<const byte, Dimensions...> s) GSL_NOEXCEPT -> multi_span<
inline 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
? (static_cast<std::size_t>(
@@ -1830,8 +1859,9 @@ public:
size_type size = this->bounds().total_size() / d;
return {const_cast<OtherValueType*>(reinterpret_cast<const OtherValueType*>(this->data())),
size, bounds_type{resize_extent(this->bounds().index_bounds(), d),
resize_stride(this->bounds().strides(), d)}};
size,
bounds_type{resize_extent(this->bounds().index_bounds(), d),
resize_stride(this->bounds().strides(), d)}};
}
constexpr strided_span section(index_type origin, index_type extents) const
@@ -1898,7 +1928,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator==(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator==(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return bounds_.size() == other.bounds_.size() &&
(data_ == other.data_ || std::equal(this->begin(), this->end(), other.begin()));
@@ -1907,7 +1938,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator!=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator!=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return !(*this == other);
}
@@ -1915,7 +1947,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator<(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end());
}
@@ -1923,7 +1956,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator<=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator<=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return !(other < *this);
}
@@ -1931,7 +1965,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator>(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return (other < *this);
}
@@ -1939,7 +1974,8 @@ public:
template <typename OtherValueType, std::ptrdiff_t OtherRank,
typename Dummy = std::enable_if_t<std::is_same<
std::remove_cv_t<value_type>, std::remove_cv_t<OtherValueType>>::value>>
constexpr bool operator>=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
constexpr bool
operator>=(const strided_span<OtherValueType, OtherRank>& other) const GSL_NOEXCEPT
{
return !(*this < other);
}
@@ -2074,15 +2110,24 @@ public:
Expects(m_validator == rhs.m_validator);
return data_ == rhs.data_;
}
bool operator!=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT { return !(*this == rhs); }
bool operator!=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT
{
return !(*this == rhs);
}
bool operator<(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT
{
Expects(m_validator == rhs.m_validator);
return data_ < rhs.data_;
}
bool operator<=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT { return !(rhs < *this); }
bool operator<=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT
{
return !(rhs < *this);
}
bool operator>(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT { return rhs < *this; }
bool operator>=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT { return !(rhs > *this); }
bool operator>=(const contiguous_span_iterator& rhs) const GSL_NOEXCEPT
{
return !(rhs > *this);
}
void swap(contiguous_span_iterator& rhs) GSL_NOEXCEPT
{
std::swap(data_, rhs.data_);
@@ -2202,20 +2247,20 @@ general_span_iterator<Span> operator+(typename general_span_iterator<Span>::diff
#undef GSL_NOEXCEPT
#ifdef _MSC_VER
#if _MSC_VER < 1910
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#if _MSC_VER < 1910
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#undef GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
#endif // _MSC_VER <= 1800
#undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#undef GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT
#endif // _MSC_VER <= 1800
#undef constexpr
#pragma pop_macro("constexpr")
#endif // _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#endif // _MSC_VER < 1910
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
#endif // GSL_MULTI_SPAN_H
+117 -87
View File
@@ -23,53 +23,54 @@
#include <gsl/gsl_assert>
#include <gsl/gsl_byte>
#include <gsl/gsl_util>
#include <array>
#include <iterator>
#include <limits>
#include <memory>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <memory>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(push)
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
// turn off some warnings that are noisy about our Expects statements
#pragma warning(disable : 4127) // conditional expression is constant
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#define GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#define GSL_MSVC_NO_CPP14_STD_EQUAL
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#define GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#define GSL_MSVC_NO_CPP14_STD_EQUAL
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#pragma push_macro("alignof")
#define alignof __alignof
#pragma push_macro("alignof")
#define alignof __alignof
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable : 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
// turn off some misguided warnings
#pragma warning(disable : 4351) // warns about newly introduced aggregate initializer behavior
#pragma warning(disable : 4512) // warns that assignment op could not be generated
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
#define GSL_NOEXCEPT /*noexcept*/
#define GSL_NOEXCEPT /*noexcept*/
#else
#define GSL_NOEXCEPT noexcept
#define GSL_NOEXCEPT noexcept
#endif // GSL_THROW_ON_CONTRACT_VIOLATION
namespace gsl
@@ -131,13 +132,13 @@ namespace details
class span_iterator
{
using element_type_ = typename Span::element_type;
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = std::remove_cv_t<element_type_>;
using difference_type = typename Span::index_type;
using reference =
std::conditional_t<IsConst, const element_type_, element_type_> &;
using reference = std::conditional_t<IsConst, const element_type_, element_type_>&;
using pointer = std::add_pointer_t<reference>;
constexpr span_iterator() GSL_NOEXCEPT : span_iterator(nullptr, 0) {}
@@ -154,7 +155,8 @@ namespace details
{
}
constexpr span_iterator<Span, IsConst>& operator=(const span_iterator<Span, IsConst>&) GSL_NOEXCEPT = default;
constexpr span_iterator<Span, IsConst>&
operator=(const span_iterator<Span, IsConst>&) GSL_NOEXCEPT = default;
constexpr reference operator*() const
{
@@ -223,7 +225,10 @@ namespace details
return index_ - rhs.index_;
}
constexpr reference operator[](difference_type n) const GSL_NOEXCEPT { return *(*this + n); }
constexpr reference operator[](difference_type n) const GSL_NOEXCEPT
{
return *(*this + n);
}
constexpr friend bool operator==(const span_iterator& lhs,
const span_iterator& rhs) GSL_NOEXCEPT
@@ -249,7 +254,8 @@ namespace details
return !(rhs < lhs);
}
constexpr friend bool operator>(const span_iterator& lhs, const span_iterator& rhs) GSL_NOEXCEPT
constexpr friend bool operator>(const span_iterator& lhs,
const span_iterator& rhs) GSL_NOEXCEPT
{
return rhs < lhs;
}
@@ -337,7 +343,7 @@ class span
public:
// constants and types
using element_type = ElementType;
using value_type = std::remove_cv_t<ElementType>;
using value_type = std::remove_cv_t<ElementType>;
using index_type = std::ptrdiff_t;
using pointer = element_type*;
using reference = element_type&;
@@ -353,10 +359,12 @@ public:
// [span.cons], span constructors, copy, assignment, and destructor
template <bool Dependent = false,
// "Dependent" is needed to make "std::enable_if_t<Dependent || Extent <= 0>" SFINAE,
// since "std::enable_if_t<Extent <= 0>" is ill-formed when Extent is greater than 0.
class = std::enable_if_t<(Dependent || Extent <= 0)>>
constexpr span() GSL_NOEXCEPT : storage_(nullptr, details::extent_type<0>()) {}
// "Dependent" is needed to make "std::enable_if_t<Dependent || Extent <= 0>" SFINAE,
// since "std::enable_if_t<Extent <= 0>" is ill-formed when Extent is greater than 0.
class = std::enable_if_t<(Dependent || Extent <= 0)>>
constexpr span() GSL_NOEXCEPT : storage_(nullptr, details::extent_type<0>())
{
}
constexpr span(std::nullptr_t) GSL_NOEXCEPT : span() {}
@@ -368,7 +376,8 @@ public:
}
template <std::size_t N>
constexpr span(element_type (&arr)[N]) GSL_NOEXCEPT : storage_(&arr[0], details::extent_type<N>())
constexpr span(element_type (&arr)[N]) GSL_NOEXCEPT
: storage_(&arr[0], details::extent_type<N>())
{
}
@@ -384,11 +393,18 @@ public:
{
}
template<class ArrayElementType = std::add_pointer<element_type>>
constexpr span(const std::unique_ptr<ArrayElementType>& ptr, index_type count) : storage_(ptr.get(), count) {}
template <class ArrayElementType = std::add_pointer<element_type>>
constexpr span(const std::unique_ptr<ArrayElementType>& ptr, index_type count)
: storage_(ptr.get(), count)
{
}
constexpr span(const std::unique_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0) {}
constexpr span(const std::shared_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0) {}
constexpr span(const std::unique_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0)
{
}
constexpr span(const std::shared_ptr<ElementType>& ptr) : storage_(ptr.get(), ptr.get() ? 1 : 0)
{
}
// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
// on Container to be a contiguous sequence container.
@@ -498,7 +514,10 @@ public:
constexpr index_type length() const GSL_NOEXCEPT { return size(); }
constexpr index_type size() const GSL_NOEXCEPT { return storage_.size(); }
constexpr index_type length_bytes() const GSL_NOEXCEPT { return size_bytes(); }
constexpr index_type size_bytes() const GSL_NOEXCEPT { return size() * narrow_cast<index_type>(sizeof(element_type)); }
constexpr index_type size_bytes() const GSL_NOEXCEPT
{
return size() * narrow_cast<index_type>(sizeof(element_type));
}
constexpr bool empty() const GSL_NOEXCEPT { return size() == 0; }
// [span.elem], span element access
@@ -551,7 +570,7 @@ private:
// [span.comparison], span comparison operators
template <class ElementType, std::ptrdiff_t FirstExtent, std::ptrdiff_t SecondExtent>
inline constexpr bool operator==(const span<ElementType, FirstExtent>& l,
const span<ElementType, SecondExtent>& r)
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());
@@ -561,31 +580,36 @@ inline constexpr bool operator==(const span<ElementType, FirstExtent>& l,
}
template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator!=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r)
inline constexpr bool operator!=(const span<ElementType, Extent>& l,
const span<ElementType, Extent>& r)
{
return !(l == r);
}
template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator<(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r)
inline constexpr bool operator<(const span<ElementType, Extent>& l,
const 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<=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r)
inline constexpr bool operator<=(const span<ElementType, Extent>& l,
const span<ElementType, Extent>& r)
{
return !(l > r);
}
template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r)
inline constexpr bool operator>(const span<ElementType, Extent>& l,
const span<ElementType, Extent>& r)
{
return r < l;
}
template <class ElementType, std::ptrdiff_t Extent>
inline constexpr bool operator>=(const span<ElementType, Extent>& l, const span<ElementType, Extent>& r)
inline constexpr bool operator>=(const span<ElementType, Extent>& l,
const span<ElementType, Extent>& r)
{
return !(l < r);
}
@@ -633,40 +657,46 @@ as_writeable_bytes(span<ElementType, Extent> s) GSL_NOEXCEPT
// make_span() - Utility functions for creating spans
//
template <class ElementType>
span<ElementType>
make_span(ElementType* ptr, typename span<ElementType>::index_type count)
{ return span<ElementType>(ptr, count); }
span<ElementType> make_span(ElementType* ptr, typename span<ElementType>::index_type count)
{
return span<ElementType>(ptr, count);
}
template <class ElementType>
span<ElementType>
make_span(ElementType* firstElem, ElementType* lastElem)
{ return span<ElementType>(firstElem, lastElem); }
span<ElementType> make_span(ElementType* firstElem, ElementType* lastElem)
{
return span<ElementType>(firstElem, lastElem);
}
template <class ElementType, std::size_t N>
span<ElementType>
make_span(ElementType (&arr)[N])
{ return span<ElementType>(arr); }
span<ElementType> make_span(ElementType (&arr)[N])
{
return span<ElementType>(arr);
}
template <class Container>
span<typename Container::value_type>
make_span(Container &cont)
{ return span<typename Container::value_type>(cont); }
span<typename Container::value_type> make_span(Container& cont)
{
return span<typename Container::value_type>(cont);
}
template <class Container>
span<const typename Container::value_type>
make_span(const Container &cont)
{ return span<const typename Container::value_type>(cont); }
span<const typename Container::value_type> make_span(const Container& cont)
{
return span<const typename Container::value_type>(cont);
}
template <class Ptr>
span<typename Ptr::element_type>
make_span(Ptr& cont, std::ptrdiff_t count)
{ return span<typename Ptr::element_type>(cont, count); }
span<typename Ptr::element_type> make_span(Ptr& cont, std::ptrdiff_t count)
{
return span<typename Ptr::element_type>(cont, count);
}
template <class Ptr>
span<typename Ptr::element_type>
make_span(Ptr& cont)
{ return span<typename Ptr::element_type>(cont); }
span<typename Ptr::element_type> make_span(Ptr& cont)
{
return span<typename Ptr::element_type>(cont);
}
// Specialization of gsl::at for span
template <class ElementType, std::ptrdiff_t Extent>
@@ -681,24 +711,24 @@ inline constexpr ElementType& at(const span<ElementType, Extent>& s, std::ptrdif
#undef GSL_NOEXCEPT
#ifdef _MSC_VER
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#undef alignof
#pragma pop_macro("alignof")
#undef alignof
#pragma pop_macro("alignof")
#undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#undef GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#undef GSL_MSVC_NO_CPP14_STD_EQUAL
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#undef GSL_MSVC_HAS_VARIADIC_CTOR_BUG
#undef GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#undef GSL_MSVC_NO_CPP14_STD_EQUAL
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#pragma warning(pop)
#pragma warning(pop)
#endif // _MSC_VER
#endif // GSL_SPAN_H
+48 -53
View File
@@ -22,41 +22,42 @@
#include <gsl/gsl_assert>
#include <gsl/gsl_util>
#include <gsl/span>
#include <cstdint>
#include <cstring>
#include <string>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(push)
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
// blanket turn off warnings from CppCoreCheck for now
// so people aren't annoyed by them when running the tool.
// more targeted suppressions will be added in a future update to the GSL
#pragma warning(disable : 26481 26482 26483 26485 26490 26491 26492 26493 26495)
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
#if _MSC_VER < 1910
#pragma push_macro("constexpr")
#define constexpr /*constexpr*/
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_TYPE_DEDUCTION_BUG
#define GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE
#define GSL_MSVC_NO_CPP14_STD_EQUAL
#define GSL_MSVC_NO_DEFAULT_MOVE_CTOR
// VS 2013 workarounds
#if _MSC_VER <= 1800
#define GSL_MSVC_HAS_TYPE_DEDUCTION_BUG
#define GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE
#define GSL_MSVC_NO_CPP14_STD_EQUAL
#define GSL_MSVC_NO_DEFAULT_MOVE_CTOR
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
// noexcept is not understood
#pragma push_macro("noexcept")
#define noexcept /*noexcept*/
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
// In order to test the library, we need it to throw exceptions that we can catch
#ifdef GSL_THROW_ON_CONTRACT_VIOLATION
#define GSL_NOEXCEPT /*noexcept*/
#define GSL_NOEXCEPT /*noexcept*/
#else
#define GSL_NOEXCEPT noexcept
#define GSL_NOEXCEPT noexcept
#endif // GSL_THROW_ON_CONTRACT_VIOLATION
namespace gsl
@@ -89,30 +90,26 @@ using wzstring = basic_zstring<wchar_t, Extent>;
namespace details
{
inline std::ptrdiff_t string_length(const char *str, std::ptrdiff_t n)
inline std::ptrdiff_t string_length(const char* str, std::ptrdiff_t n)
{
if (str == nullptr || n <= 0)
return 0;
if (str == nullptr || n <= 0) return 0;
span<const char> str_span{str, n};
std::ptrdiff_t len = 0;
while (len < n && str_span[len])
len++;
while (len < n && str_span[len]) len++;
return len;
}
inline std::ptrdiff_t wstring_length(const wchar_t *str, std::ptrdiff_t n)
inline std::ptrdiff_t wstring_length(const wchar_t* str, std::ptrdiff_t n)
{
if (str == nullptr || n <= 0)
return 0;
if (str == nullptr || n <= 0) return 0;
span<const wchar_t> str_span{str, n};
std::ptrdiff_t len = 0;
while (len < n && str_span[len])
len++;
while (len < n && str_span[len]) len++;
return len;
}
@@ -316,7 +313,8 @@ public:
}
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
constexpr basic_string_span(const std::array<ArrayElementType, N>& arr) GSL_NOEXCEPT : span_(arr)
constexpr basic_string_span(const std::array<ArrayElementType, N>& arr) GSL_NOEXCEPT
: span_(arr)
{
}
@@ -484,14 +482,11 @@ inline std::wstring to_string(wstring_span<> view)
#endif
template <typename CharT,
typename Traits = typename std::char_traits<CharT>,
typename Allocator = std::allocator<CharT>,
typename gCharT,
std::ptrdiff_t Extent>
template <typename CharT, typename Traits = typename std::char_traits<CharT>,
typename Allocator = std::allocator<CharT>, typename gCharT, std::ptrdiff_t Extent>
std::basic_string<CharT, Traits, Allocator> to_basic_string(basic_string_span<gCharT, Extent> view)
{
return {view.data(), static_cast<std::size_t>(view.length())};
return {view.data(), static_cast<std::size_t>(view.length())};
}
// zero-terminated string span, used to convert
@@ -830,23 +825,23 @@ bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other) GSL_N
#undef GSL_NOEXCEPT
#ifdef _MSC_VER
#pragma warning(pop)
#pragma warning(pop)
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
#if _MSC_VER < 1910
#undef constexpr
#pragma pop_macro("constexpr")
// VS 2013 workarounds
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
// VS 2013 workarounds
#if _MSC_VER <= 1800
#undef noexcept
#pragma pop_macro("noexcept")
#undef GSL_MSVC_HAS_TYPE_DEDUCTION_BUG
#undef GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE
#undef GSL_MSVC_NO_CPP14_STD_EQUAL
#undef GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#undef GSL_MSVC_HAS_TYPE_DEDUCTION_BUG
#undef GSL_MSVC_HAS_SFINAE_SUBSTITUTION_ICE
#undef GSL_MSVC_NO_CPP14_STD_EQUAL
#undef GSL_MSVC_NO_DEFAULT_MOVE_CTOR
#endif // _MSC_VER <= 1800
#endif // _MSC_VER < 1910
#endif // _MSC_VER
#endif // GSL_STRING_SPAN_H