diff --git a/include/span.h b/include/span.h index 31c26ad..659e116 100644 --- a/include/span.h +++ b/include/span.h @@ -1072,7 +1072,7 @@ struct dim template -class span; +class multi_span; template class strided_span; @@ -1096,7 +1096,7 @@ namespace details template struct SpanArrayTraits { - using type = span; + using type = multi_span; using value_type = T; using bounds_type = static_bounds; using pointer = T*; @@ -1161,7 +1161,7 @@ namespace details }; template - struct is_span_oracle> : std::true_type + struct is_span_oracle> : std::true_type { }; @@ -1177,12 +1177,12 @@ namespace details } template -class span +class multi_span { // TODO do we still need this? template - friend class span; + friend class multi_span; public: using bounds_type = static_bounds; @@ -1193,13 +1193,13 @@ public: using const_value_type = std::add_const_t; using pointer = std::add_pointer_t; using reference = std::add_lvalue_reference_t; - using iterator = contiguous_span_iterator; - using const_span = span; + using iterator = contiguous_span_iterator; + using const_span = multi_span; using const_iterator = contiguous_span_iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; using sliced_type = - std::conditional_t>; + std::conditional_t>; private: pointer data_; @@ -1210,36 +1210,36 @@ private: public: // default constructor - same as constructing from nullptr_t - constexpr span() noexcept : span(nullptr, bounds_type{}) + constexpr multi_span() noexcept : multi_span(nullptr, bounds_type{}) { static_assert(bounds_type::dynamic_rank != 0 || (bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0), - "Default construction of span only possible " + "Default construction of multi_span only possible " "for dynamic or fixed, zero-length spans."); } - // construct from nullptr - get an empty span - constexpr span(std::nullptr_t) noexcept : span(nullptr, bounds_type{}) + // construct from nullptr - get an empty multi_span + constexpr multi_span(std::nullptr_t) noexcept : multi_span(nullptr, bounds_type{}) { static_assert(bounds_type::dynamic_rank != 0 || (bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0), - "nullptr_t construction of span only possible " + "nullptr_t construction of multi_span only possible " "for dynamic or fixed, zero-length spans."); } // construct from nullptr with size of 0 (helps with template function calls) template ::value>> - constexpr span(std::nullptr_t, IntType size) noexcept : span(nullptr, bounds_type{}) + constexpr multi_span(std::nullptr_t, IntType size) noexcept : multi_span(nullptr, bounds_type{}) { static_assert(bounds_type::dynamic_rank != 0 || (bounds_type::dynamic_rank == 0 && bounds_type::static_size == 0), - "nullptr_t construction of span only possible " + "nullptr_t construction of multi_span only possible " "for dynamic or fixed, zero-length spans."); Expects(size == 0); } // construct from a single element - constexpr span(reference data) noexcept : span(&data, bounds_type{1}) + constexpr multi_span(reference data) noexcept : multi_span(&data, bounds_type{1}) { static_assert(bounds_type::dynamic_rank > 0 || bounds_type::static_size == 0 || bounds_type::static_size == 1, @@ -1248,13 +1248,13 @@ public: } // prevent constructing from temporaries for single-elements - constexpr span(value_type&&) = delete; + constexpr multi_span(value_type&&) = delete; // construct from pointer + length - constexpr span(pointer ptr, size_type size) noexcept : span(ptr, bounds_type{size}) {} + constexpr multi_span(pointer ptr, size_type size) noexcept : multi_span(ptr, bounds_type{size}) {} // construct from pointer + length - multidimensional - constexpr span(pointer data, bounds_type bounds) noexcept : data_(data), + constexpr multi_span(pointer data, bounds_type bounds) noexcept : data_(data), bounds_(std::move(bounds)) { Expects((bounds_.size() > 0 && data != nullptr) || bounds_.size() == 0); @@ -1264,60 +1264,60 @@ public: template ::value && details::LessThan::value>> - constexpr span(pointer begin, Ptr end) - : span(begin, details::newBoundsHelper(static_cast(end) - begin)) + constexpr multi_span(pointer begin, Ptr end) + : multi_span(begin, details::newBoundsHelper(static_cast(end) - begin)) { Expects(begin != nullptr && end != nullptr && begin <= static_cast(end)); } // construct from n-dimensions static array template > - constexpr span(T (&arr)[N]) - : span(reinterpret_cast(arr), bounds_type{typename Helper::bounds_type{}}) + constexpr multi_span(T (&arr)[N]) + : multi_span(reinterpret_cast(arr), bounds_type{typename Helper::bounds_type{}}) { static_assert( std::is_convertible::value, - "Cannot convert from source type to target span type."); + "Cannot convert from source type to target multi_span type."); static_assert(std::is_convertible::value, - "Cannot construct a span from an array with fewer elements."); + "Cannot construct a multi_span from an array with fewer elements."); } // construct from n-dimensions dynamic array (e.g. new int[m][4]) // (precedence will be lower than the 1-dimension pointer) template > - constexpr span(T* const& data, size_type size) - : span(reinterpret_cast(data), typename Helper::bounds_type{size}) + constexpr multi_span(T* const& data, size_type size) + : multi_span(reinterpret_cast(data), typename Helper::bounds_type{size}) { static_assert( std::is_convertible::value, - "Cannot convert from source type to target span type."); + "Cannot convert from source type to target multi_span type."); } // construct from std::array template - constexpr span(std::array& arr) : span(arr.data(), bounds_type{static_bounds{}}) + constexpr multi_span(std::array& arr) : multi_span(arr.data(), bounds_type{static_bounds{}}) { static_assert( std::is_convertible(*) []>::value, - "Cannot convert from source type to target span type."); + "Cannot convert from source type to target multi_span type."); static_assert(std::is_convertible, bounds_type>::value, - "You cannot construct a span from a std::array of smaller size."); + "You cannot construct a multi_span from a std::array of smaller size."); } // construct from const std::array template - constexpr span(const std::array, N>& arr) - : span(arr.data(), static_bounds()) + constexpr multi_span(const std::array, N>& arr) + : multi_span(arr.data(), static_bounds()) { static_assert(std::is_convertible>::value, - "Cannot convert from source type to target span type."); + "Cannot convert from source type to target multi_span type."); static_assert(std::is_convertible, bounds_type>::value, - "You cannot construct a span from a std::array of smaller size."); + "You cannot construct a multi_span from a std::array of smaller size."); } // prevent constructing from temporary std::array template - constexpr span(std::array&& arr) = delete; + constexpr multi_span(std::array&& arr) = delete; // construct from containers // future: could use contiguous_iterator_traits to identify only contiguous containers @@ -1329,8 +1329,8 @@ public: std::is_same().size(), *std::declval().data())>, DataType>::value>> - constexpr span(Cont& cont) - : span(static_cast(cont.data()), + constexpr multi_span(Cont& cont) + : multi_span(static_cast(cont.data()), details::newBoundsHelper(narrow_cast(cont.size()))) { } @@ -1343,33 +1343,33 @@ public: std::is_same().size(), *std::declval().data())>, DataType>::value>> - explicit constexpr span(Cont&& cont) = delete; + explicit constexpr multi_span(Cont&& cont) = delete; - // construct from a convertible span + // construct from a convertible multi_span template , typename = std::enable_if_t::value && std::is_convertible::value>> - constexpr span(span other) noexcept : data_(other.data_), + constexpr multi_span(multi_span other) noexcept : data_(other.data_), bounds_(other.bounds_) { } // trivial copy and move #ifndef GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT - constexpr span(span&&) = default; + constexpr multi_span(multi_span&&) = default; #endif - constexpr span(const span&) = default; + constexpr multi_span(const multi_span&) = default; // trivial assignment #ifndef GSL_MSVC_NO_SUPPORT_FOR_MOVE_CTOR_DEFAULT - constexpr span& operator=(span&&) = default; + constexpr multi_span& operator=(multi_span&&) = default; #endif - constexpr span& operator=(const span&) = default; + constexpr multi_span& operator=(const multi_span&) = default; - // first() - extract the first Count elements into a new span + // first() - extract the first Count elements into a new multi_span template - constexpr span first() const noexcept + constexpr multi_span first() const noexcept { static_assert(Count >= 0, "Count must be >= 0."); static_assert(bounds_type::static_size == dynamic_range || @@ -1380,16 +1380,16 @@ public: return {this->data(), Count}; } - // first() - extract the first count elements into a new span - constexpr span first(size_type count) const noexcept + // first() - extract the first count elements into a new multi_span + constexpr multi_span first(size_type count) const noexcept { Expects(count >= 0 && count <= this->size()); return {this->data(), count}; } - // last() - extract the last Count elements into a new span + // last() - extract the last Count elements into a new multi_span template - constexpr span last() const noexcept + constexpr multi_span last() const noexcept { static_assert(Count >= 0, "Count must be >= 0."); static_assert(bounds_type::static_size == dynamic_range || @@ -1400,8 +1400,8 @@ public: return {this->data() + this->size() - Count, Count}; } - // last() - extract the last count elements into a new span - constexpr span last(size_type count) const noexcept + // last() - extract the last count elements into a new multi_span + constexpr multi_span last(size_type count) const noexcept { Expects(count >= 0 && count <= this->size()); return {this->data() + this->size() - count, count}; @@ -1409,14 +1409,14 @@ public: // subspan() - create a subview of Count elements starting at Offset template - constexpr span subspan() const noexcept + constexpr multi_span subspan() const noexcept { static_assert(Count >= 0, "Count must be >= 0."); static_assert(Offset >= 0, "Offset must be >= 0."); static_assert(bounds_type::static_size == dynamic_range || ((Offset <= bounds_type::static_size) && Count <= bounds_type::static_size - Offset), - "You must describe a sub-range within bounds of the span."); + "You must describe a sub-range within bounds of the multi_span."); Expects(bounds_type::static_size != dynamic_range || (Offset <= this->size() && Count <= this->size() - Offset)); @@ -1425,7 +1425,7 @@ public: // subspan() - create a subview of count elements starting at offset // supplying dynamic_range for count will consume all available elements from offset - constexpr span subspan(size_type offset, + constexpr multi_span subspan(size_type offset, size_type count = dynamic_range) const noexcept { Expects((offset >= 0 && offset <= this->size()) && @@ -1433,7 +1433,7 @@ public: return {this->data() + offset, count == dynamic_range ? this->length() - offset : count}; } - // section - creates a non-contiguous, strided span from a contiguous one + // section - creates a non-contiguous, strided multi_span from a contiguous one constexpr strided_span section(index_type origin, index_type extents) const noexcept { @@ -1442,16 +1442,16 @@ public: strided_bounds{extents, details::make_stride(bounds())}}; } - // length of the span in elements + // length of the multi_span in elements constexpr size_type size() const noexcept { return bounds_.size(); } - // length of the span in elements + // length of the multi_span in elements constexpr size_type length() const noexcept { return this->size(); } - // length of the span in bytes + // length of the multi_span in bytes constexpr size_type size_bytes() const noexcept { return sizeof(value_type) * this->size(); } - // length of the span in bytes + // length of the multi_span in bytes constexpr size_type length_bytes() const noexcept { return this->size_bytes(); } constexpr bool empty() const noexcept { return this->size() == 0; } @@ -1537,7 +1537,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator==(const span& other) const noexcept + constexpr bool operator==(const multi_span& other) const noexcept { return bounds_.size() == other.bounds_.size() && (data_ == other.data_ || std::equal(this->begin(), this->end(), other.begin())); @@ -1546,7 +1546,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator!=(const span& other) const noexcept + constexpr bool operator!=(const multi_span& other) const noexcept { return !(*this == other); } @@ -1554,7 +1554,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator<(const span& other) const noexcept + constexpr bool operator<(const multi_span& other) const noexcept { return std::lexicographical_compare(this->begin(), this->end(), other.begin(), other.end()); } @@ -1562,7 +1562,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator<=(const span& other) const noexcept + constexpr bool operator<=(const multi_span& other) const noexcept { return !(other < *this); } @@ -1570,7 +1570,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator>(const span& other) const noexcept + constexpr bool operator>(const multi_span& other) const noexcept { return (other < *this); } @@ -1578,7 +1578,7 @@ public: template , std::remove_cv_t>::value>> - constexpr bool operator>=(const span& other) const noexcept + constexpr bool operator>=(const multi_span& other) const noexcept { return !(*this < other); } @@ -1588,57 +1588,57 @@ public: // Free functions for manipulating spans // -// reshape a span into a different dimensionality +// reshape a multi_span into a different dimensionality // DimCount and Enabled here are workarounds for a bug in MSVC 2015 template 0), typename = std::enable_if_t> -constexpr span as_span(SpanType s, +constexpr multi_span as_span(SpanType s, Dimensions2... dims) { static_assert(details::is_span::value, "Variadic as_span() is for reshaping existing spans."); using BoundsType = - typename span::bounds_type; + typename multi_span::bounds_type; auto tobounds = details::static_as_span_helper(dims..., details::Sep{}); details::verifyBoundsReshape(s.bounds(), tobounds); return {s.data(), tobounds}; } -// convert a span to a span +// convert a multi_span to a multi_span template -span as_bytes(span s) noexcept +multi_span as_bytes(multi_span s) noexcept { static_assert(std::is_trivial>::value, - "The value_type of span must be a trivial type."); + "The value_type of multi_span must be a trivial type."); return {reinterpret_cast(s.data()), s.size_bytes()}; } -// convert a span to a span (a writeable byte span) +// convert a multi_span to a multi_span (a writeable byte multi_span) // this is not currently a portable function that can be relied upon to work // on all implementations. It should be considered an experimental extension // to the standard GSL interface. template -span as_writeable_bytes(span s) noexcept +multi_span as_writeable_bytes(multi_span s) noexcept { static_assert(std::is_trivial>::value, - "The value_type of span must be a trivial type."); + "The value_type of multi_span must be a trivial type."); return {reinterpret_cast(s.data()), s.size_bytes()}; } -// convert a span to a span +// convert a multi_span to a multi_span // this is not currently a portable function that can be relied upon to work // on all implementations. It should be considered an experimental extension // to the standard GSL interface. template -constexpr auto as_span(span s) noexcept - -> span( - span::bounds_type::static_size != dynamic_range +constexpr auto as_span(multi_span s) noexcept + -> multi_span( + multi_span::bounds_type::static_size != dynamic_range ? (static_cast( - span::bounds_type::static_size) / + multi_span::bounds_type::static_size) / sizeof(U)) : dynamic_range)> { - using ConstByteSpan = span; + using ConstByteSpan = multi_span; static_assert( std::is_trivial>::value && (ConstByteSpan::bounds_type::static_size == dynamic_range || @@ -1650,19 +1650,19 @@ constexpr auto as_span(span s) noexcept s.size_bytes() / narrow_cast(sizeof(U))}; } -// convert a span to a span +// convert a multi_span to a multi_span // this is not currently a portable function that can be relied upon to work // on all implementations. It should be considered an experimental extension // to the standard GSL interface. template -constexpr auto as_span(span s) noexcept -> span< +constexpr auto as_span(multi_span s) noexcept -> multi_span< U, narrow_cast( - span::bounds_type::static_size != dynamic_range - ? static_cast(span::bounds_type::static_size) / + multi_span::bounds_type::static_size != dynamic_range + ? static_cast(multi_span::bounds_type::static_size) / sizeof(U) : dynamic_range)> { - using ByteSpan = span; + using ByteSpan = multi_span; static_assert( std::is_trivial>::value && (ByteSpan::bounds_type::static_size == dynamic_range || @@ -1676,7 +1676,7 @@ constexpr auto as_span(span s) noexcept -> span< template constexpr auto as_span(T* const& ptr, dim... args) - -> span, Dimensions...> + -> multi_span, Dimensions...> { return {reinterpret_cast*>(ptr), details::static_as_span_helper>(args..., details::Sep{})}; @@ -1696,22 +1696,22 @@ constexpr auto as_span(T (&arr)[N]) -> typename details::SpanArrayTraits:: } template -constexpr span as_span(const std::array& arr) +constexpr multi_span as_span(const std::array& arr) { return {arr}; } template -constexpr span as_span(const std::array&&) = delete; +constexpr multi_span as_span(const std::array&&) = delete; template -constexpr span as_span(std::array& arr) +constexpr multi_span as_span(std::array& arr) { return {arr}; } template -constexpr span as_span(T* begin, T* end) +constexpr multi_span as_span(T* begin, T* end) { return {begin, end}; } @@ -1719,7 +1719,7 @@ constexpr span as_span(T* begin, T* end) template constexpr auto as_span(Cont& arr) -> std::enable_if_t< !details::is_span>::value, - span, dynamic_range>> + multi_span, dynamic_range>> { Expects(arr.size() < PTRDIFF_MAX); return {arr.data(), narrow_cast(arr.size())}; @@ -1728,12 +1728,12 @@ constexpr auto as_span(Cont& arr) -> std::enable_if_t< template constexpr auto as_span(Cont&& arr) -> std::enable_if_t< !details::is_span>::value, - span, dynamic_range>> = delete; + multi_span, dynamic_range>> = delete; // from basic_string which doesn't have nonconst .data() member like other contiguous containers template constexpr auto as_span(std::basic_string& str) - -> span + -> multi_span { Expects(str.size() < PTRDIFF_MAX); return {&str[0], narrow_cast(str.size())}; @@ -1792,7 +1792,7 @@ public: bool Enabled1 = (sizeof...(Dimensions) == Rank), bool Enabled2 = std::is_convertible::value, typename Dummy = std::enable_if_t> - constexpr strided_span(span av, bounds_type bounds) + constexpr strided_span(multi_span av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds)) { } @@ -1988,7 +1988,7 @@ public: private: template - friend class span; + friend class multi_span; pointer data_; const Span* m_validator; diff --git a/include/string_span.h b/include/string_span.h index 46bf2d4..f585d3f 100644 --- a/include/string_span.h +++ b/include/string_span.h @@ -96,7 +96,7 @@ using wzstring = basic_zstring; // Will fail-fast if sentinel cannot be found before max elements are examined. // template -span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) +multi_span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) { auto cur = seq; while ((cur - seq) < max && *cur != Sentinel) ++cur; @@ -111,34 +111,34 @@ span ensure_sentinel(T* seq, std::ptrdiff_t max = PTRDIFF_MAX) // the limit of size_type. // template -inline span ensure_z(T* const & sz, std::ptrdiff_t max = PTRDIFF_MAX) +inline multi_span ensure_z(T* const & sz, std::ptrdiff_t max = PTRDIFF_MAX) { return ensure_sentinel(sz, max); } // TODO (neilmac) there is probably a better template-magic way to get the const and non-const overloads to share an implementation -inline span ensure_z(char* const& sz, std::ptrdiff_t max) +inline multi_span ensure_z(char* const& sz, std::ptrdiff_t max) { auto len = strnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } -inline span ensure_z(const char* const& sz, std::ptrdiff_t max) +inline multi_span ensure_z(const char* const& sz, std::ptrdiff_t max) { auto len = strnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } -inline span ensure_z(wchar_t* const& sz, std::ptrdiff_t max) +inline multi_span ensure_z(wchar_t* const& sz, std::ptrdiff_t max) { auto len = wcsnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); return{ sz, static_cast(len) }; } -inline span ensure_z(const wchar_t* const& sz, std::ptrdiff_t max) +inline multi_span ensure_z(const wchar_t* const& sz, std::ptrdiff_t max) { auto len = wcsnlen(sz, narrow_cast(max)); Ensures(sz[len] == 0); @@ -146,10 +146,10 @@ inline span ensure_z(const wchar_t* const& sz, std } template -span ensure_z(T(&sz)[N]) { return ensure_z(&sz[0], static_cast(N)); } +multi_span ensure_z(T(&sz)[N]) { return ensure_z(&sz[0], static_cast(N)); } template -span::type, dynamic_range> ensure_z(Cont& cont) +multi_span::type, dynamic_range> ensure_z(Cont& cont) { return ensure_z(cont.data(), static_cast(cont.length())); } @@ -228,7 +228,7 @@ public: using reference = std::add_lvalue_reference_t; using const_reference = std::add_lvalue_reference_t; using bounds_type = static_bounds; - using impl_type = span; + using impl_type = multi_span; using size_type = ptrdiff_t; using iterator = typename impl_type::iterator; @@ -323,17 +323,17 @@ public: std::is_convertible::value && std::is_convertible, bounds_type>::value> > - constexpr basic_string_span(span other) noexcept + constexpr basic_string_span(multi_span other) noexcept : span_(other) {} #else // from span - constexpr basic_string_span(span other) noexcept + constexpr basic_string_span(multi_span other) noexcept : span_(other) {} template , value_type>::value>> - constexpr basic_string_span(span, Extent> other) noexcept + constexpr basic_string_span(multi_span, Extent> other) noexcept : span_(other) {} #endif @@ -540,14 +540,14 @@ public: using zstring_type = basic_zstring; using const_zstring_type = basic_zstring; - using impl_type = span; + using impl_type = multi_span; using string_span_type = basic_string_span; - constexpr basic_zstring_span(impl_type span) noexcept - : span_(span) + constexpr basic_zstring_span(impl_type multi_span) noexcept + : span_(multi_span) { // expects a zero-terminated span - Expects(span[span.size() - 1] == '\0'); + Expects(multi_span[multi_span.size() - 1] == '\0'); } // copy diff --git a/tests/bounds_tests.cpp b/tests/bounds_tests.cpp index 0665260..ab8c5bd 100644 --- a/tests/bounds_tests.cpp +++ b/tests/bounds_tests.cpp @@ -58,7 +58,7 @@ SUITE(bounds_test) auto itr = bounds.begin(); (void)itr; #ifdef CONFIRM_COMPILATION_ERRORS - span av(nullptr, bounds); + multi_span av(nullptr, bounds); auto itr2 = av.cbegin(); diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 8b39639..0d1170d 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -43,33 +43,33 @@ SUITE(span_tests) TEST(default_constructor) { { - span s; + multi_span s; CHECK(s.length() == 0 && s.data() == nullptr); - span cs; + multi_span cs; CHECK(cs.length() == 0 && cs.data() == nullptr); } { - span s; + multi_span s; CHECK(s.length() == 0 && s.data() == nullptr); - span cs; + multi_span cs; CHECK(cs.length() == 0 && cs.data() == nullptr); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s; + multi_span s; CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile #endif } { - span s{}; + multi_span s{}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{}; + multi_span cs{}; CHECK(cs.length() == 0 && cs.data() == nullptr); } } @@ -77,41 +77,41 @@ SUITE(span_tests) TEST(from_nullptr_constructor) { { - span s = nullptr; + multi_span s = nullptr; CHECK(s.length() == 0 && s.data() == nullptr); - span cs = nullptr; + multi_span cs = nullptr; CHECK(cs.length() == 0 && cs.data() == nullptr); } { - span s = nullptr; + multi_span s = nullptr; CHECK(s.length() == 0 && s.data() == nullptr); - span cs = nullptr; + multi_span cs = nullptr; CHECK(cs.length() == 0 && cs.data() == nullptr); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s = nullptr; + multi_span s = nullptr; CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile #endif } { - span s{nullptr}; + multi_span s{nullptr}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{nullptr}; + multi_span cs{nullptr}; CHECK(cs.length() == 0 && cs.data() == nullptr); } { - span s{nullptr}; + multi_span s{nullptr}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{nullptr}; + multi_span cs{nullptr}; CHECK(cs.length() == 0 && cs.data() == nullptr); } } @@ -119,49 +119,49 @@ SUITE(span_tests) TEST(from_nullptr_length_constructor) { { - span s{nullptr, 0}; + multi_span s{nullptr, 0}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{nullptr, 0}; + multi_span cs{nullptr, 0}; CHECK(cs.length() == 0 && cs.data() == nullptr); } { - span s{nullptr, 0}; + multi_span s{nullptr, 0}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{nullptr, 0}; + multi_span cs{nullptr, 0}; CHECK(cs.length() == 0 && cs.data() == nullptr); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{nullptr, 0}; + multi_span s{nullptr, 0}; CHECK(s.length() == 1 && s.data() == nullptr); // explains why it can't compile #endif } { - auto workaround_macro = []() { span s{nullptr, 1}; }; + auto workaround_macro = []() { multi_span s{nullptr, 1}; }; CHECK_THROW(workaround_macro(), fail_fast); - auto const_workaround_macro = []() { span cs{nullptr, 1}; }; + auto const_workaround_macro = []() { multi_span cs{nullptr, 1}; }; CHECK_THROW(const_workaround_macro(), fail_fast); } { - auto workaround_macro = []() { span s{nullptr, 1}; }; + auto workaround_macro = []() { multi_span s{nullptr, 1}; }; CHECK_THROW(workaround_macro(), fail_fast); - auto const_workaround_macro = []() { span s{nullptr, 1}; }; + auto const_workaround_macro = []() { multi_span s{nullptr, 1}; }; CHECK_THROW(const_workaround_macro(), fail_fast); } { - span s{nullptr, 0}; + multi_span s{nullptr, 0}; CHECK(s.length() == 0 && s.data() == nullptr); - span cs{nullptr, 0}; + multi_span cs{nullptr, 0}; CHECK(cs.length() == 0 && cs.data() == nullptr); } } @@ -171,11 +171,11 @@ SUITE(span_tests) int i = 5; { - span s = i; + multi_span s = i; CHECK(s.length() == 1 && s.data() == &i); CHECK(s[0] == 5); - span cs = i; + multi_span cs = i; CHECK(cs.length() == 1 && cs.data() == &i); CHECK(cs[0] == 5); } @@ -183,26 +183,26 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS const j = 1; - span s = j; + multi_span s = j; #endif } { #ifdef CONFIRM_COMPILATION_ERRORS - span s = i; + multi_span s = i; CHECK(s.length() == 0 && s.data() == &i); #endif } { - span s = i; + multi_span s = i; CHECK(s.length() == 1 && s.data() == &i); CHECK(s[0] == 5); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s = i; + multi_span s = i; CHECK(s.length() == 2 && s.data() == &i); #endif } @@ -210,7 +210,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS auto get_a_temp = []() -> int { return 4; }; - auto use_a_span = [](span s) { (void) s; }; + auto use_a_span = [](multi_span s) { (void) s; }; use_a_span(get_a_temp()); #endif } @@ -221,26 +221,26 @@ SUITE(span_tests) int arr[4] = {1, 2, 3, 4}; { - span s{&arr[0], 2}; + multi_span s{&arr[0], 2}; CHECK(s.length() == 2 && s.data() == &arr[0]); CHECK(s[0] == 1 && s[1] == 2); } { - span s{&arr[0], 2}; + multi_span s{&arr[0], 2}; CHECK(s.length() == 2 && s.data() == &arr[0]); CHECK(s[0] == 1 && s[1] == 2); } { int* p = nullptr; - span s{p, 0}; + multi_span s{p, 0}; CHECK(s.length() == 0 && s.data() == nullptr); } { int* p = nullptr; - auto workaround_macro = [=]() { span s{p, 2}; }; + auto workaround_macro = [=]() { multi_span s{p, 2}; }; CHECK_THROW(workaround_macro(), fail_fast); } } @@ -250,47 +250,47 @@ SUITE(span_tests) int arr[4] = {1, 2, 3, 4}; { - span s{&arr[0], &arr[2]}; + multi_span s{&arr[0], &arr[2]}; CHECK(s.length() == 2 && s.data() == &arr[0]); CHECK(s[0] == 1 && s[1] == 2); } { - span s{&arr[0], &arr[2]}; + multi_span s{&arr[0], &arr[2]}; CHECK(s.length() == 2 && s.data() == &arr[0]); CHECK(s[0] == 1 && s[1] == 2); } { - span s{&arr[0], &arr[0]}; + multi_span s{&arr[0], &arr[0]}; CHECK(s.length() == 0 && s.data() == &arr[0]); } { - span s{&arr[0], &arr[0]}; + multi_span s{&arr[0], &arr[0]}; CHECK(s.length() == 0 && s.data() == &arr[0]); } { - auto workaround_macro = [&]() { span s{&arr[1], &arr[0]}; }; + auto workaround_macro = [&]() { multi_span s{&arr[1], &arr[0]}; }; CHECK_THROW(workaround_macro(), fail_fast); } { int* p = nullptr; - auto workaround_macro = [&]() { span s{&arr[0], p}; }; + auto workaround_macro = [&]() { multi_span s{&arr[0], p}; }; CHECK_THROW(workaround_macro(), fail_fast); } { int* p = nullptr; - auto workaround_macro = [&]() { span s{p, p}; }; + auto workaround_macro = [&]() { multi_span s{p, p}; }; CHECK_THROW(workaround_macro(), fail_fast); } { int* p = nullptr; - auto workaround_macro = [&]() { span s{&arr[0], p}; }; + auto workaround_macro = [&]() { multi_span s{&arr[0], p}; }; CHECK_THROW(workaround_macro(), fail_fast); } } @@ -300,64 +300,64 @@ SUITE(span_tests) int arr[5] = {1, 2, 3, 4, 5}; { - span s{arr}; + multi_span s{arr}; CHECK(s.length() == 5 && s.data() == &arr[0]); } { - span s{arr}; + multi_span s{arr}; CHECK(s.length() == 5 && s.data() == &arr[0]); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr}; + multi_span s{arr}; #endif } { - span s{arr}; + multi_span s{arr}; CHECK(s.length() == 0 && s.data() == &arr[0]); } int arr2d[2][3] = {1, 2, 3, 4, 5, 6}; { - span s{arr2d}; + multi_span s{arr2d}; CHECK(s.length() == 6 && s.data() == &arr2d[0][0]); CHECK(s[0] == 1 && s[5] == 6); } { - span s{arr2d}; + multi_span s{arr2d}; CHECK(s.length() == 0 && s.data() == &arr2d[0][0]); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr2d}; + multi_span s{arr2d}; #endif } { - span s{arr2d}; + multi_span s{arr2d}; CHECK(s.length() == 6 && s.data() == &arr2d[0][0]); CHECK(s[0] == 1 && s[5] == 6); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr2d}; + multi_span s{arr2d}; #endif } { - span s{arr2d[0]}; + multi_span s{arr2d[0]}; CHECK(s.length() == 1 && s.data() == &arr2d[0]); } { - span s{arr2d}; + multi_span s{arr2d}; CHECK(s.length() == 6 && s.data() == &arr2d[0][0]); auto workaround_macro = [&]() { return s[{1, 2}] == 6; }; CHECK(workaround_macro()); @@ -365,48 +365,48 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr2d}; + multi_span s{arr2d}; #endif } int arr3d[2][3][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; { - span s{arr3d}; + multi_span s{arr3d}; CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]); CHECK(s[0] == 1 && s[11] == 12); } { - span s{arr3d}; + multi_span s{arr3d}; CHECK(s.length() == 0 && s.data() == &arr3d[0][0][0]); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr3d}; + multi_span s{arr3d}; #endif } { - span s{arr3d}; + multi_span s{arr3d}; CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]); CHECK(s[0] == 1 && s[5] == 6); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr3d}; + multi_span s{arr3d}; #endif } { - span s{arr3d[0]}; + multi_span s{arr3d[0]}; CHECK(s.length() == 1 && s.data() == &arr3d[0]); } { - span s{arr3d}; + multi_span s{arr3d}; CHECK(s.length() == 12 && s.data() == &arr3d[0][0][0]); auto workaround_macro = [&]() { return s[{2, 1, 0}] == 11; }; CHECK(workaround_macro()); @@ -414,7 +414,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr3d}; + multi_span s{arr3d}; #endif } } @@ -424,23 +424,23 @@ SUITE(span_tests) double(*arr)[3][4] = new double[100][3][4]; { - span s(arr, 10); + multi_span s(arr, 10); CHECK(s.length() == 120 && s.data() == &arr[0][0][0]); CHECK_THROW(s[10][3][4], fail_fast); } { - span s(arr, 10); + multi_span s(arr, 10); CHECK(s.length() == 120 && s.data() == &arr[0][0][0]); } { - span s(arr, 10); + multi_span s(arr, 10); CHECK(s.length() == 120 && s.data() == &arr[0][0][0]); } { - span s(arr, 0); + multi_span s(arr, 0); CHECK(s.length() == 0 && s.data() == &arr[0][0][0]); } @@ -452,54 +452,54 @@ SUITE(span_tests) std::array arr = {1, 2, 3, 4}; { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); - span cs{arr}; + multi_span cs{arr}; CHECK(cs.size() == narrow_cast(arr.size()) && cs.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); - span cs{arr}; + multi_span cs{arr}; CHECK(cs.size() == narrow_cast(arr.size()) && cs.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == 2 && s.data() == arr.data()); - span cs{arr}; + multi_span cs{arr}; CHECK(cs.size() == 2 && cs.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == 0 && s.data() == arr.data()); - span cs{arr}; + multi_span cs{arr}; CHECK(cs.size() == 0 && cs.data() == arr.data()); } // TODO This is currently an unsupported scenario. We will come back to it as we revise // the multidimensional interface and what transformations between dimensionality look like //{ - // span s{arr}; + // multi_span s{arr}; // CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); //} { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr}; + multi_span s{arr}; #endif } { #ifdef CONFIRM_COMPILATION_ERRORS auto get_an_array = []() { return std::array{1, 2, 3, 4}; }; - auto take_a_span = [](span s) { (void) s; }; + auto take_a_span = [](multi_span s) { (void) s; }; // try to take a temporary std::array take_a_span(get_an_array()); #endif @@ -511,42 +511,42 @@ SUITE(span_tests) const std::array arr = {1, 2, 3, 4}; { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == 2 && s.data() == arr.data()); } { - span s{arr}; + multi_span s{arr}; CHECK(s.size() == 0 && s.data() == arr.data()); } // TODO This is currently an unsupported scenario. We will come back to it as we revise // the multidimensional interface and what transformations between dimensionality look like //{ - // span s{arr}; + // multi_span s{arr}; // CHECK(s.size() == narrow_cast(arr.size()) && s.data() == arr.data()); //} { #ifdef CONFIRM_COMPILATION_ERRORS - span s{arr}; + multi_span s{arr}; #endif } { #ifdef CONFIRM_COMPILATION_ERRORS auto get_an_array = []() -> const std::array { return {1, 2, 3, 4}; }; - auto take_a_span = [](span s) { (void) s; }; + auto take_a_span = [](multi_span s) { (void) s; }; // try to take a temporary std::array take_a_span(get_an_array()); #endif @@ -559,10 +559,10 @@ SUITE(span_tests) const std::vector cv = v; { - span s{v}; + multi_span s{v}; CHECK(s.size() == narrow_cast(v.size()) && s.data() == v.data()); - span cs{v}; + multi_span cs{v}; CHECK(cs.size() == narrow_cast(v.size()) && cs.data() == v.data()); } @@ -571,18 +571,18 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS - span s{str}; + multi_span s{str}; CHECK(s.size() == narrow_cast(str.size()) && s.data() == str.data()); #endif - span cs{str}; + multi_span cs{str}; CHECK(cs.size() == narrow_cast(str.size()) && cs.data() == str.data()); } { #ifdef CONFIRM_COMPILATION_ERRORS - span s{cstr}; + multi_span s{cstr}; #endif - span cs{cstr}; + multi_span cs{cstr}; CHECK(cs.size() == narrow_cast(cstr.size()) && cs.data() == cstr.data()); } @@ -590,7 +590,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS auto get_temp_vector = []() -> std::vector { return {}; }; - auto use_span = [](span s) { (void) s; }; + auto use_span = [](multi_span s) { (void) s; }; use_span(get_temp_vector()); #endif } @@ -598,7 +598,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS auto get_temp_string = []() -> std::string { return {}; }; - auto use_span = [](span s) { (void) s; }; + auto use_span = [](multi_span s) { (void) s; }; use_span(get_temp_string()); #endif } @@ -606,7 +606,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS auto get_temp_vector = []() -> const std::vector { return {}; }; - auto use_span = [](span s) { (void) s; }; + auto use_span = [](multi_span s) { (void) s; }; use_span(get_temp_vector()); #endif } @@ -614,7 +614,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS auto get_temp_string = []() -> const std::string { return {}; }; - auto use_span = [](span s) { (void) s; }; + auto use_span = [](multi_span s) { (void) s; }; use_span(get_temp_string()); #endif } @@ -622,7 +622,7 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS std::map m; - span s{m}; + multi_span s{m}; #endif } } @@ -630,9 +630,9 @@ SUITE(span_tests) TEST(from_convertible_span_constructor) { #ifdef CONFIRM_COMPILATION_ERRORS - span av1(nullptr, b1); + multi_span av1(nullptr, b1); - auto f = [&]() { span av1(nullptr); }; + auto f = [&]() { multi_span av1(nullptr); }; CHECK_THROW(f(), fail_fast); #endif @@ -641,34 +641,34 @@ SUITE(span_tests) b12 = b11; b11 = b12; - span av1 = nullptr; - span av2(av1); - span av2(av1); + multi_span av1 = nullptr; + multi_span av2(av1); + multi_span av2(av1); #endif - span avd; + multi_span avd; #ifdef CONFIRM_COMPILATION_ERRORS - span avb = avd; + multi_span avb = avd; #endif - span avcd = avd; + multi_span avcd = avd; (void) avcd; } TEST(copy_move_and_assignment) { - span s1; + multi_span s1; CHECK(s1.empty()); int arr[] = {3, 4, 5}; - span s2 = arr; + multi_span s2 = arr; CHECK(s2.length() == 3 && s2.data() == &arr[0]); s2 = s1; CHECK(s2.empty()); - auto get_temp_span = [&]() -> span { return {&arr[1], 2}; }; - auto use_span = [&](span s) { CHECK(s.length() == 2 && s.data() == &arr[1]); }; + auto get_temp_span = [&]() -> multi_span { return {&arr[1], 2}; }; + auto use_span = [&](multi_span s) { CHECK(s.length() == 2 && s.data() == &arr[1]); }; use_span(get_temp_span()); s1 = get_temp_span(); @@ -708,28 +708,28 @@ SUITE(span_tests) int arr[5] = {1, 2, 3, 4, 5}; { - span av = arr; + multi_span av = arr; CHECK((av.first<2>().bounds() == static_bounds<2>())); CHECK(av.first<2>().length() == 2); CHECK(av.first(2).length() == 2); } { - span av = arr; + multi_span av = arr; CHECK((av.first<0>().bounds() == static_bounds<0>())); CHECK(av.first<0>().length() == 0); CHECK(av.first(0).length() == 0); } { - span av = arr; + multi_span av = arr; CHECK((av.first<5>().bounds() == static_bounds<5>())); CHECK(av.first<5>().length() == 5); CHECK(av.first(5).length() == 5); } { - span av = arr; + multi_span av = arr; #ifdef CONFIRM_COMPILATION_ERRORS CHECK(av.first<6>().bounds() == static_bounds<6>()); CHECK(av.first<6>().length() == 6); @@ -739,7 +739,7 @@ SUITE(span_tests) } { - span av; + multi_span av; CHECK((av.first<0>().bounds() == static_bounds<0>())); CHECK(av.first<0>().length() == 0); CHECK(av.first(0).length() == 0); @@ -751,28 +751,28 @@ SUITE(span_tests) int arr[5] = {1, 2, 3, 4, 5}; { - span av = arr; + multi_span av = arr; CHECK((av.last<2>().bounds() == static_bounds<2>())); CHECK(av.last<2>().length() == 2); CHECK(av.last(2).length() == 2); } { - span av = arr; + multi_span av = arr; CHECK((av.last<0>().bounds() == static_bounds<0>())); CHECK(av.last<0>().length() == 0); CHECK(av.last(0).length() == 0); } { - span av = arr; + multi_span av = arr; CHECK((av.last<5>().bounds() == static_bounds<5>())); CHECK(av.last<5>().length() == 5); CHECK(av.last(5).length() == 5); } { - span av = arr; + multi_span av = arr; #ifdef CONFIRM_COMPILATION_ERRORS CHECK((av.last<6>().bounds() == static_bounds<6>())); CHECK(av.last<6>().length() == 6); @@ -781,7 +781,7 @@ SUITE(span_tests) } { - span av; + multi_span av; CHECK((av.last<0>().bounds() == static_bounds<0>())); CHECK(av.last<0>().length() == 0); CHECK(av.last(0).length() == 0); @@ -793,7 +793,7 @@ SUITE(span_tests) int arr[5] = {1, 2, 3, 4, 5}; { - span av = arr; + multi_span av = arr; CHECK((av.subspan<2, 2>().bounds() == static_bounds<2>())); CHECK((av.subspan<2, 2>().length() == 2)); CHECK(av.subspan(2, 2).length() == 2); @@ -801,14 +801,14 @@ SUITE(span_tests) } { - span av = arr; + multi_span av = arr; CHECK((av.subspan<0, 0>().bounds() == static_bounds<0>())); CHECK((av.subspan<0, 0>().length() == 0)); CHECK(av.subspan(0, 0).length() == 0); } { - span av = arr; + multi_span av = arr; CHECK((av.subspan<0, 5>().bounds() == static_bounds<5>())); CHECK((av.subspan<0, 5>().length() == 5)); CHECK(av.subspan(0, 5).length() == 5); @@ -817,7 +817,7 @@ SUITE(span_tests) } { - span av = arr; + multi_span av = arr; CHECK((av.subspan<5, 0>().bounds() == static_bounds<0>())); CHECK((av.subspan<5, 0>().length() == 0)); CHECK(av.subspan(5, 0).length() == 0); @@ -825,7 +825,7 @@ SUITE(span_tests) } { - span av; + multi_span av; CHECK((av.subspan<0, 0>().bounds() == static_bounds<0>())); CHECK((av.subspan<0, 0>().length() == 0)); CHECK(av.subspan(0, 0).length() == 0); @@ -833,13 +833,13 @@ SUITE(span_tests) } { - span av; + multi_span av; CHECK(av.subspan(0).length() == 0); CHECK_THROW(av.subspan(1).length(), fail_fast); } { - span av = arr; + multi_span av = arr; CHECK(av.subspan(0).length() == 5); CHECK(av.subspan(1).length() == 4); CHECK(av.subspan(4).length() == 1); @@ -850,7 +850,7 @@ SUITE(span_tests) } { - span av = arr; + multi_span av = arr; CHECK(av.subspan(0).length() == 5); CHECK(av.subspan(1).length() == 4); CHECK(av.subspan(4).length() == 1); @@ -866,18 +866,18 @@ SUITE(span_tests) int arr[2] = {1, 2}; { - span s; + multi_span s; CHECK(s.rank() == 1); } { - span s = arr; + multi_span s = arr; CHECK(s.rank() == 1); } int arr2d[1][1] = {}; { - span s = arr2d; + multi_span s = arr2d; CHECK(s.rank() == 2); } } @@ -885,7 +885,7 @@ SUITE(span_tests) TEST(extent) { { - span s; + multi_span s; CHECK(s.extent() == 0); CHECK(s.extent(0) == 0); CHECK_THROW(s.extent(1), fail_fast); @@ -895,7 +895,7 @@ SUITE(span_tests) } { - span s; + multi_span s; CHECK(s.extent() == 0); CHECK(s.extent(0) == 0); CHECK_THROW(s.extent(1), fail_fast); @@ -904,7 +904,7 @@ SUITE(span_tests) { int arr2d[1][2] = {}; - span s = arr2d; + multi_span s = arr2d; CHECK(s.extent() == 1); CHECK(s.extent<0>() == 1); CHECK(s.extent<1>() == 2); @@ -916,7 +916,7 @@ SUITE(span_tests) { int arr2d[1][2] = {}; - span s = arr2d; + multi_span s = arr2d; CHECK(s.extent() == 0); CHECK(s.extent<0>() == 0); CHECK(s.extent<1>() == 2); @@ -931,7 +931,7 @@ SUITE(span_tests) int arr[4] = {1, 2, 3, 4}; { - span s = arr; + multi_span s = arr; CHECK(s(0) == 1); CHECK_THROW(s(5), fail_fast); } @@ -939,7 +939,7 @@ SUITE(span_tests) int arr2d[2][3] = {1, 2, 3, 4, 5, 6}; { - span s = arr2d; + multi_span s = arr2d; CHECK(s(0, 0) == 1); CHECK(s(1, 2) == 6); } @@ -950,11 +950,11 @@ SUITE(span_tests) { int arr[10][2]; auto s1 = as_span(arr); - span s2 = s1; + multi_span s2 = s1; CHECK(s1 == s2); - span s3 = as_span(s1, dim<>(20)); + multi_span s3 = as_span(s1, dim<>(20)); CHECK(s3 == s2 && s3 == s1); } @@ -978,8 +978,8 @@ SUITE(span_tests) { int arr[] = {2, 1}; // bigger - span s1 = nullptr; - span s2 = arr; + multi_span s1 = nullptr; + multi_span s2 = arr; CHECK(s1 != s2); CHECK(s2 != s1); @@ -998,8 +998,8 @@ SUITE(span_tests) { int arr1[] = {1, 2}; int arr2[] = {1, 2}; - span s1 = arr1; - span s2 = arr2; + multi_span s1 = arr1; + multi_span s2 = arr2; CHECK(s1 == s2); CHECK(!(s1 != s2)); @@ -1018,8 +1018,8 @@ SUITE(span_tests) { int arr[] = {1, 2, 3}; - span s1 = {&arr[0], 2}; // shorter - span s2 = arr; // longer + multi_span s1 = {&arr[0], 2}; // shorter + multi_span s2 = arr; // longer CHECK(s1 != s2); CHECK(s2 != s1); @@ -1039,8 +1039,8 @@ SUITE(span_tests) int arr1[] = {1, 2}; // smaller int arr2[] = {2, 1}; // bigger - span s1 = arr1; - span s2 = arr2; + multi_span s1 = arr1; + multi_span s2 = arr2; CHECK(s1 != s2); CHECK(s2 != s1); @@ -1086,21 +1086,21 @@ SUITE(span_tests) CHECK_THROW((av[{10, 2}]), fail_fast); } - void overloaded_func(span exp, int expected_value) + void overloaded_func(multi_span exp, int expected_value) { for (auto val : exp) { CHECK(val == expected_value); } } - void overloaded_func(span exp, char expected_value) + void overloaded_func(multi_span exp, char expected_value) { for (auto val : exp) { CHECK(val == expected_value); } } - void fixed_func(span exp, int expected_value) + void fixed_func(multi_span exp, int expected_value) { for (auto val : exp) { CHECK(val == expected_value); @@ -1185,10 +1185,10 @@ SUITE(span_tests) { string str; - span strspan = as_span(str); + multi_span strspan = as_span(str); (void) strspan; const string cstr; - span cstrspan = as_span(cstr); + multi_span cstrspan = as_span(cstr); (void) cstrspan; } @@ -1218,7 +1218,7 @@ SUITE(span_tests) TEST(empty_spans) { { - span empty_av(nullptr); + multi_span empty_av(nullptr); CHECK(empty_av.bounds().index_bounds() == index<1>{0}); CHECK_THROW(empty_av[0], fail_fast); @@ -1231,7 +1231,7 @@ SUITE(span_tests) } { - span empty_av = {}; + multi_span empty_av = {}; CHECK(empty_av.bounds().index_bounds() == index<1>{0}); CHECK_THROW(empty_av[0], fail_fast); CHECK_THROW(empty_av.begin()[0], fail_fast); @@ -1251,7 +1251,7 @@ SUITE(span_tests) arr[2 * i + 1] = i; } - span av(arr, 8); + multi_span av(arr, 8); ptrdiff_t a[1] = {0}; index<1> i = a; @@ -1395,7 +1395,7 @@ SUITE(span_tests) } } - void iterate_second_column(span av) + void iterate_second_column(multi_span av) { auto length = av.size() / 2; @@ -1456,22 +1456,22 @@ SUITE(span_tests) // static bounds { - span av = arr; + multi_span av = arr; iterate_second_column(av); } // first bound is dynamic { - span av = arr; + multi_span av = arr; iterate_second_column(av); } // second bound is dynamic { - span av = arr; + multi_span av = arr; iterate_second_column(av); } // both bounds are dynamic { - span av = arr; + multi_span av = arr; iterate_second_column(av); } } @@ -1490,17 +1490,17 @@ SUITE(span_tests) // first bound is dynamic { - span av2 = as_span(av, dim<>(height), dim<>(width)); + multi_span av2 = as_span(av, dim<>(height), dim<>(width)); iterate_second_column(av2); } // second bound is dynamic { - span av2 = as_span(av, dim<>(height), dim<>(width)); + multi_span av2 = as_span(av, dim<>(height), dim<>(width)); iterate_second_column(av2); } // both bounds are dynamic { - span av2 = as_span(av, dim<>(height), dim<>(width)); + multi_span av2 = as_span(av, dim<>(height), dim<>(width)); iterate_second_column(av2); } @@ -1510,7 +1510,7 @@ SUITE(span_tests) TEST(span_structure_size) { double(*arr)[3][4] = new double[100][3][4]; - span av1(arr, 10); + multi_span av1(arr, 10); struct EffectiveStructure { @@ -1521,7 +1521,7 @@ SUITE(span_tests) CHECK_THROW(av1[10][3][4], fail_fast); - span av2 = as_span(av1, dim<>(5), dim<6>(), dim<4>()); + multi_span av2 = as_span(av1, dim<>(5), dim<6>(), dim<4>()); (void) av2; } @@ -1529,46 +1529,46 @@ SUITE(span_tests) { int arr[] = {1, 2, 3, 4}; - // converting to an span from an equal size array is ok - span av4 = arr; + // converting to an multi_span from an equal size array is ok + multi_span av4 = arr; CHECK(av4.length() == 4); // converting to dynamic_range a_v is always ok { - span av = av4; + multi_span av = av4; (void) av; } { - span av = arr; + multi_span av = arr; (void) av; } -// initialization or assignment to static span that REDUCES size is NOT ok +// initialization or assignment to static multi_span that REDUCES size is NOT ok #ifdef CONFIRM_COMPILATION_ERRORS { - span av2 = arr; + multi_span av2 = arr; } { - span av2 = av4; + multi_span av2 = av4; } #endif { - span av = arr; - span av2 = av; + multi_span av = arr; + multi_span av2 = av; (void) av2; } #ifdef CONFIRM_COMPILATION_ERRORS { - span av = arr; - span av2 = av.as_span(dim<2>(), dim<2>()); + multi_span av = arr; + multi_span av2 = av.as_span(dim<2>(), dim<2>()); } #endif { - span av = arr; - span av2 = as_span(av, dim<>(2), dim<>(2)); + multi_span av = arr; + multi_span av2 = as_span(av, dim<>(2), dim<>(2)); auto workaround_macro = [&]() { return av2[{1, 0}] == 2; }; CHECK(workaround_macro()); } @@ -1577,45 +1577,45 @@ SUITE(span_tests) // you can convert statically { - span av2 = {arr, 2}; + multi_span av2 = {arr, 2}; (void) av2; } { - span av2 = av4.first<1>(); + multi_span av2 = av4.first<1>(); (void) av2; } // ...or dynamically { - // NB: implicit conversion to span from span - span av2 = av4.first(1); + // NB: implicit conversion to multi_span from multi_span + multi_span av2 = av4.first(1); (void) av2; } - // initialization or assignment to static span that requires size INCREASE is not ok. + // initialization or assignment to static multi_span that requires size INCREASE is not ok. int arr2[2] = {1, 2}; #ifdef CONFIRM_COMPILATION_ERRORS { - span av4 = arr2; + multi_span av4 = arr2; } { - span av2 = arr2; - span av4 = av2; + multi_span av2 = arr2; + multi_span av4 = av2; } #endif { auto f = [&]() { - span av9 = {arr2, 2}; + multi_span av9 = {arr2, 2}; (void) av9; }; CHECK_THROW(f(), fail_fast); } // this should fail - we are trying to assign a small dynamic a_v to a fixed_size larger one - span av = arr2; + multi_span av = arr2; auto f = [&]() { - span av2 = av; + multi_span av2 = av; (void) av2; }; CHECK_THROW(f(), fail_fast); @@ -1628,13 +1628,13 @@ SUITE(span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS // you should not be able to get writeable bytes for const objects - span av = a; + multi_span av = a; auto wav = av.as_writeable_bytes(); #endif } { - span av; + multi_span av; auto wav = as_writeable_bytes(av); CHECK(wav.length() == av.length()); CHECK(wav.length() == 0); @@ -1642,7 +1642,7 @@ SUITE(span_tests) } { - span av = a; + multi_span av = a; auto wav = as_writeable_bytes(av); CHECK(wav.data() == (byte*) &a[0]); CHECK(wav.length() == sizeof(a)); @@ -1654,7 +1654,7 @@ SUITE(span_tests) int a[] = {1, 2, 3, 4}; { - span av = a; + multi_span av = a; auto wav = as_writeable_bytes(av); for (auto& b : wav) { b = byte(0); @@ -1665,7 +1665,7 @@ SUITE(span_tests) } { - span av = a; + multi_span av = a; for (auto& n : av) { n = 1; } diff --git a/tests/strided_span_tests.cpp b/tests/strided_span_tests.cpp index 0fbf1d7..8b96ddf 100644 --- a/tests/strided_span_tests.cpp +++ b/tests/strided_span_tests.cpp @@ -49,7 +49,7 @@ SUITE(strided_span_tests) { std::vector data(5 * 10); std::iota(begin(data), end(data), 0); - const span av = as_span(span{data}, dim<5>(), dim<10>()); + const multi_span av = as_span(multi_span{data}, dim<5>(), dim<10>()); strided_span av_section_1 = av.section({ 1, 2 }, { 3, 4 }); CHECK((av_section_1[{0, 0}] == 12)); @@ -87,13 +87,13 @@ SUITE(strided_span_tests) CHECK((sav3[{0, 0}] == 1 && sav3[{0, 1}] == 3 && sav3[{1, 0}] == 7)); } - // Check span constructor + // Check multi_span constructor { int arr[] = { 1, 2 }; // From non-cv-qualified source { - const span src = arr; + const multi_span src = arr; strided_span sav{ src, {2, 1} }; CHECK(sav.bounds().index_bounds() == index<1>{ 2 }); @@ -102,9 +102,9 @@ SUITE(strided_span_tests) #if _MSC_VER > 1800 //strided_span sav_c{ {src}, {2, 1} }; - strided_span sav_c{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} }; #else - strided_span sav_c{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_c{ multi_span{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_c.bounds().strides() == index<1>{ 1 }); @@ -113,7 +113,7 @@ SUITE(strided_span_tests) #if _MSC_VER > 1800 strided_span sav_v{ src, {2, 1} }; #else - strided_span sav_v{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_v{ multi_span{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_v.bounds().strides() == index<1>{ 1 }); @@ -122,7 +122,7 @@ SUITE(strided_span_tests) #if _MSC_VER > 1800 strided_span sav_cv{ src, {2, 1} }; #else - strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_cv.bounds().strides() == index<1>{ 1 }); @@ -131,7 +131,7 @@ SUITE(strided_span_tests) // From const-qualified source { - const span src{ arr }; + const multi_span src{ arr }; strided_span sav_c{ src, {2, 1} }; CHECK(sav_c.bounds().index_bounds() == index<1>{ 2 }); @@ -141,7 +141,7 @@ SUITE(strided_span_tests) #if _MSC_VER > 1800 strided_span sav_cv{ src, {2, 1} }; #else - strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 }); @@ -151,7 +151,7 @@ SUITE(strided_span_tests) // From volatile-qualified source { - const span src{ arr }; + const multi_span src{ arr }; strided_span sav_v{ src, {2, 1} }; CHECK(sav_v.bounds().index_bounds() == index<1>{ 2 }); @@ -161,7 +161,7 @@ SUITE(strided_span_tests) #if _MSC_VER > 1800 strided_span sav_cv{ src, {2, 1} }; #else - strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; + strided_span sav_cv{ multi_span{src}, strided_bounds<1>{2, 1} }; #endif CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 }); CHECK(sav_cv.bounds().strides() == index<1>{ 1 }); @@ -170,7 +170,7 @@ SUITE(strided_span_tests) // From cv-qualified source { - const span src{ arr }; + const multi_span src{ arr }; strided_span sav_cv{ src, {2, 1} }; CHECK(sav_cv.bounds().index_bounds() == index<1>{ 2 }); @@ -183,11 +183,11 @@ SUITE(strided_span_tests) { int arr[2] = { 4, 5 }; - const span av(arr, 2); - span av2{ av }; + const multi_span av(arr, 2); + multi_span av2{ av }; CHECK(av2[1] == 5); - static_assert(std::is_convertible, span>::value, "ctor is not implicit!"); + static_assert(std::is_convertible, multi_span>::value, "ctor is not implicit!"); const strided_span src{ arr, {2, 1} }; strided_span sav{ src }; @@ -258,13 +258,13 @@ SUITE(strided_span_tests) { std::vector data(5 * 10); std::iota(begin(data), end(data), 0); - const span src = as_span(span{data}, dim<5>(), dim<10>()); + const multi_span src = as_span(multi_span{data}, dim<5>(), dim<10>()); const strided_span sav{ src, {{5, 10}, {10, 1}} }; #ifdef CONFIRM_COMPILATION_ERRORS const strided_span csav{ {src},{ { 5, 10 },{ 10, 1 } } }; #endif - const strided_span csav{ span{ src }, { { 5, 10 },{ 10, 1 } } }; + const strided_span csav{ multi_span{ src }, { { 5, 10 },{ 10, 1 } } }; strided_span sav_sl = sav[2]; CHECK(sav_sl[0] == 20); @@ -317,7 +317,7 @@ SUITE(strided_span_tests) TEST(strided_span_bounds) { int arr[] = { 0, 1, 2, 3 }; - span av(arr); + multi_span av(arr); { // incorrect sections @@ -432,7 +432,7 @@ SUITE(strided_span_tests) TEST(strided_span_type_conversion) { int arr[] = { 0, 1, 2, 3 }; - span av(arr); + multi_span av(arr); { strided_span sav{ av.data(), av.size(), { av.size() / 2, 2 } }; @@ -447,7 +447,7 @@ SUITE(strided_span_tests) #endif } - span bytes = as_bytes(av); + multi_span bytes = as_bytes(av); // retype strided array with regular strides - from raw data { @@ -460,10 +460,10 @@ SUITE(strided_span_tests) CHECK_THROW(sav3[0][1], fail_fast); } - // retype strided array with regular strides - from span + // retype strided array with regular strides - from multi_span { strided_bounds<2> bounds{ { 2, bytes.size() / 4 }, { bytes.size() / 2, 1 } }; - span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); + multi_span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); strided_span sav2{ bytes2, bounds }; strided_span sav3 = sav2.as_strided_span(); 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 { strided_bounds<2> bounds{ { 4,2 },{ 4, 1 } }; - span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); + multi_span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); strided_span sav2{ bytes2, bounds }; CHECK_THROW(sav2.as_strided_span(), fail_fast); } @@ -483,7 +483,7 @@ SUITE(strided_span_tests) // retype strided array with not enough elements - strides are too small { strided_bounds<2> bounds{ { 4,2 },{ 2, 1 } }; - span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); + multi_span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); strided_span sav2{ bytes2, bounds }; CHECK_THROW(sav2.as_strided_span(), 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 { strided_bounds<2> bounds{ { 2,6 },{ 4, 1 } }; - span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); + multi_span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); strided_span sav2{ bytes2, bounds }; CHECK_THROW(sav2.as_strided_span(), 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 { strided_bounds<2> bounds{ { 2, 1 },{ 6, 1 } }; - span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); + multi_span bytes2 = as_span(bytes, dim<2>(), dim<>(bytes.size() / 2)); strided_span sav2{ bytes2, bounds }; CHECK_THROW(sav2.as_strided_span(), fail_fast); } @@ -511,7 +511,7 @@ SUITE(strided_span_tests) CHECK_THROW(sav2.as_strided_span(), fail_fast); } - // retype strided array with irregular strides - from span + // retype strided array with irregular strides - from multi_span { strided_bounds<1> bounds{ bytes.size() / 2, 2 }; strided_span sav2{ bytes, bounds }; @@ -522,7 +522,7 @@ SUITE(strided_span_tests) TEST(empty_strided_spans) { { - span empty_av(nullptr); + multi_span empty_av(nullptr); strided_span empty_sav{ empty_av, { 0, 1 } }; CHECK(empty_sav.bounds().index_bounds() == index<1>{ 0 }); @@ -553,7 +553,7 @@ SUITE(strided_span_tests) } } - void iterate_every_other_element(span av) + void iterate_every_other_element(multi_span av) { // pick every other element @@ -586,13 +586,13 @@ SUITE(strided_span_tests) // static bounds { - span av(arr, 8); + multi_span av(arr, 8); iterate_every_other_element(av); } // dynamic bounds { - span av(arr, 8); + multi_span av(arr, 8); iterate_every_other_element(av); } } @@ -612,7 +612,7 @@ SUITE(strided_span_tests) delete[] arr; } - void iterate_second_slice(span av) + void iterate_second_slice(multi_span av) { int expected[6] = {2,3,10,11,18,19}; auto section = av.section({0,1,0}, {3,1,2}); @@ -653,7 +653,7 @@ SUITE(strided_span_tests) } { - span av = arr; + multi_span av = arr; iterate_second_slice(av); } } @@ -693,7 +693,7 @@ SUITE(strided_span_tests) TEST(strided_span_conversion) { - // get an span of 'c' values from the list of X's + // get an multi_span of 'c' values from the list of X's struct X { int a; int b; int c; }; diff --git a/tests/string_span_tests.cpp b/tests/string_span_tests.cpp index 28d7353..cd301a0 100644 --- a/tests/string_span_tests.cpp +++ b/tests/string_span_tests.cpp @@ -142,7 +142,7 @@ SUITE(string_span_tests) const char* ptr = "Hello"; const std::string str = "Hello"; const std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - gsl::span sp = ensure_z("Hello"); + gsl::multi_span sp = ensure_z("Hello"); // comparison to literal CHECK(span == cstring_span<>("Hello")); @@ -182,7 +182,7 @@ SUITE(string_span_tests) char* ptr = ar; std::string str = "Hello"; std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - gsl::span sp = ensure_z(ar1); + gsl::multi_span sp = ensure_z(ar1); // comparison to static array with no null termination CHECK(span == string_span<>(ar)); @@ -216,7 +216,7 @@ SUITE(string_span_tests) const char ar2[10] = "Hello"; const std::string str = "Hello"; const std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - gsl::span sp = ensure_z("Hello"); + gsl::multi_span sp = ensure_z("Hello"); cstring_span<> span = "Hello"; @@ -253,7 +253,7 @@ SUITE(string_span_tests) char* _ptr = _ar; std::string _str = "Hello"; std::vector _vec = { 'H', 'e', 'l', 'l', 'o' }; - gsl::span _sp{ _ar, 5 }; + gsl::multi_span _sp{ _ar, 5 }; CHECK(span == _ar); CHECK(span == _ar1); @@ -447,7 +447,7 @@ SUITE(string_span_tests) // from span of a final extent { - span sp = "Hello"; + multi_span sp = "Hello"; cstring_span<> span = sp; CHECK(span.length() == 6); } @@ -455,7 +455,7 @@ SUITE(string_span_tests) // from const span of a final extent to non-const string_span #ifdef CONFIRM_COMPILATION_ERRORS { - span sp = "Hello"; + multi_span sp = "Hello"; string_span<> span = sp; CHECK(span.length() == 6); } @@ -568,7 +568,7 @@ SUITE(string_span_tests) // from const span { std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - const span inner = vec; + const multi_span inner = vec; cstring_span<> span = inner; CHECK(span.length() == 5); } @@ -576,7 +576,7 @@ SUITE(string_span_tests) // from non-const span { std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - span inner = vec; + multi_span inner = vec; cstring_span<> span = inner; CHECK(span.length() == 5); } @@ -675,7 +675,7 @@ SUITE(string_span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - const span inner = vec; + const multi_span inner = vec; string_span<> span = inner; CHECK(span.length() == 5); #endif @@ -684,7 +684,7 @@ SUITE(string_span_tests) // from non-const span { std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - span inner = vec; + multi_span inner = vec; string_span<> span = inner; CHECK(span.length() == 5); } @@ -693,7 +693,7 @@ SUITE(string_span_tests) { #ifdef CONFIRM_COMPILATION_ERRORS const std::vector vec = { 'H', 'e', 'l', 'l', 'o' }; - const span inner = vec; + const multi_span inner = vec; string_span<> span = inner; CHECK(span.length() == 5); #endif @@ -769,12 +769,12 @@ SUITE(string_span_tests) // move span { - span span = ensure_z("Hello"); + multi_span span = ensure_z("Hello"); cstring_span<> span1 = std::move(span); CHECK(span1.length() == 5); } { - span span = ensure_z("Hello"); + multi_span span = ensure_z("Hello"); cstring_span<> span2 = move_wrapper(std::move(span)); CHECK(span2.length() == 5); }