xtd 1.0.0
Loading...
Searching...
No Matches
xtd::span< type_t, extent > Class Template Reference
Inheritance diagram for xtd::span< type_t, extent >:
xtd::object xtd::iequatable< xtd::span< type_t, xtd::dynamic_extent > > xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_t > >

Definition

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
class xtd::span< type_t, extent >

Represents a non-owning view over a contiguous sequence of objects.

Definition
template<typename type_t, xtd::usize extent = dynamic_extent>
class span : public xtd::object, public xtd::iequatable<xtd::span<type_t, extent>>;
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
constexpr span()
Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.
Definition span.hpp:91
Header
#include <xtd/span>
Namespace
xtd
Library
xtd.core
Remarks
The class template xtd::span describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent, in which case the number of elements in the sequence is known at compile-time and encoded in the type, or a dynamic extent.
The referenced data can be modified through a xtd::span object. To prevent this, construct a xtd::span over a const type_t:
int numbers[] = {0, 1, 2};
span<int> span_numbers = numbers;
span_numbers[0] = 42; // numbers == {42, 1, 2};
span<const int> cspan_numbers = numbers;
cspan_numbers[0] = 0; // ERROR: cspan_numbers[0] is read-only
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:55
Examples
Create a span from memory.
#include <xtd/xtd>
auto main() -> int {
// Create a span from memory.
auto memory_pointer = new byte[100];
auto memory_span = span(memory_pointer, 100);
auto data = byte {};
for (auto ctr = 0_z; ctr < memory_span.length(); ++ctr)
memory_span[ctr] = data++;
auto array_sum = 0;
for (auto value : memory_span)
array_sum += value;
console::write_line("The sum is {}", array_sum);
// Don't forget to free memory pointer allocation as xtd::span does not manage memory.
delete[] memory_pointer;
}
// This code produces the following output :
//
// The sum is 4950
static auto write_line() -> void
Writes the current line terminator to the standard output stream using the specified format informati...
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition span.hpp:224
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197

Create a span over an array.

#include <xtd/xtd>
auto main() -> int {
// Create a span over an array.
auto bytes = array<byte>(100);
auto array_span = span(bytes);
auto data = byte {};
for (auto ctr = 0_z; ctr < array_span.length(); ++ctr)
array_span[ctr] = data++;
auto array_sum = 0;
for (auto value : bytes)
array_sum += value;
console::write_line("The sum is {}", array_sum);
}
// This code produces the following output :
//
// The sum is 4950
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64

Public Aliases

using element_type
 Represents the span elemeent type.
using value_type
 Represents the span value type.
using size_type
 Represents the span size type (usually xtd::usize).
using difference_type
 Represents the span difference type (usually xtd::ptrdiff).
using pointer
 Represents the span pointer type.
using const_pointer
 Represents the span const pointer type.
using reference
 Represents the span reference type.
using const_reference
 Represents the span const reference type.
using iterator
 Represents the iterator of span value type.
using const_iterator
 Represents the const iterator of span value type.
using reverse_iterator
 Represents the reverse iterator of span value type.
using const_reverse_iterator
 Represents the const reverse iterator of span value type.

Public Fields

static const span empty_span
 Returns an empty xtd::span <type_t> object.

Public Constructors

template<xtd::usize count = 0>
constexpr span ()
 Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.
template<typename iterator_t>
constexpr span (iterator_t first, iterator_t last)
 Creates an xtd::span with specified iterators.
template<xtd::usize len>
constexpr span (element_type(&array)[len]) noexcept
 Creates an xtd::span with specified native array.
template<typename array_type_t, xtd::usize len>
constexpr span (const std::array< array_type_t, len > &array) noexcept
 Creates an xtd::span with specified std::array.
template<typename array_type_t, xtd::usize len>
constexpr span (std::array< array_type_t, len > &array) noexcept
 Creates an xtd::span with specified std::array.
template<typename array_type_t>
constexpr span (const xtd::array< array_type_t > &items)
 Creates an xtd::span with specified collection and count.
template<typename array_type_t>
constexpr span (xtd::array< array_type_t > &items)
 Creates an xtd::span with specified collection and count.
template<typename range_t>
constexpr span (range_t &&range) noexcept
 Creates an xtd::span with specified range.
constexpr span (std::initializer_list< type_t > items) noexcept
 Creates an xtd::span with specified initializer list.
template<typename collection_t>
constexpr span (collection_t &items, size_type length)
 Creates an xtd::span with specified collection and count.
template<typename collection_t>
constexpr span (collection_t &items, size_type start, size_type length)
 Creates an xtd::span with specified collection, offest and count.
constexpr span (type_t *const data, size_type length)
 Creates an xtd::span with specified data pointer and count.

Public Properties

auto begin () const -> const_iterator
 Returns an iterator to the beginning.
auto begin () -> iterator
 Returns an iterator to the beginning.
auto cbegin () const -> const_iterator
 Returns an iterator to the beginning.
auto cend () const -> const_iterator
 Returns an iterator to the end.
constexpr auto data () const noexcept -> const_pointer
 Gets direct access to the underlying contiguous storage.
constexpr auto empty () const noexcept -> bool
 Returns a value that indicates whether the current xtd::span <type_t> is empty.
auto end () const -> const_iterator
 Returns an iterator to the end.
auto end () -> iterator
 Returns an iterator to the end.
constexpr auto is_empty () const noexcept -> bool
 Returns a value that indicates whether the current xtd::span <type_t> is empty.
constexpr auto length () const noexcept -> size_type
 Returns the length of the current span.
constexpr auto size () const noexcept -> size_type
 Returns the number of elements.
constexpr auto size_bytes () const noexcept -> size_type
 Returns the size of the sequence in bytes.

Public Methods

auto clear () noexcept -> void
 Clears the contents of this xtd::span <type> object.
template<xtd::usize length>
auto copy_to (span< type_t, length > &destination) const -> void
 Copies the contents of this xtd::span <type_t> into a destination xtd:span <type_t>.
auto equals (const object &obj) const noexcept -> bool override
 Determines whether the specified object is equal to the current object.
auto equals (const span &rhs) const noexcept -> bool override
 Indicates whether the current object is equal to another object of the same type.
auto fill (const type_t &value) -> void
 Fills the elements of this span with a specified value.
template<xtd::usize count>
auto first () const -> span< type_t, count >
 Obtains a subspan consisting of the first count elements of the sequence.
auto first (xtd::usize count) const -> span< type_t >
 Obtains a subspan consisting of the first count elements of the sequence.
auto get_hash_code () const noexcept -> xtd::usize override
 Serves as a hash function for a particular type.
template<xtd::usize count>
auto last () const -> span< type_t, count >
 Obtains a subspan consisting of the last N elements of the sequence.
auto last (xtd::usize count) const -> span< type_t >
 Obtains a subspan consisting of the last N elements of the sequence.
template<xtd::usize start, size_type lenght = xtd::dynamic_extent>
auto slice () const -> span< type_t >
 Forms a slice out of the current span starting at a specified index for a specified length.
auto slice (size_type start) const -> span< type_t >
 Forms a slice out of the current span that begins at a specified index.
auto slice (size_type start, size_type length) const -> span< type_t >
 Forms a slice out of the current span starting at a specified index for a specified length.
template<xtd::usize offset, size_type count = xtd::dynamic_extent>
auto subspan () const -> span< type_t >
 Forms a subspan of the current span starting at a specified index for a specified length.
auto subspan (size_type offset, size_type count=xtd::dynamic_extent) const -> span< type_t >
 Forms a subspan of the current span starting at a specified index for a specified length.
auto to_array () const noexcept -> xtd::array< value_type >
 Copies the contents of this span into a new array.
auto to_string () const noexcept -> xtd::string override
 Returns the string representation of this xtd::span <type_t> object.
template<xtd::usize length>
auto try_copy_to (span< type_t, length > &destination) const noexcept -> bool
 Attempts to copy the current xtd::span <type_t> to a destination xtd::span <type_t> and returns a value that indicates whether the copy operation succeeded.

Public Operators

auto operator[] (size_type index) const -> const_reference
 Gets the element at the specified zero-based index.
auto operator[] (size_type index) -> reference
 Gets the element at the specified zero-based index.

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto equals (const type_t &) const noexcept -> bool=0
 Indicates whether the current object is equal to another object of the same type.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.

Member Typedef Documentation

◆ element_type

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::element_type

Represents the span elemeent type.

◆ value_type

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::value_type

Represents the span value type.

◆ size_type

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::size_type

Represents the span size type (usually xtd::usize).

◆ difference_type

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::difference_type

Represents the span difference type (usually xtd::ptrdiff).

◆ pointer

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::pointer

Represents the span pointer type.

◆ const_pointer

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::const_pointer

Represents the span const pointer type.

◆ reference

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::reference

Represents the span reference type.

◆ const_reference

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::const_reference

Represents the span const reference type.

◆ iterator

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::iterator

Represents the iterator of span value type.

◆ const_iterator

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::const_iterator

Represents the const iterator of span value type.

◆ reverse_iterator

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::reverse_iterator

Represents the reverse iterator of span value type.

◆ const_reverse_iterator

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
using xtd::span< type_t, extent >::const_reverse_iterator

Represents the const reverse iterator of span value type.

Constructor & Destructor Documentation

◆ span() [1/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize count = 0>
xtd::span< type_t, extent >::span ( )
inlineconstexpr

Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.

◆ span() [2/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename iterator_t>
xtd::span< type_t, extent >::span ( iterator_t first,
iterator_t last )
inlineconstexpr

Creates an xtd::span with specified iterators.

Parameters
firstThe iterator to the first element of the sequence.
lastThe iterator to the last element of the sequence.

◆ span() [3/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize len>
xtd::span< type_t, extent >::span ( element_type(&) array[len])
inlineconstexprnoexcept

Creates an xtd::span with specified native array.

Parameters
arrayThe native array to construct a view for.

◆ span() [4/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename array_type_t, xtd::usize len>
xtd::span< type_t, extent >::span ( const std::array< array_type_t, len > & array)
inlineconstexprnoexcept

Creates an xtd::span with specified std::array.

Parameters
arrayThe std::array to construct a view for.

◆ span() [5/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename array_type_t, xtd::usize len>
xtd::span< type_t, extent >::span ( std::array< array_type_t, len > & array)
inlineconstexprnoexcept

Creates an xtd::span with specified std::array.

Parameters
arrayThe std::array to construct a view for.

◆ span() [6/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename array_type_t>
xtd::span< type_t, extent >::span ( const xtd::array< array_type_t > & items)
inlineconstexpr

Creates an xtd::span with specified collection and count.

Parameters
itemsThe collection to construct a view for.
lengthThe number of elements in the collection.
Exceptions
xtd::argument_out_of_range_exceptionif length is greater than items size.

◆ span() [7/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename array_type_t>
xtd::span< type_t, extent >::span ( xtd::array< array_type_t > & items)
inlineconstexpr

Creates an xtd::span with specified collection and count.

Parameters
itemsThe collection to construct a view for.
lengthThe number of elements in the collection.
Exceptions
xtd::argument_out_of_range_exceptionif length is greater than items size.

◆ span() [8/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename range_t>
xtd::span< type_t, extent >::span ( range_t && range)
inlineconstexprnoexcept

Creates an xtd::span with specified range.

Parameters
rangeThe range to construct a view for.

◆ span() [9/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
xtd::span< type_t, extent >::span ( std::initializer_list< type_t > items)
inlineconstexprnoexcept

Creates an xtd::span with specified initializer list.

Parameters
itemsThe initializer list to construct a view for.

◆ span() [10/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename collection_t>
xtd::span< type_t, extent >::span ( collection_t & items,
size_type length )
inlineconstexpr

Creates an xtd::span with specified collection and count.

Parameters
itemsThe collection to construct a view for.
lengthThe number of elements in the collection.
Exceptions
xtd::argument_out_of_range_exceptionif length is greater than items size.

◆ span() [11/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<typename collection_t>
xtd::span< type_t, extent >::span ( collection_t & items,
size_type start,
size_type length )
inlineconstexpr

Creates an xtd::span with specified collection, offest and count.

Parameters
itemsThe collection to construct a view for.
startThe offset in the collection.
lengthThe number of elements in the collection.
Exceptions
xtd::argument_out_of_range_exceptionif start or start + length are greater than items size.

◆ span() [12/12]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
xtd::span< type_t, extent >::span ( type_t *const data,
size_type length )
inlineconstexpr

Creates an xtd::span with specified data pointer and count.

Parameters
dataThe data pointer to construct a view for.
lengthThe number of elements to constuct.

Member Function Documentation

◆ begin() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::begin ( ) const -> const_iterator
inlinenodiscard

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ begin() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::begin ( ) -> iterator
inlinenodiscard

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ cbegin()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::cbegin ( ) const -> const_iterator
inlinenodiscard

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ cend()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::cend ( ) const -> const_iterator
inlinenodiscard

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ data()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::data ( ) const -> const_pointer
inlinenodiscardconstexprnoexcept

Gets direct access to the underlying contiguous storage.

Returns
A pointer to the beginning of the sequence.

◆ empty()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::empty ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns a value that indicates whether the current xtd::span <type_t> is empty.

Returns
true if the current span is empty; otherwise, false.

◆ end() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::end ( ) const -> const_iterator
inlinenodiscard

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ end() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::end ( ) -> iterator
inlinenodiscard

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ is_empty()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::is_empty ( ) const -> bool
inlinenodiscardconstexprnoexcept

Returns a value that indicates whether the current xtd::span <type_t> is empty.

Returns
true if the current span is empty; otherwise, false.

◆ length()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::length ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the length of the current span.

Returns
The length of the current span.

◆ size()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::size ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the number of elements.

Returns
The number of elements in the span.

◆ size_bytes()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::size_bytes ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the size of the sequence in bytes.

Returns
The size of the sequence in bytes, i.e., size() * sizeof(element_type).

◆ clear()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::clear ( ) -> void
inlinenoexcept

Clears the contents of this xtd::span <type> object.

Remarks
The xtd::span::clear method sets the items in the xtd::span <type_t> object to their default values. It does not remove items from the xtd::span <type_t>.

◆ copy_to()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize length>
auto xtd::span< type_t, extent >::copy_to ( span< type_t, length > & destination) const -> void
inline

Copies the contents of this xtd::span <type_t> into a destination xtd:span <type_t>.

Parameters
destinatonThe destination xtd::span <type_t> object.
Exceptions
xtd::argument_exception`destination` is shorter than the source xtd::span <type_t>.

◆ equals() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::equals ( const object & obj) const -> bool
inlinenodiscardoverridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ equals() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::equals ( const span< type_t, extent > & rhs) const -> bool
inlinenodiscardoverridenoexcept

Indicates whether the current object is equal to another object of the same type.

Parameters
objAn object to compare with this object.
Returns
true if the current object is equal to the other parameter; otherwise, false.

◆ fill()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::fill ( const type_t & value) -> void
inline

Fills the elements of this span with a specified value.

Parameters
valueThe value to assign to each element of the span.

◆ first() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize count>
auto xtd::span< type_t, extent >::first ( ) const -> span< type_t, count >
inlinenodiscard

Obtains a subspan consisting of the first count elements of the sequence.

Parameters
countThe count elements.
Returns
A span r that is a view over the first count elements of *this, such that r.data() == this->data() && r.size() == count.

◆ first() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::first ( xtd::usize count) const -> span< type_t >
inlinenodiscard

Obtains a subspan consisting of the first count elements of the sequence.

Parameters
countThe count elements.
Returns
A span r that is a view over the first count elements of *this, such that r.data() == this->data() && r.size() == count.

◆ get_hash_code()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::get_hash_code ( ) const -> xtd::usize
inlinenodiscardoverridevirtualnoexcept

Serves as a hash function for a particular type.

Returns
A hash code for the current object.

Reimplemented from xtd::object.

◆ last() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize count>
auto xtd::span< type_t, extent >::last ( ) const -> span< type_t, count >
inlinenodiscard

Obtains a subspan consisting of the last N elements of the sequence.

Parameters
countThe count elements.
Returns
A span r that is a view over the last count elements of *this, such that r.data() == this->data() + (this->size() - count) && r.size() == count.

◆ last() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::last ( xtd::usize count) const -> span< type_t >
inlinenodiscard

Obtains a subspan consisting of the last N elements of the sequence.

Parameters
countThe count elements.
Returns
A span r that is a view over the last count elements of *this, such that r.data() == this->data() + (this->size() - count) && r.size() == count.

◆ slice() [1/3]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize start, size_type lenght = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::slice ( ) const -> span< type_t >
inlinenodiscard

Forms a slice out of the current span starting at a specified index for a specified length.

Parameters
startThe zero-based index at which to begin this slice.
lengthThe desired length for the slice.
Returns
A span that consists of length elements from the current span starting at start.
Exceptions
xtd::argument_out_of_range_exception`start` or `start + length` is less than zero or greater than xtd::span::length.

◆ slice() [2/3]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::slice ( size_type start) const -> span< type_t >
inlinenodiscard

Forms a slice out of the current span that begins at a specified index.

Parameters
startThe zero-based index at which to begin the slice.
Returns
A span that consists of all elements of the current span from start to the end of the span.
Exceptions
xtd::argument_out_of_range_exception`start` is less than zero or greater than xtd::span::length.

◆ slice() [3/3]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::slice ( size_type start,
size_type length ) const -> span< type_t >
inlinenodiscard

Forms a slice out of the current span starting at a specified index for a specified length.

Parameters
startThe zero-based index at which to begin this slice.
lengthThe desired length for the slice.
Returns
A span that consists of length elements from the current span starting at start.
Exceptions
xtd::argument_out_of_range_exception`start` or `start + length` is less than zero or greater than xtd::span::length.

◆ subspan() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize offset, size_type count = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::subspan ( ) const -> span< type_t >
inlinenodiscard

Forms a subspan of the current span starting at a specified index for a specified length.

Parameters
offsetThe zero-based index at which to begin this slice.
countThe desired length for the slice.
Returns
A span that consists of length elements from the current span starting at start.
Exceptions
xtd::argument_out_of_range_exception`offset` or `offset + count` is less than zero or greater than xtd::span::length.

◆ subspan() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::subspan ( size_type offset,
size_type count = xtd::dynamic_extent ) const -> span< type_t >
inlinenodiscard

Forms a subspan of the current span starting at a specified index for a specified length.

Parameters
offsetThe zero-based index at which to begin this slice.
countThe desired length for the slice.
Returns
A span that consists of length elements from the current span starting at start.
Exceptions
xtd::argument_out_of_range_exception`offset` or `offset + count` is less than zero or greater than xtd::span::length.

◆ to_array()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::to_array ( ) const -> xtd::array< value_type >
inlinenodiscardnoexcept

Copies the contents of this span into a new array.

Returns
An array containing the data in the current span.

◆ to_string()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::to_string ( ) const -> xtd::string
inlinenodiscardoverridevirtualnoexcept

Returns the string representation of this xtd::span <type_t> object.

Returns
The string representation of this xtd::span <type_t> object.
Remarks
For a xtd::span <type_t>, the xtd::span::to_string method returns a xtd::string that contains the characters pointed to by the xtd::span <type_t>. Otherwise, it returns a xtd::string with collection sequance string of the elements that the xtd::span <type_t> contains separated by , .

Reimplemented from xtd::object.

◆ try_copy_to()

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
template<xtd::usize length>
auto xtd::span< type_t, extent >::try_copy_to ( span< type_t, length > & destination) const -> bool
inlinenoexcept

Attempts to copy the current xtd::span <type_t> to a destination xtd::span <type_t> and returns a value that indicates whether the copy operation succeeded.

Parameters
destinationThe target of the copy operation.
Returns
true if the copy operation succeeded; otherwise, false.
Remarks
This method copies all of source to destination even if source and destination overlap.

◆ operator[]() [1/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::operator[] ( size_type index) const -> const_reference
inline

Gets the element at the specified zero-based index.

Parameters
indexThe zero-based index of the element.
Returns
The element at the specified index.
Exceptions
xtd::index_out_of_range_exception`index` is less than zero or greater than or equal to xtd::span::length.

◆ operator[]() [2/2]

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
auto xtd::span< type_t, extent >::operator[] ( size_type index) -> reference
inline

Gets the element at the specified zero-based index.

Parameters
indexThe zero-based index of the element.
Returns
The element at the specified index.
Exceptions
xtd::index_out_of_range_exception`index` is less than zero or greater than or equal to xtd::span::length.

Member Data Documentation

◆ empty_span

template<typename type_t, xtd::usize extent = xtd::dynamic_extent>
const span xtd::span< type_t, extent >::empty_span
static

Returns an empty xtd::span <type_t> object.

Returns
An empty xtd::span <type_t> object.

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