Renamed as_span() to as_multi_span() for clarity.

This commit is contained in:
Neil MacIntosh 2016-07-28 17:27:22 -07:00
parent a88cfb168a
commit a0cf1ecc49
3 changed files with 78 additions and 78 deletions

View File

@ -1127,25 +1127,25 @@ namespace details
}; };
template <typename T, typename... Args> template <typename T, typename... Args>
T static_as_span_helper(Sep, Args... args) T static_as_multi_span_helper(Sep, Args... args)
{ {
return T{narrow_cast<typename T::size_type>(args)...}; return T{narrow_cast<typename T::size_type>(args)...};
} }
template <typename T, typename Arg, typename... Args> template <typename T, typename Arg, typename... Args>
std::enable_if_t< std::enable_if_t<
!std::is_same<Arg, dim<dynamic_range>>::value && !std::is_same<Arg, Sep>::value, T> !std::is_same<Arg, dim<dynamic_range>>::value && !std::is_same<Arg, Sep>::value, T>
static_as_span_helper(Arg, Args... args) static_as_multi_span_helper(Arg, Args... args)
{ {
return static_as_span_helper<T>(args...); return static_as_multi_span_helper<T>(args...);
} }
template <typename T, typename... Args> template <typename T, typename... Args>
T static_as_span_helper(dim<dynamic_range> val, Args... args) T static_as_multi_span_helper(dim<dynamic_range> val, Args... args)
{ {
return static_as_span_helper<T>(args..., val.dvalue); return static_as_multi_span_helper<T>(args..., val.dvalue);
} }
template <typename... Dimensions> template <typename... Dimensions>
struct static_as_span_static_bounds_helper struct static_as_multi_span_static_bounds_helper
{ {
using type = static_bounds<(Dimensions::value)...>; using type = static_bounds<(Dimensions::value)...>;
}; };
@ -1599,13 +1599,13 @@ public:
template <typename SpanType, typename... Dimensions2, size_t DimCount = sizeof...(Dimensions2), template <typename SpanType, typename... Dimensions2, size_t DimCount = sizeof...(Dimensions2),
bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>> bool Enabled = (DimCount > 0), typename = std::enable_if_t<Enabled>>
constexpr multi_span<typename SpanType::value_type, Dimensions2::value...> constexpr multi_span<typename SpanType::value_type, Dimensions2::value...>
as_span(SpanType s, Dimensions2... dims) as_multi_span(SpanType s, Dimensions2... dims)
{ {
static_assert(details::is_multi_span<SpanType>::value, static_assert(details::is_multi_span<SpanType>::value,
"Variadic as_span() is for reshaping existing spans."); "Variadic as_multi_span() is for reshaping existing spans.");
using BoundsType = using BoundsType =
typename multi_span<typename SpanType::value_type, (Dimensions2::value)...>::bounds_type; typename multi_span<typename SpanType::value_type, (Dimensions2::value)...>::bounds_type;
auto tobounds = details::static_as_span_helper<BoundsType>(dims..., details::Sep{}); auto tobounds = details::static_as_multi_span_helper<BoundsType>(dims..., details::Sep{});
details::verifyBoundsReshape(s.bounds(), tobounds); details::verifyBoundsReshape(s.bounds(), tobounds);
return {s.data(), tobounds}; return {s.data(), tobounds};
} }
@ -1636,7 +1636,7 @@ multi_span<byte> as_writeable_bytes(multi_span<U, Dimensions...> s) noexcept
// on all implementations. It should be considered an experimental extension // on all implementations. It should be considered an experimental extension
// to the standard GSL interface. // to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions> template <typename U, std::ptrdiff_t... Dimensions>
constexpr auto as_span(multi_span<const byte, Dimensions...> s) noexcept -> multi_span< constexpr auto as_multi_span(multi_span<const byte, Dimensions...> s) noexcept -> multi_span<
const U, static_cast<std::ptrdiff_t>( const U, static_cast<std::ptrdiff_t>(
multi_span<const byte, Dimensions...>::bounds_type::static_size != dynamic_range multi_span<const byte, Dimensions...>::bounds_type::static_size != dynamic_range
? (static_cast<size_t>( ? (static_cast<size_t>(
@ -1661,7 +1661,7 @@ constexpr auto as_span(multi_span<const byte, Dimensions...> s) noexcept -> mult
// on all implementations. It should be considered an experimental extension // on all implementations. It should be considered an experimental extension
// to the standard GSL interface. // to the standard GSL interface.
template <typename U, std::ptrdiff_t... Dimensions> template <typename U, std::ptrdiff_t... Dimensions>
constexpr auto as_span(multi_span<byte, Dimensions...> s) noexcept constexpr auto as_multi_span(multi_span<byte, Dimensions...> s) noexcept
-> multi_span<U, narrow_cast<std::ptrdiff_t>( -> multi_span<U, narrow_cast<std::ptrdiff_t>(
multi_span<byte, Dimensions...>::bounds_type::static_size != dynamic_range multi_span<byte, Dimensions...>::bounds_type::static_size != dynamic_range
? static_cast<std::size_t>( ? static_cast<std::size_t>(
@ -1682,49 +1682,49 @@ constexpr auto as_span(multi_span<byte, Dimensions...> s) noexcept
} }
template <typename T, std::ptrdiff_t... Dimensions> template <typename T, std::ptrdiff_t... Dimensions>
constexpr auto as_span(T* const& ptr, dim<Dimensions>... args) constexpr auto as_multi_span(T* const& ptr, dim<Dimensions>... args)
-> multi_span<std::remove_all_extents_t<T>, Dimensions...> -> multi_span<std::remove_all_extents_t<T>, Dimensions...>
{ {
return {reinterpret_cast<std::remove_all_extents_t<T>*>(ptr), return {reinterpret_cast<std::remove_all_extents_t<T>*>(ptr),
details::static_as_span_helper<static_bounds<Dimensions...>>(args..., details::Sep{})}; details::static_as_multi_span_helper<static_bounds<Dimensions...>>(args..., details::Sep{})};
} }
template <typename T> template <typename T>
constexpr auto as_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 typename details::SpanArrayTraits<T, dynamic_range>::type
{ {
return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len}; return {reinterpret_cast<std::remove_all_extents_t<T>*>(arr), len};
} }
template <typename T, size_t N> template <typename T, size_t N>
constexpr auto as_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}; return {arr};
} }
template <typename T, size_t N> template <typename T, size_t N>
constexpr multi_span<const T, N> as_span(const std::array<T, N>& arr) constexpr multi_span<const T, N> as_multi_span(const std::array<T, N>& arr)
{ {
return {arr}; return {arr};
} }
template <typename T, size_t N> template <typename T, size_t N>
constexpr multi_span<const T, N> as_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, size_t N> template <typename T, size_t N>
constexpr multi_span<T, N> as_span(std::array<T, N>& arr) constexpr multi_span<T, N> as_multi_span(std::array<T, N>& arr)
{ {
return {arr}; return {arr};
} }
template <typename T> template <typename T>
constexpr multi_span<T, dynamic_range> as_span(T* begin, T* end) constexpr multi_span<T, dynamic_range> as_multi_span(T* begin, T* end)
{ {
return {begin, end}; return {begin, end};
} }
template <typename Cont> template <typename Cont>
constexpr auto as_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, !details::is_multi_span<std::decay_t<Cont>>::value,
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>>
{ {
@ -1733,13 +1733,13 @@ constexpr auto as_span(Cont& arr) -> std::enable_if_t<
} }
template <typename Cont> template <typename Cont>
constexpr auto as_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, !details::is_multi_span<std::decay_t<Cont>>::value,
multi_span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete; 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 // from basic_string which doesn't have nonconst .data() member like other contiguous containers
template <typename CharT, typename Traits, typename Allocator> template <typename CharT, typename Traits, typename Allocator>
constexpr auto as_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> -> multi_span<CharT, dynamic_range>
{ {
Expects(str.size() < PTRDIFF_MAX); Expects(str.size() < PTRDIFF_MAX);

View File

@ -680,22 +680,22 @@ SUITE(multi_span_tests)
{ {
static_assert(Bounds::static_size == 60, "static bounds is wrong size"); static_assert(Bounds::static_size == 60, "static bounds is wrong size");
} }
TEST(as_span_reshape) TEST(as_multi_span_reshape)
{ {
int a[3][4][5]; int a[3][4][5];
auto av = as_span(a); auto av = as_multi_span(a);
fn(av.bounds()); fn(av.bounds());
auto av2 = as_span(av, dim<60>()); auto av2 = as_multi_span(av, dim<60>());
auto av3 = as_span(av2, dim<3>(), dim<4>(), dim<5>()); auto av3 = as_multi_span(av2, dim<3>(), dim<4>(), dim<5>());
auto av4 = as_span(av3, dim<4>(), dim<>(3), dim<5>()); auto av4 = as_multi_span(av3, dim<4>(), dim<>(3), dim<5>());
auto av5 = as_span(av4, dim<3>(), dim<4>(), dim<5>()); auto av5 = as_multi_span(av4, dim<3>(), dim<4>(), dim<5>());
auto av6 = as_span(av5, dim<12>(), dim<>(5)); auto av6 = as_multi_span(av5, dim<12>(), dim<>(5));
fill(av6.begin(), av6.end(), 1); fill(av6.begin(), av6.end(), 1);
auto av7 = as_bytes(av6); auto av7 = as_bytes(av6);
auto av8 = as_span<int>(av7); auto av8 = as_multi_span<int>(av7);
CHECK(av8.size() == av6.size()); CHECK(av8.size() == av6.size());
for (auto i = 0; i < av8.size(); i++) { for (auto i = 0; i < av8.size(); i++) {
@ -949,12 +949,12 @@ SUITE(multi_span_tests)
{ {
{ {
int arr[10][2]; int arr[10][2];
auto s1 = as_span(arr); auto s1 = as_multi_span(arr);
multi_span<const int, dynamic_range, 2> s2 = s1; multi_span<const int, dynamic_range, 2> s2 = s1;
CHECK(s1 == s2); CHECK(s1 == s2);
multi_span<int, 20> s3 = as_span(s1, dim<>(20)); multi_span<int, 20> s3 = as_multi_span(s1, dim<>(20));
CHECK(s3 == s2 && s3 == s1); CHECK(s3 == s2 && s3 == s1);
} }
@ -1059,7 +1059,7 @@ SUITE(multi_span_tests)
TEST(basics) TEST(basics)
{ {
auto ptr = as_span(new int[10], 10); auto ptr = as_multi_span(new int[10], 10);
fill(ptr.begin(), ptr.end(), 99); fill(ptr.begin(), ptr.end(), 99);
for (int num : ptr) { for (int num : ptr) {
CHECK(num == 99); CHECK(num == 99);
@ -1071,7 +1071,7 @@ SUITE(multi_span_tests)
TEST(bounds_checks) TEST(bounds_checks)
{ {
int arr[10][2]; int arr[10][2];
auto av = as_span(arr); auto av = as_multi_span(arr);
fill(begin(av), end(av), 0); fill(begin(av), end(av), 0);
@ -1111,7 +1111,7 @@ SUITE(multi_span_tests)
{ {
auto data = new int[4][3][5]; auto data = new int[4][3][5];
auto av = as_span(data, 4); auto av = as_multi_span(data, 4);
CHECK(av.size() == 60); CHECK(av.size() == 60);
@ -1122,7 +1122,7 @@ SUITE(multi_span_tests)
CHECK(count == 34 * 60); CHECK(count == 34 * 60);
overloaded_func(av, 34); overloaded_func(av, 34);
overloaded_func(as_span(av, dim<>(4), dim<>(3), dim<>(5)), 34); overloaded_func(as_multi_span(av, dim<>(4), dim<>(3), dim<>(5)), 34);
// fixed_func(av, 34); // fixed_func(av, 34);
delete[] data; delete[] data;
@ -1137,7 +1137,7 @@ SUITE(multi_span_tests)
// size check will be done // size check will be done
auto image_view = auto image_view =
as_span(as_span(image_ptr, imgSize), dim<>(height), dim<>(width), dim<3>()); as_multi_span(as_multi_span(image_ptr, imgSize), dim<>(height), dim<>(width), dim<3>());
iota(image_view.begin(), image_view.end(), 1); iota(image_view.begin(), image_view.end(), 1);
@ -1160,12 +1160,12 @@ SUITE(multi_span_tests)
} }
} }
TEST(as_span) TEST(as_multi_span)
{ {
{ {
int* arr = new int[150]; int* arr = new int[150];
auto av = as_span(arr, dim<10>(), dim<>(3), dim<5>()); auto av = as_multi_span(arr, dim<10>(), dim<>(3), dim<5>());
fill(av.begin(), av.end(), 24); fill(av.begin(), av.end(), 24);
overloaded_func(av, 24); overloaded_func(av, 24);
@ -1173,44 +1173,44 @@ SUITE(multi_span_tests)
delete[] arr; delete[] arr;
array<int, 15> stdarr{0}; array<int, 15> stdarr{0};
auto av2 = as_span(stdarr); auto av2 = as_multi_span(stdarr);
overloaded_func(as_span(av2, dim<>(1), dim<3>(), dim<5>()), 0); overloaded_func(as_multi_span(av2, dim<>(1), dim<3>(), dim<5>()), 0);
string str = "ttttttttttttttt"; // size = 15 string str = "ttttttttttttttt"; // size = 15
auto t = str.data(); auto t = str.data();
(void) t; (void) t;
auto av3 = as_span(str); auto av3 = as_multi_span(str);
overloaded_func(as_span(av3, dim<>(1), dim<3>(), dim<5>()), 't'); overloaded_func(as_multi_span(av3, dim<>(1), dim<3>(), dim<5>()), 't');
} }
{ {
string str; string str;
multi_span<char> strspan = as_span(str); multi_span<char> strspan = as_multi_span(str);
(void) strspan; (void) strspan;
const string cstr; const string cstr;
multi_span<const char> cstrspan = as_span(cstr); multi_span<const char> cstrspan = as_multi_span(cstr);
(void) cstrspan; (void) cstrspan;
} }
{ {
int a[3][4][5]; int a[3][4][5];
auto av = as_span(a); auto av = as_multi_span(a);
const int(*b)[4][5]; const int(*b)[4][5];
b = a; b = a;
auto bv = as_span(b, 3); auto bv = as_multi_span(b, 3);
CHECK(av == bv); CHECK(av == bv);
const std::array<double, 3> arr = {0.0, 0.0, 0.0}; const std::array<double, 3> arr = {0.0, 0.0, 0.0};
auto cv = as_span(arr); auto cv = as_multi_span(arr);
(void) cv; (void) cv;
vector<float> vec(3); vector<float> vec(3);
auto dv = as_span(vec); auto dv = as_multi_span(vec);
(void) dv; (void) dv;
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
auto dv2 = as_span(std::move(vec)); auto dv2 = as_multi_span(std::move(vec));
#endif #endif
} }
} }
@ -1258,7 +1258,7 @@ SUITE(multi_span_tests)
CHECK(av[i] == 4); CHECK(av[i] == 4);
auto av2 = as_span(av, dim<4>(), dim<>(2)); auto av2 = as_multi_span(av, dim<4>(), dim<>(2));
ptrdiff_t a2[2] = {0, 1}; ptrdiff_t a2[2] = {0, 1};
index<2> i2 = a2; index<2> i2 = a2;
@ -1486,21 +1486,21 @@ SUITE(multi_span_tests)
arr[i] = i; arr[i] = i;
} }
auto av = as_span(arr, size); auto av = as_multi_span(arr, size);
// first bound is dynamic // first bound is dynamic
{ {
multi_span<int, dynamic_range, 2> av2 = as_span(av, dim<>(height), dim<>(width)); multi_span<int, dynamic_range, 2> av2 = as_multi_span(av, dim<>(height), dim<>(width));
iterate_second_column(av2); iterate_second_column(av2);
} }
// second bound is dynamic // second bound is dynamic
{ {
multi_span<int, 4, dynamic_range> av2 = as_span(av, dim<>(height), dim<>(width)); multi_span<int, 4, dynamic_range> av2 = as_multi_span(av, dim<>(height), dim<>(width));
iterate_second_column(av2); iterate_second_column(av2);
} }
// both bounds are dynamic // both bounds are dynamic
{ {
multi_span<int, dynamic_range, dynamic_range> av2 = as_span(av, dim<>(height), dim<>(width)); multi_span<int, dynamic_range, dynamic_range> av2 = as_multi_span(av, dim<>(height), dim<>(width));
iterate_second_column(av2); iterate_second_column(av2);
} }
@ -1521,7 +1521,7 @@ SUITE(multi_span_tests)
CHECK_THROW(av1[10][3][4], fail_fast); CHECK_THROW(av1[10][3][4], fail_fast);
multi_span<const double, dynamic_range, 6, 4> av2 = as_span(av1, dim<>(5), dim<6>(), dim<4>()); multi_span<const double, dynamic_range, 6, 4> av2 = as_multi_span(av1, dim<>(5), dim<6>(), dim<4>());
(void) av2; (void) av2;
} }
@ -1562,13 +1562,13 @@ SUITE(multi_span_tests)
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
{ {
multi_span<int, dynamic_range> av = arr; multi_span<int, dynamic_range> av = arr;
multi_span<int, 2, 1> av2 = av.as_span(dim<2>(), dim<2>()); multi_span<int, 2, 1> av2 = av.as_multi_span(dim<2>(), dim<2>());
} }
#endif #endif
{ {
multi_span<int, dynamic_range> av = arr; multi_span<int, dynamic_range> av = arr;
multi_span<int, 2, 1> av2 = as_span(av, dim<>(2), dim<>(2)); multi_span<int, 2, 1> av2 = as_multi_span(av, dim<>(2), dim<>(2));
auto workaround_macro = [&]() { return av2[{1, 0}] == 2; }; auto workaround_macro = [&]() { return av2[{1, 0}] == 2; };
CHECK(workaround_macro()); CHECK(workaround_macro());
} }

View File

@ -39,7 +39,7 @@ SUITE(strided_span_tests)
{ {
int a[30][4][5]; int a[30][4][5];
auto av = as_span(a); auto av = as_multi_span(a);
auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2}); auto sub = av.section({15, 0, 0}, gsl::index<3>{2, 2, 2});
auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1}); auto subsub = sub.section({1, 0, 0}, gsl::index<3>{1, 1, 1});
(void)subsub; (void)subsub;
@ -49,7 +49,7 @@ SUITE(strided_span_tests)
{ {
std::vector<int> data(5 * 10); std::vector<int> data(5 * 10);
std::iota(begin(data), end(data), 0); std::iota(begin(data), end(data), 0);
const multi_span<int, 5, 10> av = as_span(multi_span<int>{data}, dim<5>(), dim<10>()); const multi_span<int, 5, 10> av = as_multi_span(multi_span<int>{data}, dim<5>(), dim<10>());
strided_span<int, 2> av_section_1 = av.section({ 1, 2 }, { 3, 4 }); strided_span<int, 2> av_section_1 = av.section({ 1, 2 }, { 3, 4 });
CHECK((av_section_1[{0, 0}] == 12)); CHECK((av_section_1[{0, 0}] == 12));
@ -258,7 +258,7 @@ SUITE(strided_span_tests)
{ {
std::vector<int> data(5 * 10); std::vector<int> data(5 * 10);
std::iota(begin(data), end(data), 0); std::iota(begin(data), end(data), 0);
const multi_span<int, 5, 10> src = as_span(multi_span<int>{data}, dim<5>(), dim<10>()); const multi_span<int, 5, 10> src = as_multi_span(multi_span<int>{data}, dim<5>(), dim<10>());
const strided_span<int, 2> sav{ src, {{5, 10}, {10, 1}} }; const strided_span<int, 2> sav{ src, {{5, 10}, {10, 1}} };
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
@ -413,18 +413,18 @@ SUITE(strided_span_tests)
strided_span<int, 1> sav2{ arr, { 1,1,1 } }; strided_span<int, 1> sav2{ arr, { 1,1,1 } };
strided_span<int, 1> sav3{ av, { 1 } }; strided_span<int, 1> sav3{ av, { 1 } };
strided_span<int, 1> sav4{ av, { 1,1,1 } }; strided_span<int, 1> sav4{ av, { 1,1,1 } };
strided_span<int, 2> sav5{ av.as_span(dim<2>(), dim<2>()), { 1 } }; strided_span<int, 2> sav5{ av.as_multi_span(dim<2>(), dim<2>()), { 1 } };
strided_span<int, 2> sav6{ av.as_span(dim<2>(), dim<2>()), { 1,1,1 } }; strided_span<int, 2> sav6{ av.as_multi_span(dim<2>(), dim<2>()), { 1,1,1 } };
strided_span<int, 2> sav7{ av.as_span(dim<2>(), dim<2>()), { { 1,1 },{ 1,1 },{ 1,1 } } }; strided_span<int, 2> sav7{ av.as_multi_span(dim<2>(), dim<2>()), { { 1,1 },{ 1,1 },{ 1,1 } } };
index<1> index{ 0, 1 }; index<1> index{ 0, 1 };
strided_span<int, 1> sav8{ arr,{ 1,{ 1,1 } } }; strided_span<int, 1> sav8{ arr,{ 1,{ 1,1 } } };
strided_span<int, 1> sav9{ arr,{ { 1,1 },{ 1,1 } } }; strided_span<int, 1> sav9{ arr,{ { 1,1 },{ 1,1 } } };
strided_span<int, 1> sav10{ av,{ 1,{ 1,1 } } }; strided_span<int, 1> sav10{ av,{ 1,{ 1,1 } } };
strided_span<int, 1> sav11{ av,{ { 1,1 },{ 1,1 } } }; strided_span<int, 1> sav11{ av,{ { 1,1 },{ 1,1 } } };
strided_span<int, 2> sav12{ av.as_span(dim<2>(), dim<2>()),{ { 1 },{ 1 } } }; strided_span<int, 2> sav12{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1 } } };
strided_span<int, 2> sav13{ av.as_span(dim<2>(), dim<2>()),{ { 1 },{ 1,1,1 } } }; strided_span<int, 2> sav13{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1 },{ 1,1,1 } } };
strided_span<int, 2> sav14{ av.as_span(dim<2>(), dim<2>()),{ { 1,1,1 },{ 1 } } }; strided_span<int, 2> sav14{ av.as_multi_span(dim<2>(), dim<2>()),{ { 1,1,1 },{ 1 } } };
} }
#endif #endif
} }
@ -463,7 +463,7 @@ SUITE(strided_span_tests)
// retype strided array with regular strides - from multi_span // retype strided array with regular strides - from multi_span
{ {
strided_bounds<2> bounds{ { 2, bytes.size() / 4 }, { bytes.size() / 2, 1 } }; strided_bounds<2> bounds{ { 2, bytes.size() / 4 }, { bytes.size() / 2, 1 } };
multi_span<const byte, 2, dynamic_range> bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); multi_span<const byte, 2, dynamic_range> bytes2 = as_multi_span(bytes, dim<2>(), dim<>(bytes.size() / 2));
strided_span<const byte, 2> sav2{ bytes2, bounds }; strided_span<const byte, 2> sav2{ bytes2, bounds };
strided_span<int, 2> sav3 = sav2.as_strided_span<int>(); strided_span<int, 2> sav3 = sav2.as_strided_span<int>();
CHECK(sav3[0][0] == 0); CHECK(sav3[0][0] == 0);
@ -475,7 +475,7 @@ SUITE(strided_span_tests)
// retype strided array with not enough elements - last dimension of the array is too small // retype strided array with not enough elements - last dimension of the array is too small
{ {
strided_bounds<2> bounds{ { 4,2 },{ 4, 1 } }; strided_bounds<2> bounds{ { 4,2 },{ 4, 1 } };
multi_span<const byte, 2, dynamic_range> bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); multi_span<const byte, 2, dynamic_range> bytes2 = as_multi_span(bytes, dim<2>(), dim<>(bytes.size() / 2));
strided_span<const byte, 2> sav2{ bytes2, bounds }; strided_span<const byte, 2> sav2{ bytes2, bounds };
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast); CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
} }
@ -483,7 +483,7 @@ SUITE(strided_span_tests)
// retype strided array with not enough elements - strides are too small // retype strided array with not enough elements - strides are too small
{ {
strided_bounds<2> bounds{ { 4,2 },{ 2, 1 } }; strided_bounds<2> bounds{ { 4,2 },{ 2, 1 } };
multi_span<const byte, 2, dynamic_range> bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); multi_span<const byte, 2, dynamic_range> bytes2 = as_multi_span(bytes, dim<2>(), dim<>(bytes.size() / 2));
strided_span<const byte, 2> sav2{ bytes2, bounds }; strided_span<const byte, 2> sav2{ bytes2, bounds };
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast); CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
} }
@ -491,7 +491,7 @@ SUITE(strided_span_tests)
// retype strided array with not enough elements - last dimension does not divide by the new typesize // retype strided array with not enough elements - last dimension does not divide by the new typesize
{ {
strided_bounds<2> bounds{ { 2,6 },{ 4, 1 } }; strided_bounds<2> bounds{ { 2,6 },{ 4, 1 } };
multi_span<const byte, 2, dynamic_range> bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); multi_span<const byte, 2, dynamic_range> bytes2 = as_multi_span(bytes, dim<2>(), dim<>(bytes.size() / 2));
strided_span<const byte, 2> sav2{ bytes2, bounds }; strided_span<const byte, 2> sav2{ bytes2, bounds };
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast); CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
} }
@ -499,7 +499,7 @@ SUITE(strided_span_tests)
// retype strided array with not enough elements - strides does not divide by the new typesize // retype strided array with not enough elements - strides does not divide by the new typesize
{ {
strided_bounds<2> bounds{ { 2, 1 },{ 6, 1 } }; strided_bounds<2> bounds{ { 2, 1 },{ 6, 1 } };
multi_span<const byte, 2, dynamic_range> bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); multi_span<const byte, 2, dynamic_range> bytes2 = as_multi_span(bytes, dim<2>(), dim<>(bytes.size() / 2));
strided_span<const byte, 2> sav2{ bytes2, bounds }; strided_span<const byte, 2> sav2{ bytes2, bounds };
CHECK_THROW(sav2.as_strided_span<int>(), fail_fast); CHECK_THROW(sav2.as_strided_span<int>(), fail_fast);
} }
@ -606,7 +606,7 @@ SUITE(strided_span_tests)
arr[2 * i + 1] = i; arr[2 * i + 1] = i;
} }
auto av = as_span(arr, 8); auto av = as_multi_span(arr, 8);
iterate_every_other_element(av); iterate_every_other_element(av);
delete[] arr; delete[] arr;
@ -670,22 +670,22 @@ SUITE(strided_span_tests)
} }
{ {
auto av = as_span(as_span(arr, 24), dim<3>(), dim<4>(), dim<2>()); auto av = as_multi_span(as_multi_span(arr, 24), dim<3>(), dim<4>(), dim<2>());
iterate_second_slice(av); iterate_second_slice(av);
} }
{ {
auto av = as_span(as_span(arr, 24), dim<>(3), dim<4>(), dim<2>()); auto av = as_multi_span(as_multi_span(arr, 24), dim<>(3), dim<4>(), dim<2>());
iterate_second_slice(av); iterate_second_slice(av);
} }
{ {
auto av = as_span(as_span(arr, 24), dim<3>(), dim<>(4), dim<2>()); auto av = as_multi_span(as_multi_span(arr, 24), dim<3>(), dim<>(4), dim<2>());
iterate_second_slice(av); iterate_second_slice(av);
} }
{ {
auto av = as_span(as_span(arr, 24), dim<3>(), dim<4>(), dim<>(2)); auto av = as_multi_span(as_multi_span(arr, 24), dim<3>(), dim<4>(), dim<>(2));
iterate_second_slice(av); iterate_second_slice(av);
} }
delete[] arr; delete[] arr;
@ -704,7 +704,7 @@ SUITE(strided_span_tests)
auto d1 = sizeof(int) * 12 / d2; auto d1 = sizeof(int) * 12 / d2;
// convert to 4x12 array of bytes // convert to 4x12 array of bytes
auto av = as_span(as_bytes(as_span(arr, 4)), dim<>(d1), dim<>(d2)); auto av = as_multi_span(as_bytes(as_multi_span(arr, 4)), dim<>(d1), dim<>(d2));
CHECK(av.bounds().index_bounds()[0] == 4); CHECK(av.bounds().index_bounds()[0] == 4);
CHECK(av.bounds().index_bounds()[1] == 12); CHECK(av.bounds().index_bounds()[1] == 12);