|
constexpr | span () noexcept=default |
| Default constructor that creates a span with data() == nullptr and size() == 0. All accessors will return a nullptr if used. Note that like other view types in the BSL, the bsl::span is a POD type. This means that when declaring a global, default constructed bsl::span, DO NOT include the {} for initialization. Instead, remove the {} and the global bsl::span will be included in the BSS section of the executable, and initialized to 0 for you. All other instantiations of a bsl::span (or any POD type), should be initialized using {} to ensure the POD is properly initialized. Using the above method for global initialization ensures that global constructors are not executed at runtime, which is required by AUTOSAR. More...
|
|
constexpr | span (pointer_type const ptr, size_type const count) noexcept |
| Creates a span given a pointer to an array, and the number of elements in the array. Note that the array must be contiguous in memory and [ptr, ptr + count) must be a valid range. More...
|
|
constexpr pointer_type | at_if (size_type const index) noexcept |
| Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr const_pointer_type | at_if (size_type const index) const noexcept |
| Returns a pointer to the instance of T stored at index "index". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr pointer_type | front_if () noexcept |
| Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr const_pointer_type | front_if () const noexcept |
| Returns a pointer to the instance of T stored at index "0". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr pointer_type | back_if () noexcept |
| Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr const_pointer_type | back_if () const noexcept |
| Returns a pointer to the instance of T stored at index "size() - 1". If the index is out of bounds, or the view is invalid, this function returns a nullptr. More...
|
|
constexpr pointer_type | data () noexcept |
| Returns a pointer to the array being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr. More...
|
|
constexpr const_pointer_type | data () const noexcept |
| Returns a pointer to the array being viewed. If this is a default constructed view, or the view was constructed in error, this will return a nullptr. More...
|
|
constexpr iterator_type | begin () noexcept |
| Returns an iterator to the first element of the view. More...
|
|
constexpr const_iterator_type | begin () const noexcept |
| Returns an iterator to the first element of the view. More...
|
|
constexpr const_iterator_type | cbegin () const noexcept |
| Returns an iterator to the first element of the view. More...
|
|
constexpr iterator_type | iter (size_type const i) noexcept |
| Returns an iterator to the element "i" in the view. More...
|
|
constexpr const_iterator_type | iter (size_type const i) const noexcept |
| Returns an iterator to the element "i" in the view. More...
|
|
constexpr const_iterator_type | citer (size_type const i) const noexcept |
| Returns an iterator to the element "i" in the view. More...
|
|
constexpr iterator_type | end () noexcept |
| Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
|
|
constexpr const_iterator_type | end () const noexcept |
| Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
|
|
constexpr const_iterator_type | cend () const noexcept |
| Returns an iterator to one past the last element of the view. If you attempt to access this iterator, a nullptr will always be returned. More...
|
|
constexpr reverse_iterator_type | rbegin () noexcept |
| Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | rbegin () const noexcept |
| Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | crbegin () const noexcept |
| Returns a reverse iterator to one past the last element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr reverse_iterator_type | riter (size_type const i) noexcept |
| Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | riter (size_type const i) const noexcept |
| Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | criter (size_type const i) const noexcept |
| Returns a reverse iterator element "i" in the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr reverse_iterator_type | rend () noexcept |
| Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | rend () const noexcept |
| Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr const_reverse_iterator_type | crend () const noexcept |
| Returns a reverse iterator first element of the view. When accessing the iterator, the iterator will always return the element T[internal index - 1], providing access to the range [size() - 1, 0) while internally storing the range [size(), 1) with element 0 representing the end(). For more information, see the bsl::reverse_iterator documentation. More...
|
|
constexpr bool | empty () const noexcept |
| Returns size() == 0. More...
|
|
constexpr size_type | size () const noexcept |
| Returns the number of elements in the array being viewed. If this is a default constructed view, or the view was constructed in error, this will return 0. More...
|
|
constexpr size_type | size_bytes () const noexcept |
| Returns size() * sizeof(T) More...
|
|
constexpr span< T > | first (size_type const count=npos) noexcept |
| Returns subspan(0, count). If count is 0, an invalid span is returned. More...
|
|
constexpr span< T > | first (size_type const count=npos) const noexcept |
| Returns subspan(0, count). If count is 0, an invalid span is returned. More...
|
|
constexpr span< T > | last (size_type count=npos) noexcept |
| Returns subspan(this->size() - count, count). If count is greater than the size of the current span, a copy of the current span is returned. If the count is 0, an invalid span is returned. More...
|
|
constexpr span< T > | last (size_type count=npos) const noexcept |
| Returns subspan(this->size() - count, count). If count is greater than the size of the current span, a copy of the current span is returned. If the count is 0, an invalid span is returned. More...
|
|
constexpr span< T > | subspan (size_type const pos, size_type const count=npos) noexcept |
| Returns span{at_if(pos), min_of(count, size() - pos)}. If the provided "pos" is greater than or equal to the size of the current span, an invalid span is returned. More...
|
|
constexpr span< T > | subspan (size_type const pos, size_type const count=npos) const noexcept |
| Returns span{at_if(pos), min_of(count, size() - pos)}. If the provided "pos" is greater than or equal to the size of the current span, an invalid span is returned. More...
|
|
template<typename T>
class bsl::span< T >
A bsl::span is a non-owning view of an array type. Unlike a bsl::array, the bsl::span does not own the memory it accesses and therefore cannot outlive whatever array you give it. The bsl::span is also very similar to a gsl::span and a std::span with some key differences.
- We do not provide the conversion constructors for array types as they are not compliant with AUTOSAR. If you need an array, use a bsl::array.
- We do not provide any of the accessor functions as defined by the standard library. Instead we provide _if() versions which return a pointer to the element being requested. If the element does not exist, a nullptr is returned, providing a means to check for logic errors without the need for exceptions or failing fast which is not compliant with AUTOSAR.
- We provide the iter() function which is similar to begin() and end(), but allowing you to get an iterator from any position in the view.
- As noted in the documentation for the contiguous_iterator, iterators are not allowed to go beyond their bounds which the Standard Library does not ensure. It is still possible for an iterator to be invalid as you cannot dereference end() (fixing this would break compatiblity with existing APIs when AUTOSAR compliance is disabled), but you can be rest assured that an iterator's index is always within bounds or == end(). Note that for invalid views, begin() and friends always return an interator to end().
- We do not provide any of the as_byte helper functions as they would all require a reinterpret_cast which is not allowed by AUTOSAR.
- A bsl::span is always a dynamic_extent type. The reason the dynamic_extent type exists in a std::span is to optimize away the need to store the size of the array the span is viewing. This is only useful for C-style arrays which are not supported as they are not compliant with AUTOSAR. If you need a C-style array, use a bsl::array, in which case you have no need for a bsl::span. Instead, a bsl::span is useful when you have an array in memory that is not in your control (for example, a device's memory).
namespace bsl
{
inline void
example_span_overview() noexcept
{
});
}
}
- Template Parameters
-
T | the type of element being viewed. |