xtd 0.2.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< type_t > xtd::interface xtd::extensions::equality_operators< type_t, iequatable< type_t > >

Definition

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

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

Definition
template<class type_t, xtd::size 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:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:44
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:58
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
Examples
Create a span from memory.
#include <xtd/console>
#include <xtd/span>
using namespace 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 void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition span.hpp:222
constexpr span()
Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.
Definition span.hpp:94
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10

Create a span over an array.

#include <xtd/array>
#include <xtd/console>
#include <xtd/span>
using namespace 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:59

Public Aliases

using element_type = type_t
 Represents the span elemeent type.
 
using value_type = std::remove_cv_t< type_t >
 Represents the span value type.
 
using size_type = xtd::size
 Represents the span size type (usually xtd::size).
 
using difference_type = xtd::ptrdiff
 Represents the span difference type (usually xtd::ptrdiff).
 
using pointer = type_t *
 Represents the span pointer type.
 
using const_pointer = const type_t *
 Represents the span const pointer type.
 
using reference = type_t &
 Represents the span reference type.
 
using const_reference = const type_t &
 Represents the span const reference type.
 
using iterator = xtd::collections::generic::helpers::wrap_pointer_iterator< pointer >
 Represents the iterator of span value type.
 
using const_iterator = const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer >
 Represents the const iterator of span value type.
 
using reverse_iterator = std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > >
 Represents the reverse iterator of span value type.
 
using const_reverse_iterator = const std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > >
 Represents the const reverse iterator of span value type.
 

Public Properties

static const span empty_span
 Returns an empty xtd::span <type_t> object.
 
const_reference back () const
 Gets the last element.
 
const_iterator begin () const
 Returns an iterator to the beginning.
 
iterator begin ()
 Returns an iterator to the beginning.
 
const_iterator cbegin () const
 Returns an iterator to the beginning.
 
const_iterator cend () const
 Returns an iterator to the end.
 
const_reverse_iterator crbegin () const
 Returns a reverse iterator to the beginning.
 
const_reverse_iterator crend () const
 Returns a reverse iterator to the end.
 
constexpr const_pointer data () const noexcept
 Gets direct access to the underlying contiguous storage.
 
constexpr bool empty () const noexcept
 Returns a value that indicates whether the current xtd::span <type_t> is empty.
 
const_iterator end () const
 Returns an iterator to the end.
 
iterator end ()
 Returns an iterator to the end.
 
const_reference front () const
 Gets the first element.
 
constexpr bool is_empty () const noexcept
 Returns a value that indicates whether the current xtd::span <type_t> is empty.
 
constexpr size_type length () const noexcept
 Returns the length of the current span.
 
const_reverse_iterator rbegin () const
 Returns a reverse iterator to the beginning.
 
reverse_iterator rbegin ()
 Returns a reverse iterator to the beginning.
 
const_reverse_iterator rend () const
 Returns a reverse iterator to the end.
 
reverse_iterator rend ()
 Returns a reverse iterator to the end.
 
constexpr size_type size () const noexcept
 Returns the number of elements.
 
constexpr size_type size_bytes () const noexcept
 Returns the size of the sequence in bytes.
 

Public Constructors

template<xtd::size count = 0>
constexpr span ()
 Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.
 
template<class iterator_t >
constexpr span (iterator_t first, iterator_t last)
 Creates an xtd::span with specified iterators.
 
template<xtd::size len>
constexpr span (element_type(&array)[len]) noexcept
 Creates an xtd::span with specified native array.
 
template<class array_type_t , xtd::size len>
constexpr span (const std::array< array_type_t, len > &array) noexcept
 Creates an xtd::span with specified std::array.
 
template<class array_type_t , xtd::size len>
constexpr span (std::array< array_type_t, len > &array) noexcept
 Creates an xtd::span with specified std::array.
 
template<class 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<class collection_t >
constexpr span (collection_t &items, size_type length)
 Creates an xtd::span with specified collection and count.
 
template<class 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 Methods

const_reference at (size_type pos) const
 Gets the specified element with bounds checking.
 
reference at (size_type pos)
 Gets the specified element with bounds checking.
 
void clear () noexcept
 Clears the contents of this xtd::span <type> object.
 
template<xtd::size length>
void copy_to (span< type_t, length > &destination) const
 Copies the contents of this xtd::span <type_t> into a destination xtd:span <type_t>.
 
bool equals (const object &obj) const noexcept override
 Determines whether the specified object is equal to the current object.
 
bool equals (const span &rhs) const noexcept override
 Indicates whether the current object is equal to another object of the same type.
 
void fill (const type_t &value)
 Fills the elements of this span with a specified value.
 
template<xtd::size count>
span< type_t, count > first () const
 Obtains a subspan consisting of the first count elements of the sequence.
 
span< type_t > first (xtd::size count) const
 Obtains a subspan consisting of the first count elements of the sequence.
 
xtd::size get_hash_code () const noexcept override
 Serves as a hash function for a particular type.
 
template<xtd::size count>
span< type_t, count > last () const
 Obtains a subspan consisting of the last N elements of the sequence.
 
span< type_t > last (xtd::size count) const
 Obtains a subspan consisting of the last N elements of the sequence.
 
template<xtd::size start, size_type lenght = xtd::dynamic_extent>
span< type_t > slice () const
 Forms a slice out of the current span starting at a specified index for a specified length.
 
span< type_t > slice (size_type start) const
 Forms a slice out of the current span that begins at a specified index.
 
span< type_t > slice (size_type start, size_type length) const
 Forms a slice out of the current span starting at a specified index for a specified length.
 
template<xtd::size offset, size_type count = xtd::dynamic_extent>
span< type_t > subspan () const
 Forms a subspan of the current span starting at a specified index for a specified length.
 
span< type_t > subspan (size_type offset, size_type count=xtd::dynamic_extent) const
 Forms a subspan of the current span starting at a specified index for a specified length.
 
xtd::array< value_typeto_array () const noexcept
 Copies the contents of this span into a new array.
 
string to_string () const noexcept override
 Returns the string representation of this xtd::span <type_t> object.
 
template<xtd::size length>
bool try_copy_to (span< type_t, length > &destination) const noexcept
 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

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

Additional Inherited Members

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

Member Typedef Documentation

◆ element_type

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::element_type = type_t

Represents the span elemeent type.

◆ value_type

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::value_type = std::remove_cv_t<type_t>

Represents the span value type.

◆ size_type

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::size_type = xtd::size

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

◆ difference_type

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::difference_type = xtd::ptrdiff

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

◆ pointer

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::pointer = type_t*

Represents the span pointer type.

◆ const_pointer

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::const_pointer = const type_t*

Represents the span const pointer type.

◆ reference

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::reference = type_t&

Represents the span reference type.

◆ const_reference

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::const_reference = const type_t&

Represents the span const reference type.

◆ iterator

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::iterator = xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>

Represents the iterator of span value type.

◆ const_iterator

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::const_iterator = const xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>

Represents the const iterator of span value type.

◆ reverse_iterator

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::reverse_iterator = std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer> >

Represents the reverse iterator of span value type.

◆ const_reverse_iterator

template<class type_t , xtd::size extent = dynamic_extent>
using xtd::span< type_t, extent >::const_reverse_iterator = const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer> >

Represents the const reverse iterator of span value type.

Constructor & Destructor Documentation

◆ span() [1/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size count = 0>
constexpr 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/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class iterator_t >
constexpr 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/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size len>
constexpr 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/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class array_type_t , xtd::size len>
constexpr 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/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class array_type_t , xtd::size len>
constexpr 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/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class range_t >
constexpr 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() [7/10]

template<class type_t , xtd::size extent = dynamic_extent>
constexpr 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() [8/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class collection_t >
constexpr 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() [9/10]

template<class type_t , xtd::size extent = dynamic_extent>
template<class collection_t >
constexpr 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() [10/10]

template<class type_t , xtd::size extent = dynamic_extent>
constexpr 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

◆ back()

template<class type_t , xtd::size extent = dynamic_extent>
const_reference xtd::span< type_t, extent >::back ( ) const
inline

Gets the last element.

Returns
The last element.
Exceptions
argument_out_of_range_exceptionif xtd::san i empty.

◆ begin() [1/2]

template<class type_t , xtd::size extent = dynamic_extent>
const_iterator xtd::span< type_t, extent >::begin ( ) const
inline

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ begin() [2/2]

template<class type_t , xtd::size extent = dynamic_extent>
iterator xtd::span< type_t, extent >::begin ( )
inline

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ cbegin()

template<class type_t , xtd::size extent = dynamic_extent>
const_iterator xtd::span< type_t, extent >::cbegin ( ) const
inline

Returns an iterator to the beginning.

Returns
The iterator of the first element.

◆ cend()

template<class type_t , xtd::size extent = dynamic_extent>
const_iterator xtd::span< type_t, extent >::cend ( ) const
inline

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ crbegin()

template<class type_t , xtd::size extent = dynamic_extent>
const_reverse_iterator xtd::span< type_t, extent >::crbegin ( ) const
inline

Returns a reverse iterator to the beginning.

Returns
The reverse iterator of the first element.

◆ crend()

template<class type_t , xtd::size extent = dynamic_extent>
const_reverse_iterator xtd::span< type_t, extent >::crend ( ) const
inline

Returns a reverse iterator to the end.

Returns
The reverse iterator to the element following the last element.

◆ data()

template<class type_t , xtd::size extent = dynamic_extent>
constexpr const_pointer xtd::span< type_t, extent >::data ( ) const
inlineconstexprnoexcept

Gets direct access to the underlying contiguous storage.

Returns
A pointer to the beginning of the sequence.

◆ empty()

template<class type_t , xtd::size extent = dynamic_extent>
constexpr bool xtd::span< type_t, extent >::empty ( ) const
inlineconstexprnoexcept

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<class type_t , xtd::size extent = dynamic_extent>
const_iterator xtd::span< type_t, extent >::end ( ) const
inline

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ end() [2/2]

template<class type_t , xtd::size extent = dynamic_extent>
iterator xtd::span< type_t, extent >::end ( )
inline

Returns an iterator to the end.

Returns
The iterator to the element following the last element.

◆ front()

template<class type_t , xtd::size extent = dynamic_extent>
const_reference xtd::span< type_t, extent >::front ( ) const
inline

Gets the first element.

Returns
The first element.
Exceptions
argument_out_of_range_exceptionif xtd::san i empty.

◆ is_empty()

template<class type_t , xtd::size extent = dynamic_extent>
constexpr bool xtd::span< type_t, extent >::is_empty ( ) const
inlineconstexprnoexcept

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<class type_t , xtd::size extent = dynamic_extent>
constexpr size_type xtd::span< type_t, extent >::length ( ) const
inlineconstexprnoexcept

Returns the length of the current span.

Returns
The length of the current span.

◆ rbegin() [1/2]

template<class type_t , xtd::size extent = dynamic_extent>
const_reverse_iterator xtd::span< type_t, extent >::rbegin ( ) const
inline

Returns a reverse iterator to the beginning.

Returns
The reverse iterator of the first element.

◆ rbegin() [2/2]

template<class type_t , xtd::size extent = dynamic_extent>
reverse_iterator xtd::span< type_t, extent >::rbegin ( )
inline

Returns a reverse iterator to the beginning.

Returns
The reverse iterator of the first element.

◆ rend() [1/2]

template<class type_t , xtd::size extent = dynamic_extent>
const_reverse_iterator xtd::span< type_t, extent >::rend ( ) const
inline

Returns a reverse iterator to the end.

Returns
The reverse iterator to the element following the last element.

◆ rend() [2/2]

template<class type_t , xtd::size extent = dynamic_extent>
reverse_iterator xtd::span< type_t, extent >::rend ( )
inline

Returns a reverse iterator to the end.

Returns
The reverse iterator to the element following the last element.

◆ size()

template<class type_t , xtd::size extent = dynamic_extent>
constexpr size_type xtd::span< type_t, extent >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements.

Returns
The number of elements in the span.

◆ size_bytes()

template<class type_t , xtd::size extent = dynamic_extent>
constexpr size_type xtd::span< type_t, extent >::size_bytes ( ) const
inlineconstexprnoexcept

Returns the size of the sequence in bytes.

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

◆ at() [1/2]

template<class type_t , xtd::size extent = dynamic_extent>
const_reference xtd::span< type_t, extent >::at ( size_type  pos) const
inline

Gets the specified element with bounds checking.

Parameters
posThe position of the element to return.
Returns
Reference to the requested element.
Exceptions
xtd::index_out_of_range_exception`index` is less than zero or greater than or equal to xtd::span::length.

◆ at() [2/2]

template<class type_t , xtd::size extent = dynamic_extent>
reference xtd::span< type_t, extent >::at ( size_type  pos)
inline

Gets the specified element with bounds checking.

Parameters
posThe position of the element to return.
Returns
Reference to the requested element.
Exceptions
xtd::argument_out_of_range_exceptionvif pos greather or equal than length.

◆ clear()

template<class type_t , xtd::size extent = dynamic_extent>
void xtd::span< type_t, extent >::clear ( )
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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size length>
void xtd::span< type_t, extent >::copy_to ( span< type_t, length > &  destination) const
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<class type_t , xtd::size extent = dynamic_extent>
bool xtd::span< type_t, extent >::equals ( const object obj) const
inlineoverridevirtualnoexcept

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<class type_t , xtd::size extent = dynamic_extent>
bool xtd::span< type_t, extent >::equals ( const span< type_t, extent > &  rhs) const
inlineoverridenoexcept

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<class type_t , xtd::size extent = dynamic_extent>
void xtd::span< type_t, extent >::fill ( const type_t &  value)
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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size count>
span< type_t, count > xtd::span< type_t, extent >::first ( ) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
span< type_t > xtd::span< type_t, extent >::first ( xtd::size  count) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
xtd::size xtd::span< type_t, extent >::get_hash_code ( ) const
inlineoverridevirtualnoexcept

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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size count>
span< type_t, count > xtd::span< type_t, extent >::last ( ) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
span< type_t > xtd::span< type_t, extent >::last ( xtd::size  count) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size start, size_type lenght = xtd::dynamic_extent>
span< type_t > xtd::span< type_t, extent >::slice ( ) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
span< type_t > xtd::span< type_t, extent >::slice ( size_type  start) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
span< type_t > xtd::span< type_t, extent >::slice ( size_type  start,
size_type  length 
) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size offset, size_type count = xtd::dynamic_extent>
span< type_t > xtd::span< type_t, extent >::subspan ( ) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
span< type_t > xtd::span< type_t, extent >::subspan ( size_type  offset,
size_type  count = xtd::dynamic_extent 
) const
inline

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<class type_t , xtd::size extent = dynamic_extent>
xtd::array< value_type > xtd::span< type_t, extent >::to_array ( ) const
inlinenoexcept

Copies the contents of this span into a new array.

Returns
An array containing the data in the current span.

◆ to_string()

template<class type_t , xtd::size extent = dynamic_extent>
string xtd::span< type_t, extent >::to_string ( ) const
inlineoverridevirtualnoexcept

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<class type_t , xtd::size extent = dynamic_extent>
template<xtd::size length>
bool xtd::span< type_t, extent >::try_copy_to ( span< type_t, length > &  destination) const
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<class type_t , xtd::size extent = dynamic_extent>
const_reference xtd::span< type_t, extent >::operator[] ( size_type  index) const
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<class type_t , xtd::size extent = dynamic_extent>
reference xtd::span< type_t, extent >::operator[] ( size_type  index)
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<class type_t , xtd::size extent>
const span< type_t, extent > xtd::span< type_t, extent >::empty_span
inlinestatic

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: