From 41517ff316f6740d8b83e5aa8af6f40b1422035e Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Wed, 4 Nov 2015 02:11:49 +0000 Subject: [PATCH] Cleaned up size_t use for ranks. Compilation fixes for non-MSVC compilers. --- include/array_view.h | 50 +++++++++++++++++++------------------- tests/array_view_tests.cpp | 5 ++-- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/include/array_view.h b/include/array_view.h index 83d9231..482666e 100644 --- a/include/array_view.h +++ b/include/array_view.h @@ -146,7 +146,7 @@ public: constexpr index operator-() const noexcept { index ret = *this; - std::transform(ret, ret + rank, ret, std::negate{}); + std::transform(ret, ret + rank, ret, std::negate{}); return ret; } @@ -266,7 +266,7 @@ namespace details template struct BoundsRanges { - using size_type = std::ptrdiff_t; + using size_type = std::ptrdiff_t; static const size_type Depth = 0; static const size_type DynamicNum = 0; static const size_type CurrentRange = 1; @@ -278,7 +278,7 @@ namespace details {} BoundsRanges (const BoundsRanges&) = default; - BoundsRanges(const size_type* const) { } + BoundsRanges(const std::ptrdiff_t* const) { } BoundsRanges() = default; @@ -312,7 +312,7 @@ namespace details template struct BoundsRanges : BoundsRanges{ using Base = BoundsRanges ; - using size_type = Base::size_type; + using size_type = std::ptrdiff_t; static const size_t Depth = Base::Depth + 1; static const size_t DynamicNum = Base::DynamicNum + 1; static const size_type CurrentRange = dynamic_range; @@ -321,7 +321,7 @@ namespace details BoundsRanges (const BoundsRanges&) = default; - BoundsRanges(const size_type* const arr) : Base(arr + 1), m_bound(*arr * this->Base::totalSize()) + BoundsRanges(const std::ptrdiff_t* const arr) : Base(arr + 1), m_bound(*arr * this->Base::totalSize()) { fail_fast_assert(0 <= *arr); } @@ -329,9 +329,9 @@ namespace details BoundsRanges() : m_bound(0) {} template - BoundsRanges(const BoundsRanges& other, bool /* firstLevel */ = true) : - Base(static_cast&>(other), false), m_bound(other.totalSize()) - {} + BoundsRanges(const BoundsRanges& other, bool /* firstLevel */ = true) : + Base(static_cast&>(other), false), m_bound(other.totalSize()) + {} template void serialize(T& arr) const @@ -386,14 +386,14 @@ namespace details struct BoundsRanges : BoundsRanges { using Base = BoundsRanges ; - using size_type = Base::size_type; + using size_type = std::ptrdiff_t; static const size_t Depth = Base::Depth + 1; static const size_t DynamicNum = Base::DynamicNum; static const size_type CurrentRange = CurRange; static const size_type TotalSize = Base::TotalSize == dynamic_range ? dynamic_range : CurrentRange * Base::TotalSize; BoundsRanges (const BoundsRanges&) = default; - BoundsRanges(const size_type* const arr) : Base(arr) { } + BoundsRanges(const std::ptrdiff_t* const arr) : Base(arr) { } BoundsRanges() = default; template @@ -469,10 +469,10 @@ namespace details template struct BoundsRangeConvertible2 : std::true_type {}; - template + template struct BoundsRangeConvertible : decltype(helpBoundsRangeConvertible(SourceType(), TargetType(), std::integral_constant::value || TargetType::CurrentRange == dynamic_range || SourceType::CurrentRange == dynamic_range)>())) + && (!LessThan::value || TargetType::CurrentRange == dynamic_range || SourceType::CurrentRange == dynamic_range)>())) {}; template struct BoundsRangeConvertible : std::true_type {}; @@ -561,7 +561,7 @@ public: constexpr static_bounds(const static_bounds& other) : m_ranges(other.m_ranges) {} - constexpr static_bounds(std::initializer_list il) : m_ranges(il.begin()) + constexpr static_bounds(std::initializer_list il) : m_ranges((const std::ptrdiff_t*)il.begin()) { fail_fast_assert((MyRanges::DynamicNum == 0 && il.size() == 1 && *il.begin() == static_size) || MyRanges::DynamicNum == il.size(), "Size of the initializer list must match the rank of the array"); fail_fast_assert(m_ranges.totalSize() <= PTRDIFF_MAX, "Size of the range is larger than the max element of the size type"); @@ -1230,7 +1230,7 @@ namespace details using size_type = typename Traits::array_view_traits::size_type; }; - template + template struct ArrayViewArrayTraits { using type = array_view; using value_type = T; @@ -1238,7 +1238,7 @@ namespace details using pointer = T*; using reference = T&; }; - template + template struct ArrayViewArrayTraits : ArrayViewArrayTraits {}; template @@ -1292,7 +1292,7 @@ namespace details struct is_array_view_oracle> : std::true_type {}; - template + template struct is_array_view_oracle> : std::true_type {}; @@ -1339,7 +1339,7 @@ public: } // default - template > + template > constexpr array_view() : Base(nullptr, bounds_type()) {} @@ -1351,15 +1351,15 @@ public: // from n-dimensions static array template , - typename = std::enable_if_t::value>> - constexpr array_view (T (&arr)[N]) : Base(arr, Helper::bounds_type()) + typename = std::enable_if_t::value>> + constexpr array_view (T (&arr)[N]) : Base(arr, typename Helper::bounds_type()) {} // from n-dimensions static array with size template , - typename = std::enable_if_t::value> + typename = std::enable_if_t::value> > - constexpr array_view(T(&arr)[N], size_type size) : Base(arr, Helper::bounds_type{size}) + constexpr array_view(T(&arr)[N], size_type size) : Base(arr, typename Helper::bounds_type{size}) { fail_fast_assert(size <= N); } @@ -1420,14 +1420,14 @@ public: // to bytes array template >::value> - constexpr auto as_bytes() const noexcept -> array_view + auto as_bytes() const noexcept -> array_view { static_assert(Enabled, "The value_type of array_view must be standarded layout"); return { reinterpret_cast(this->data()), this->bytes() }; } template >::value> - constexpr auto as_writeable_bytes() const noexcept -> array_view + auto as_writeable_bytes() const noexcept -> array_view { static_assert(Enabled, "The value_type of array_view must be standarded layout"); return { reinterpret_cast(this->data()), this->bytes() }; @@ -1435,7 +1435,7 @@ public: // from bytes array template::value, typename = std::enable_if_t> - constexpr auto as_array_view() const noexcept -> array_view(Base::bounds_type::static_size) / sizeof(U) : dynamic_range)> + constexpr auto as_array_view() const noexcept -> array_view(static_cast(Base::bounds_type::static_size) / sizeof(U)) : dynamic_range)> { static_assert(std::is_standard_layout::value && (Base::bounds_type::static_size == dynamic_range || Base::bounds_type::static_size % static_cast(sizeof(U)) == 0), "Target type must be standard layout and its size must match the byte array size"); @@ -1444,7 +1444,7 @@ public: } template::value, typename = std::enable_if_t> - constexpr auto as_array_view() const noexcept -> array_view(Base::bounds_type::static_size) / sizeof(U) : dynamic_range)> + constexpr auto as_array_view() const noexcept -> array_view(static_cast(Base::bounds_type::static_size) / sizeof(U)) : dynamic_range)> { static_assert(std::is_standard_layout::value && (Base::bounds_type::static_size == dynamic_range || Base::bounds_type::static_size % static_cast(sizeof(U)) == 0), "Target type must be standard layout and its size must match the byte array size"); diff --git a/tests/array_view_tests.cpp b/tests/array_view_tests.cpp index 8937388..d9d0a42 100644 --- a/tests/array_view_tests.cpp +++ b/tests/array_view_tests.cpp @@ -222,12 +222,13 @@ SUITE(array_view_tests) #endif } } - template void fn(Bounds& b) { static_assert(Bounds::static_size == 60, "static bounds is wrong size"); } + + template void fn(const Bounds& b) { static_assert(Bounds::static_size == 60, "static bounds is wrong size"); } TEST (array_view_reshape_test) { int a[3][4][5]; auto av = as_array_view(a); - fn(av.bounds()); + fn(av.bounds()); auto av2 = av.as_array_view(dim<60>()); auto av3 = av2.as_array_view(dim<3>(), dim<4>(), dim<5>()); auto av4 = av3.as_array_view(dim<4>(), dim<>(3), dim<5>());