My Project
Public Types | Public Member Functions | Static Public Member Functions | Related Functions | List of all members
bsl::span< T > Class Template Referencefinal

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. More...

#include <span.hpp>

Public Types

using value_type = T
 alias for: T
 
using size_type = bsl::uintmax
 alias for: bsl::uintmax
 
using difference_type = bsl::uintmax
 alias for: bsl::uintmax
 
using reference_type = T &
 alias for: T &
 
using const_reference_type = T const &
 alias for: T &
 
using pointer_type = T *
 alias for: T *
 
using const_pointer_type = T const *
 alias for: T const *
 
using iterator_type = contiguous_iterator< T >
 alias for: contiguous_iterator<T>
 
using const_iterator_type = contiguous_iterator< T const >
 alias for: contiguous_iterator<T const>
 
using reverse_iterator_type = reverse_iterator< iterator_type >
 alias for: reverse_iterator<iterator>
 
using const_reverse_iterator_type = reverse_iterator< const_iterator_type >
 alias for: reverse_iterator<const_iterator>
 

Public Member Functions

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...
 

Static Public Member Functions

static constexpr size_type max_size () noexcept
 Returns the max number of elements the BSL supports. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
constexpr bool operator== (span< T > const &lhs, span< T > const &rhs) noexcept
 Returns true if two spans have the same size and contain the same contents. Returns false otherwise. More...
 
template<typename T >
constexpr bool operator!= (span< T > const &lhs, span< T > const &rhs) noexcept
 Returns false if two spans have the same size and contain the same contents. Returns true otherwise. More...
 

Detailed Description

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.

Template Parameters
Tthe type of element being viewed.

Constructor & Destructor Documentation

◆ span() [1/2]

template<typename T>
constexpr bsl::span< T >::span ( )
defaultnoexcept

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.

#include <bsl/span.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_default_constructor() noexcept
{
bsl::span<bool> const s{};
if (s.empty()) {
bsl::print() << "success\n";
}
}
}

◆ span() [2/2]

template<typename T>
constexpr bsl::span< T >::span ( pointer_type const  ptr,
size_type const  count 
)
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_ptr_count_constructor() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const s{arr.data(), arr.size()};
bsl::for_each(s, [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ptra pointer to the array being spaned.
countthe number of elements in the array being spaned.

Member Function Documentation

◆ at_if() [1/2]

template<typename T>
constexpr pointer_type bsl::span< T >::at_if ( size_type const  index)
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_at_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}

SUPPRESSION: PRQA 4024 - false positive

  • We suppress this because A9-3-1 states that we should not provide a non-const reference or pointer to private member function, unless the class mimics a smart pointer or a containter. This class mimics a container.
Parameters
indexthe index of the instance to return
Returns
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.

◆ at_if() [2/2]

template<typename T>
constexpr const_pointer_type bsl::span< T >::at_if ( size_type const  index) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_at_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.at_if(0U)) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Parameters
indexthe index of the instance to return
Returns
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.

◆ front_if() [1/2]

template<typename T>
constexpr pointer_type bsl::span< T >::front_if ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_front_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
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.

◆ front_if() [2/2]

template<typename T>
constexpr const_pointer_type bsl::span< T >::front_if ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_front_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.front_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
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.

◆ back_if() [1/2]

template<typename T>
constexpr pointer_type bsl::span< T >::back_if ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_back_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
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.

◆ back_if() [2/2]

template<typename T>
constexpr const_pointer_type bsl::span< T >::back_if ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_back_if() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (auto const *const ptr = spn.back_if()) {
bsl::print() << "success: " << *ptr << bsl::endl;
}
}
}
Returns
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.

◆ data() [1/2]

template<typename T>
constexpr pointer_type bsl::span< T >::data ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_data() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (spn.data() == arr.data()) {
bsl::print() << "success\n";
}
}
}
Returns
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.

◆ data() [2/2]

template<typename T>
constexpr const_pointer_type bsl::span< T >::data ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_data() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (spn.data() == arr.data()) {
bsl::print() << "success\n";
}
}
}
Returns
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.

◆ begin() [1/2]

template<typename T>
constexpr iterator_type bsl::span< T >::begin ( )
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ begin() [2/2]

template<typename T>
constexpr const_iterator_type bsl::span< T >::begin ( ) const
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ cbegin()

template<typename T>
constexpr const_iterator_type bsl::span< T >::cbegin ( ) const
inlinenoexcept

Returns an iterator to the first element of the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_begin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns an iterator to the first element of the view.

◆ iter() [1/2]

template<typename T>
constexpr iterator_type bsl::span< T >::iter ( size_type const  i)
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.iter(i1), spn.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ iter() [2/2]

template<typename T>
constexpr const_iterator_type bsl::span< T >::iter ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.iter(i1), spn.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ citer()

template<typename T>
constexpr const_iterator_type bsl::span< T >::citer ( size_type const  i) const
inlinenoexcept

Returns an iterator to the element "i" in the view.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_iter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.iter(i1), spn.iter(i4), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns an iterator to the element "i" in the view.

◆ end() [1/2]

template<typename T>
constexpr iterator_type bsl::span< T >::end ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
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.

◆ end() [2/2]

template<typename T>
constexpr const_iterator_type bsl::span< T >::end ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
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.

◆ cend()

template<typename T>
constexpr const_iterator_type bsl::span< T >::cend ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_end() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.begin(), spn.end(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
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.

◆ rbegin() [1/2]

template<typename T>
constexpr reverse_iterator_type bsl::span< T >::rbegin ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ rbegin() [2/2]

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::rbegin ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ crbegin()

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::crbegin ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rbegin() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator to the last element of the view.

◆ riter() [1/2]

template<typename T>
constexpr reverse_iterator_type bsl::span< T >::riter ( size_type const  i)
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.riter(i4), spn.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ riter() [2/2]

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::riter ( size_type const  i) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.riter(i4), spn.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ criter()

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::criter ( size_type const  i) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_riter() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i1{1U};
constexpr bsl::uintmax i4{4U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.riter(i4), spn.riter(i1), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Parameters
ithe element in the array to return an iterator for.
Returns
Returns a reverse iterator element "i" in the view.

◆ rend() [1/2]

template<typename T>
constexpr reverse_iterator_type bsl::span< T >::rend ( )
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ rend() [2/2]

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::rend ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ crend()

template<typename T>
constexpr const_reverse_iterator_type bsl::span< T >::crend ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_rend() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::for_each(spn.rbegin(), spn.rend(), [](auto &e, auto const i) noexcept {
bsl::print() << "element [" << i << "] == " << e << bsl::endl;
});
}
}
Returns
Returns a reverse iterator first element of the view.

◆ empty()

template<typename T>
constexpr bool bsl::span< T >::empty ( ) const
inlinenoexcept

Returns size() == 0.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_empty() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
if (!spn.empty()) {
bsl::print() << "success\n";
}
}
}
Returns
Returns size() == 0

◆ size()

template<typename T>
constexpr size_type bsl::span< T >::size ( ) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_size() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::print() << "size: " << spn.size() << bsl::endl;
}
}
Returns
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.

◆ max_size()

template<typename T>
static constexpr size_type bsl::span< T >::max_size ( )
inlinestaticnoexcept

Returns the max number of elements the BSL supports.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_max_size() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::print() << "max size: " << spn.max_size() << bsl::endl;
}
}
Returns
Returns the max number of elements the BSL supports.

◆ size_bytes()

template<typename T>
constexpr size_type bsl::span< T >::size_bytes ( ) const
inlinenoexcept

Returns size() * sizeof(T)

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_size_bytes() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const spn{arr.data(), arr.size()};
bsl::print() << "size in bytes: " << spn.size_bytes() << bsl::endl;
}
}
Returns
Returns size() * sizeof(T)

◆ first() [1/2]

template<typename T>
constexpr span<T> bsl::span< T >::first ( size_type const  count = npos)
inlinenoexcept

Returns subspan(0, count). If count is 0, an invalid span is returned.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_first() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
val1,
val2,
val3,
val4,
val5,
val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.first(i).front_if()) {
if (val1 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
countthe number of elements of the new subspan
Returns
Returns subspan(0, count). If count is 0, an invalid span is returned.

◆ first() [2/2]

template<typename T>
constexpr span<T> bsl::span< T >::first ( size_type const  count = npos) const
inlinenoexcept

Returns subspan(0, count). If count is 0, an invalid span is returned.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_first() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
val1,
val2,
val3,
val4,
val5,
val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.first(i).front_if()) {
if (val1 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
countthe number of elements of the new subspan
Returns
Returns subspan(0, count). If count is 0, an invalid span is returned.

◆ last() [1/2]

template<typename T>
constexpr span<T> bsl::span< T >::last ( size_type  count = npos)
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_last() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.last(i).front_if()) {
if (val4 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
countthe number of elements of the new subspan
Returns
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.

◆ last() [2/2]

template<typename T>
constexpr span<T> bsl::span< T >::last ( size_type  count = npos) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_last() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.last(i).front_if()) {
if (val4 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
countthe number of elements of the new subspan
Returns
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.

◆ subspan() [1/2]

template<typename T>
constexpr span<T> bsl::span< T >::subspan ( size_type const  pos,
size_type const  count = npos 
)
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_subspan() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
constexpr bsl::uintmax n{2U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.subspan(i, n).front_if()) {
if (val3 == *ptr) {
bsl::print() << "success\n";
}
}
if (auto const *const ptr = s.subspan(i, n).back_if()) {
if (val5 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
posthe starting position of the new span
countthe number of elements of the new subspan
Returns
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.

◆ subspan() [2/2]

template<typename T>
constexpr span<T> bsl::span< T >::subspan ( size_type const  pos,
size_type const  count = npos 
) const
inlinenoexcept

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.

#include <bsl/span.hpp>
#include <bsl/array.hpp>
#include <bsl/for_each.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_subspan() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
constexpr bsl::uintmax i{3U};
constexpr bsl::uintmax n{2U};
bsl::array<bsl::uintmax, size> const arr{val1, val2, val3, val4, val5, val6};
bsl::span const s{arr.data(), arr.size()};
if (auto const *const ptr = s.subspan(i, n).front_if()) {
if (val3 == *ptr) {
bsl::print() << "success\n";
}
}
if (auto const *const ptr = s.subspan(i, n).back_if()) {
if (val5 == *ptr) {
bsl::print() << "success\n";
}
}
}
}
Parameters
posthe starting position of the new span
countthe number of elements of the new subspan
Returns
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.

Friends And Related Function Documentation

◆ operator==()

template<typename T >
constexpr bool operator== ( span< T > const &  lhs,
span< T > const &  rhs 
)
related

Returns true if two spans have the same size and contain the same contents. Returns false otherwise.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_equals() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr1{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr2{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr3{val1, val1, val1, val1, val1, val1};
bsl::span const spn1{arr1.data(), arr1.size()};
bsl::span const spn2{arr2.data(), arr2.size()};
bsl::span const spn3{arr3.data(), arr3.size()};
if (spn1 == spn2) {
bsl::print() << "success\n";
}
if (spn1 != spn3) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of elements in the span
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two spans have the same size and contain the same contents. Returns false otherwise.

◆ operator!=()

template<typename T >
constexpr bool operator!= ( span< T > const &  lhs,
span< T > const &  rhs 
)
related

Returns false if two spans have the same size and contain the same contents. Returns true otherwise.

#include <bsl/array.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_span_not_equals() noexcept
{
constexpr bsl::uintmax size{6U};
constexpr bsl::uintmax val1{4U};
constexpr bsl::uintmax val2{8U};
constexpr bsl::uintmax val3{15U};
constexpr bsl::uintmax val4{16U};
constexpr bsl::uintmax val5{23U};
constexpr bsl::uintmax val6{42U};
bsl::array<bsl::uintmax, size> const arr1{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr2{val1, val2, val3, val4, val5, val6};
bsl::array<bsl::uintmax, size> const arr3{val1, val1, val1, val1, val1, val1};
bsl::span const spn1{arr1.data(), arr1.size()};
bsl::span const spn2{arr2.data(), arr2.size()};
bsl::span const spn3{arr3.data(), arr3.size()};
if (spn1 == spn2) {
bsl::print() << "success\n";
}
if (spn1 != spn3) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of elements in the span
Parameters
lhsthe left hand side of the operation
rhsthe right hand side of the operation
Returns
Returns true if two spans have the same size and contain the same contents. Returns false otherwise.

The documentation for this class was generated from the following file: