Updated all array_view uses with the C++20 span. (#7157)

* Updated all array_view uses with the C++20 span.

The updates were done in the following order
1. `AZStd::array_view<([^>].+)\* ?>`  -> `AZStd::span<\1 const>`
2. `AZStd::array_view<(?:const )(.+)>` -> `AZStd::span<const \1>`
3. `AZStd::array_view` -> `AZStd::span`

Removed the implementation of array_view.

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* Added missing whitespace between `const` and the typename for spans.

Updated the ShaderTest comparison of the ShaderResourceGroupLayout span
to compare the sizes as well

Updated comments on some of the methods that stated that they return "an
array" to mention they return "a span".

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
lumberyard-employee-dm
2022-01-26 16:15:47 -06:00
committed by GitHub
parent 48cea89910
commit b9824ed172
170 changed files with 833 additions and 1274 deletions
@@ -42,12 +42,11 @@ namespace AZStd::Internal
namespace AZStd
{
/**
* First pass partial implementation of span copied over from array_view. It
* returns non-const iterator/pointers. first(), last(), and subspan()
* are yet to be implemented. It does not maintain storage for the data,
* but just holds pointers to mark the beginning and end of the array.
* It can be conveniently constructed from a variety of other container
* types like array, vector, and fixed_vector.
* Full C++20 implementation of span done using the C++ draft at https://eel.is/c++draft/views.
* It does not maintain storage for the data,
* but just hold a pointer to mark the beginning and the size for the elements.
* It can be constructed any type that models the C++ contiguous_range concept
* such like array, vector, fixed_vector, raw-array, string_view, string, etc... .
*
* Example:
* Given "void Func(AZStd::span<int> a) {...}" you can call...
@@ -84,7 +83,7 @@ namespace AZStd
inline static constexpr size_t extent = Extent;
constexpr span() noexcept = default;;
constexpr span() noexcept = default;
~span() = default;
@@ -110,12 +109,12 @@ namespace AZStd
Extent != dynamic_extent, int> = 0>
constexpr explicit span(It first, End last);
template<size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
template<size_t N, class = enable_if_t<extent == dynamic_extent || N == Extent>>
constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
template <class U, size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
template <class U, size_t N, class = enable_if_t<extent == dynamic_extent || N == Extent>>
constexpr span(array<U, N>& data) noexcept;
template <class U, size_t N, class = enable_if_t<N == dynamic_extent || N == Extent>>
template <class U, size_t N, class = enable_if_t<extent == dynamic_extent || N == Extent>>
constexpr span(const array<U, N>& data) noexcept;
template <class R, class = enable_if_t<ranges::contiguous_range<R> &&
@@ -246,4 +246,16 @@ namespace UnitTest
AZ_TEST_STOP_TRACE_SUPPRESSION(1);
}
}
TEST_F(SpanTestFixture, CanInitializeFixedArrayToDynamicExtentSpan)
{
constexpr size_t arrayElementCount = 5;
static constexpr AZStd::array<int, arrayElementCount> intArray{ 4, 5, 6, 1, 7 };
constexpr AZStd::span<const int, AZStd::dynamic_extent> arraySpan(intArray);
static_assert(intArray.data() == arraySpan.data());
constexpr AZStd::span<const int, arrayElementCount> arraySpanFixedExtent(intArray);
static_assert(intArray.data() == arraySpanFixedExtent.data());
}
}