mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
applied clang-format
This commit is contained in:
parent
9b3ac8d681
commit
f8bcb7d9eb
@ -21,9 +21,9 @@
|
|||||||
#include <gsl/gsl_byte> // for byte
|
#include <gsl/gsl_byte> // for byte
|
||||||
#include <gsl/gsl_util> // for narrow_cast, narrow
|
#include <gsl/gsl_util> // for narrow_cast, narrow
|
||||||
|
|
||||||
#include <array> // for array
|
#include <array> // for array
|
||||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||||
#include <iterator> // for reverse_iterator, distance, random_access_...
|
#include <iterator> // for reverse_iterator, distance, random_access_...
|
||||||
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
|
#include <type_traits> // for enable_if_t, declval, is_convertible, inte...
|
||||||
|
|
||||||
#if defined(_MSC_VER) && !defined(__clang__)
|
#if defined(_MSC_VER) && !defined(__clang__)
|
||||||
@ -441,18 +441,20 @@ public:
|
|||||||
: storage_(KnownNotNull{arr + 0}, details::extent_type<N>())
|
: storage_(KnownNotNull{arr + 0}, details::extent_type<N>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <class T, std::size_t N,
|
template <
|
||||||
std::enable_if_t<(details::is_allowed_extent_conversion<N, Extent>::value &&
|
class T, std::size_t N,
|
||||||
details::is_allowed_element_type_conversion<T, element_type>::value), int> = 0>
|
std::enable_if_t<(details::is_allowed_extent_conversion<N, Extent>::value &&
|
||||||
|
details::is_allowed_element_type_conversion<T, element_type>::value),
|
||||||
|
int> = 0>
|
||||||
constexpr span(std::array<T, N>& arr) noexcept
|
constexpr span(std::array<T, N>& arr) noexcept
|
||||||
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template <class T, std::size_t N,
|
template <class T, std::size_t N,
|
||||||
std::enable_if_t<(details::is_allowed_extent_conversion<N, Extent>::value &&
|
std::enable_if_t<
|
||||||
details::is_allowed_element_type_conversion<const T,
|
(details::is_allowed_extent_conversion<N, Extent>::value &&
|
||||||
element_type>::value),
|
details::is_allowed_element_type_conversion<const T, element_type>::value),
|
||||||
int> = 0>
|
int> = 0>
|
||||||
constexpr span(const std::array<T, N>& arr) noexcept
|
constexpr span(const std::array<T, N>& arr) noexcept
|
||||||
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
||||||
{}
|
{}
|
||||||
@ -463,7 +465,9 @@ public:
|
|||||||
class = std::enable_if_t<
|
class = std::enable_if_t<
|
||||||
!details::is_span<Container>::value && !details::is_std_array<Container>::value &&
|
!details::is_span<Container>::value && !details::is_std_array<Container>::value &&
|
||||||
std::is_pointer<decltype(std::declval<Container&>().data())>::value &&
|
std::is_pointer<decltype(std::declval<Container&>().data())>::value &&
|
||||||
std::is_convertible<std::remove_pointer_t<decltype(std::declval<Container&>().data())>(*)[], element_type(*)[]>::value>>
|
std::is_convertible<
|
||||||
|
std::remove_pointer_t<decltype(std::declval<Container&>().data())> (*)[],
|
||||||
|
element_type (*)[]>::value>>
|
||||||
constexpr span(Container& cont) noexcept : span(cont.data(), cont.size())
|
constexpr span(Container& cont) noexcept : span(cont.data(), cont.size())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -472,7 +476,9 @@ public:
|
|||||||
std::is_const<element_type>::value && !details::is_span<Container>::value &&
|
std::is_const<element_type>::value && !details::is_span<Container>::value &&
|
||||||
!details::is_std_array<Container>::value &&
|
!details::is_std_array<Container>::value &&
|
||||||
std::is_pointer<decltype(std::declval<const Container&>().data())>::value &&
|
std::is_pointer<decltype(std::declval<const Container&>().data())>::value &&
|
||||||
std::is_convertible<std::remove_pointer_t<decltype(std::declval<const Container&>().data())>(*)[], element_type(*)[]>::value>>
|
std::is_convertible<std::remove_pointer_t<
|
||||||
|
decltype(std::declval<const Container&>().data())> (*)[],
|
||||||
|
element_type (*)[]>::value>>
|
||||||
constexpr span(const Container& cont) noexcept : span(cont.data(), cont.size())
|
constexpr span(const Container& cont) noexcept : span(cont.data(), cont.size())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -501,8 +507,8 @@ public:
|
|||||||
template <std::size_t Count>
|
template <std::size_t Count>
|
||||||
// clang-format off
|
// clang-format off
|
||||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
||||||
// clang-format on
|
// clang-format on
|
||||||
constexpr span<element_type, Count> last() const noexcept
|
constexpr span<element_type, Count> last() const noexcept
|
||||||
{
|
{
|
||||||
Expects(Count <= size());
|
Expects(Count <= size());
|
||||||
return {data() + (size() - Count), Count};
|
return {data() + (size() - Count), Count};
|
||||||
@ -511,9 +517,9 @@ public:
|
|||||||
template <std::size_t Offset, std::size_t Count = dynamic_extent>
|
template <std::size_t Offset, std::size_t Count = dynamic_extent>
|
||||||
// clang-format off
|
// clang-format off
|
||||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
||||||
// clang-format on
|
// clang-format on
|
||||||
constexpr auto subspan() const noexcept ->
|
constexpr auto subspan() const noexcept ->
|
||||||
typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type
|
typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type
|
||||||
{
|
{
|
||||||
Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
|
Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
|
||||||
|
|
||||||
@ -674,7 +680,8 @@ private:
|
|||||||
|
|
||||||
template <std::size_t CallerExtent>
|
template <std::size_t CallerExtent>
|
||||||
constexpr span<element_type, dynamic_extent> make_subspan(size_type offset, size_type count,
|
constexpr span<element_type, dynamic_extent> make_subspan(size_type offset, size_type count,
|
||||||
subspan_selector<CallerExtent>) const noexcept
|
subspan_selector<CallerExtent>) const
|
||||||
|
noexcept
|
||||||
{
|
{
|
||||||
const span<element_type, dynamic_extent> tmp(*this);
|
const span<element_type, dynamic_extent> tmp(*this);
|
||||||
return tmp.subspan(offset, count);
|
return tmp.subspan(offset, count);
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include <iterator> // for reverse_iterator, operator-, operator==
|
#include <iterator> // for reverse_iterator, operator-, operator==
|
||||||
#include <type_traits> // for integral_constant<>::value, is_default_co...
|
#include <type_traits> // for integral_constant<>::value, is_default_co...
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gsl;
|
using namespace gsl;
|
||||||
@ -46,7 +46,7 @@ TEST(span_compatibility_tests, assertion_tests)
|
|||||||
{
|
{
|
||||||
int arr[3]{10, 20, 30};
|
int arr[3]{10, 20, 30};
|
||||||
std::array<int, 3> stl{{100, 200, 300}};
|
std::array<int, 3> stl{{100, 200, 300}};
|
||||||
std::array<int*, 3> stl_nullptr{{nullptr,nullptr,nullptr}};
|
std::array<int*, 3> stl_nullptr{{nullptr, nullptr, nullptr}};
|
||||||
|
|
||||||
#if __cplusplus >= 201703l
|
#if __cplusplus >= 201703l
|
||||||
// This std::is_convertible_v<int*(*)[], int const* const(*)[]> fails for C++14
|
// This std::is_convertible_v<int*(*)[], int const* const(*)[]> fails for C++14
|
||||||
@ -60,8 +60,9 @@ TEST(span_compatibility_tests, assertion_tests)
|
|||||||
EXPECT_TRUE(sp_const_nullptr_2.data() == stl_nullptr.data());
|
EXPECT_TRUE(sp_const_nullptr_2.data() == stl_nullptr.data());
|
||||||
EXPECT_TRUE(sp_const_nullptr_2.size() == 3);
|
EXPECT_TRUE(sp_const_nullptr_2.size() == 3);
|
||||||
|
|
||||||
static_assert(std::is_same<decltype(span{stl_nullptr}), span<int*, 3>);
|
static_assert(std::is_same < decltype(span{stl_nullptr}), span<int*, 3>);
|
||||||
static_assert(std::is_same<decltype(span{std::as_const(stl_nullptr)}), span<int* const, 3>);
|
static_assert(std::is_same < decltype(span{std::as_const(stl_nullptr)}),
|
||||||
|
span<int* const, 3>);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1070,21 +1071,20 @@ static_assert(std::is_convertible<std::array<int, 3>&, gsl::span<const int>>::va
|
|||||||
static_assert(std::is_convertible<const std::array<int, 3>&, gsl::span<const int>>::value,
|
static_assert(std::is_convertible<const std::array<int, 3>&, gsl::span<const int>>::value,
|
||||||
"std::is_convertible<const std::array<int, 3>&, gsl::span<const int>>");
|
"std::is_convertible<const std::array<int, 3>&, gsl::span<const int>>");
|
||||||
|
|
||||||
|
|
||||||
#if __cplusplus >= 201703l
|
#if __cplusplus >= 201703l
|
||||||
template <typename U, typename = void>
|
template <typename U, typename = void>
|
||||||
static constexpr bool AsWritableBytesCompilesFor = false;
|
static constexpr bool AsWritableBytesCompilesFor = false;
|
||||||
|
|
||||||
template <typename U>
|
template <typename U>
|
||||||
static constexpr bool AsWritableBytesCompilesFor<U, void_t<decltype(as_writable_bytes(declval<U>()))>> =
|
static constexpr bool
|
||||||
true;
|
AsWritableBytesCompilesFor<U, void_t<decltype(as_writable_bytes(declval<U>()))>> = true;
|
||||||
|
|
||||||
static_assert(AsWritableBytesCompilesFor<gsl::span<int>>,
|
static_assert(AsWritableBytesCompilesFor<gsl::span<int>>,
|
||||||
"AsWritableBytesCompilesFor<gsl::span<int>>");
|
"AsWritableBytesCompilesFor<gsl::span<int>>");
|
||||||
static_assert(AsWritableBytesCompilesFor<gsl::span<int, 9>>,
|
static_assert(AsWritableBytesCompilesFor<gsl::span<int, 9>>,
|
||||||
"AsWritableBytesCompilesFor<gsl::span<int, 9>>");
|
"AsWritableBytesCompilesFor<gsl::span<int, 9>>");
|
||||||
static_assert(!AsWritableBytesCompilesFor<gsl::span<const int>>,
|
static_assert(!AsWritableBytesCompilesFor<gsl::span<const int>>,
|
||||||
"!AsWritableBytesCompilesFor<gsl::span<const int>>");
|
"!AsWritableBytesCompilesFor<gsl::span<const int>>");
|
||||||
static_assert(!AsWritableBytesCompilesFor<gsl::span<const int, 9>>,
|
static_assert(!AsWritableBytesCompilesFor<gsl::span<const int, 9>>,
|
||||||
"!AsWritableBytesCompilesFor<gsl::span<const int, 9>>");
|
"!AsWritableBytesCompilesFor<gsl::span<const int, 9>>");
|
||||||
#endif // __cplusplus >= 201703l
|
#endif // __cplusplus >= 201703l
|
||||||
|
Loading…
Reference in New Issue
Block a user