addressing a few more comments and adding gsl-std span compatibility tests

This commit is contained in:
Jordan Maples [MSFT] 2020-02-14 15:24:46 -08:00
parent 926aaeca56
commit 41ae38f197
5 changed files with 1080 additions and 13 deletions

View File

@ -105,19 +105,19 @@ namespace details
};
template <class T>
struct is_std_array : public is_std_array_oracle<std::remove_cv_t<T>>
struct is_std_array : is_std_array_oracle<std::remove_cv_t<T>>
{
};
template <std::size_t From, std::size_t To>
struct is_allowed_extent_conversion
: public std::integral_constant<bool, From == To || To == gsl::dynamic_extent>
: std::integral_constant<bool, From == To || To == gsl::dynamic_extent>
{
};
template <class From, class To>
struct is_allowed_element_type_conversion
: public std::integral_constant<bool, std::is_convertible<From (*)[], To (*)[]>::value>
: std::integral_constant<bool, std::is_convertible<From (*)[], To (*)[]>::value>
{
};
@ -460,13 +460,12 @@ public:
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
{}
// NB: the SFINAE here uses .data() as a incomplete/imperfect proxy for the requirement
// NB: the SFINAE here uses .data() as an incomplete/imperfect proxy for the requirement
// on Container to be a contiguous sequence container.
template <class Container,
class = std::enable_if_t<
!details::is_span<Container>::value && !details::is_std_array<Container>::value &&
std::is_convertible<typename Container::pointer, pointer>::value &&
std::is_convertible<pointer, typename Container::pointer>::value &&
std::is_convertible<decltype(std::declval<Container&>().data()), pointer>::value>>
constexpr span(Container& cont) noexcept : span(cont.data(), cont.size())
{}
@ -671,7 +670,7 @@ private:
// The rest is needed to remove unnecessary null check
// in subspans and constructors from arrays
constexpr span(KnownNotNull ptr, size_type count) : storage_(ptr, count) {}
constexpr span(KnownNotNull ptr, size_type count) noexcept : storage_(ptr, count) {}
template <std::size_t CallerExtent>
class subspan_selector
@ -680,7 +679,7 @@ private:
template <std::size_t CallerExtent>
constexpr span<element_type, dynamic_extent> make_subspan(size_type offset, size_type count,
subspan_selector<CallerExtent>) const
subspan_selector<CallerExtent>) const noexcept
{
const span<element_type, dynamic_extent> tmp(*this);
return tmp.subspan(offset, count);
@ -690,7 +689,7 @@ private:
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
// clang-format on
constexpr span<element_type, dynamic_extent>
make_subspan(size_type offset, size_type count, subspan_selector<dynamic_extent>) const
make_subspan(size_type offset, size_type count, subspan_selector<dynamic_extent>) const noexcept
{
Expects(size() >= offset);

View File

@ -153,6 +153,7 @@ function(add_gsl_test name)
endfunction()
add_gsl_test(span_tests)
add_gsl_test(span_compatibility_tests)
add_gsl_test(multi_span_tests)
add_gsl_test(strided_span_tests)
add_gsl_test(string_span_tests)

File diff suppressed because it is too large Load Diff

View File

@ -29,6 +29,7 @@
#include <string> // for string
#include <type_traits> // for integral_constant<>::value, is_default_co...
#include <vector> // for vector
#include <utility>
using namespace std;
using namespace gsl;
@ -1021,11 +1022,11 @@ TEST(span_test, from_array_constructor)
EXPECT_TRUE((std::is_same<decltype(s.crbegin()), decltype(crbegin(s))>::value));
EXPECT_TRUE((std::is_same<decltype(s.crend()), decltype(crend(s))>::value));
EXPECT_TRUE(s.begin() == begin(s));
EXPECT_TRUE(s.end() == end(s));
EXPECT_TRUE(s.begin() == std::begin(s));
EXPECT_TRUE(s.end() == std::end(s));
EXPECT_TRUE(s.cbegin() == cbegin(s));
EXPECT_TRUE(s.cend() == cend(s));
EXPECT_TRUE(s.cbegin() == std::cbegin(s));
EXPECT_TRUE(s.cend() == std::cend(s));
EXPECT_TRUE(s.rbegin() == rbegin(s));
EXPECT_TRUE(s.rend() == rend(s));

View File

@ -23,7 +23,7 @@
#include <limits> // for numeric_limits
#include <stdint.h> // for uint32_t, int32_t
#include <type_traits> // for is_same
#include <cstddef> // for std::size_t
#include <cstddef> // for std::ptrdiff_t
using namespace gsl;