5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
57 template<
typename type_t, xtd::usize extent>
84 using reverse_iterator = std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
86 using const_reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
93 template <xtd::usize count = 0>
100 template<
typename iterator_t>
106 template<typename iterator_t>
107 span(iterator_t first, xtd::usize count) : data_ {&(*first)}, length_ {extent != dynamic_extent ? extent : count} {}
109 #if defined(__xtd__cpp_lib_type_identity)
112 template<xtd::usize len>
113 constexpr span(std::type_identity_t<element_type> (&
array)[len]) noexcept : data_ {
array}, length_ {extent !=
dynamic_extent ? extent : len} {}
117 template<xtd::usize len>
122 template<
typename array_type_t, xtd::usize len>
126 template<
typename array_type_t, xtd::usize len>
132 template<
typename array_type_t>
138 template<
typename array_type_t>
140 #if defined(__xtd__cpp_lib_ranges)
143 template<
typename range_t>
144 constexpr span(range_t&&
range) noexcept : data_ {std::ranges::data(
range)}, length_ {extent !=
dynamic_extent ? extent : std::ranges::size(range)} {}
148 template<
typename range_t>
151 #if __cplusplus >= 202002l
154 constexpr span(std::initializer_list<type_t> items)
noexcept requires std::is_const_v<element_type> : data_ {items.begin()}, length_ {extent !=
dynamic_extent ? extent : items.size()} {}
158 constexpr span(std::initializer_list<type_t> items) noexcept : data_ {
const_cast<type_t*
>(items.begin())}, length_ {extent !=
dynamic_extent ? extent : items.size()} {
159 static_assert(std::is_const_v<element_type>,
"type_t must be const");
166 template<typename collection_t>
167 constexpr span(collection_t& items) noexcept : span {items, size_type {0}, items.size()} {}
173 template<
typename collection_t>
180 template<
typename collection_t>
194 template<
typename collection_t>
203 constexpr span(
span&& items) =
default;
204 constexpr span(
const span& items) =
default;
206 auto operator =(
span&& items) ->
span& =
default;
207 auto operator =(
const span& items) ->
span& =
default;
241 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return is_empty();}
252 [[nodiscard]]
constexpr auto is_empty() const noexcept ->
bool {
return !length_;}
273 for (
auto& item : *
this)
280 template<xtd::usize length>
293 [[nodiscard]]
auto equals(
const span& rhs)
const noexcept ->
bool override {
return length() == rhs.length() &&
data() == rhs.data();}
297 auto fill(
const type_t& value) ->
void {
298 for (
auto& item : *
this)
305 template<xtd::usize count>
306 [[nodiscard]]
auto first() const ->
span<type_t, count> {
322 for (
const auto& item : *
this)
324 return result.to_hash_code();
330 template<xtd::usize count>
331 [[nodiscard]]
auto last() const ->
span<type_t, count> {
348 template<xtd::usize start,
size_type lenght = xtd::dynamic_extent>
358 return slice(start, length_ - start);
376 template<xtd::usize offset,
size_type count = xtd::dynamic_extent>
399 [[nodiscard]]
auto to_string() const noexcept ->
xtd::
string override {
408 template<xtd::usize length>
410 if (destination.length() < this->length())
return false;
411 for (
auto index =
xtd::usize {}; index < length_; ++index)
412 destination[index] =
operator [](index);
426 return *(data_ + index);
434 return *(data_ + index);
443 template<
typename type_t, xtd::usize extent>
449 template<
typename iterator_t>
452 template<
typename type_t, xtd::usize len>
455 template<
class type_t, xtd::usize len>
458 template<
class type_t, xtd::usize len>
461 template<xtd::iterable iterable_t>
464 template<
typename type_t>
467 template<
typename collection_t>
470 template<
typename collection_t>
473 template<
typename collection_t>
476 template<
typename collection_t>
479 template<
typename collection_t>
482 template<
typename collection_t>
485 template<
typename type_t>
492template<
typename type_t,
typename list_t>
497template<
typename type_t,
typename list_t>
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
virtual auto data() noexcept -> pointer override
Returns pointer to the underlying array serving as element storage.
Definition basic_array.hpp:77
static auto join(const basic_string &separator, const collection_t &values) noexcept -> basic_string
Definition basic_string.hpp:1259
virtual auto operator()(xtd::usize index) const -> const type_t &
Gets the element at the specified index.
Definition list_common.hpp:48
auto operator[](const xtd::index &index) const -> const type_t &
Gets the element at the specified index.
Represents a wrap pointer iterator.
Definition wrap_pointer_iterator.hpp:35
Combines the hash code for multiple values into a single hash code.
Definition hash_code.hpp:26
auto add(const type_t &value) noexcept -> hash_code &
Adds a single value to the hash code.
Definition hash_code.hpp:43
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
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:40
Represents a range that has start and end indexes.
Definition range.hpp:28
constexpr auto start() const noexcept -> const index_type &
Gets the inclusive start index of the Range.
Definition range.hpp:63
constexpr auto end() const noexcept -> const index_type &
Gets an Index that represents the exclusive end index of the range.
Definition range.hpp:60
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:58
constexpr span(const std::array< array_type_t, len > &array) noexcept
Creates an xtd::span with specified std::array.
Definition span.hpp:123
auto last(xtd::usize count) const -> span< type_t >
Obtains a subspan consisting of the last N elements of the sequence.
Definition span.hpp:338
constexpr span(element_type(&array)[len]) noexcept
Creates an xtd::span with specified native array.
Definition span.hpp:118
static const span empty_span
Returns an empty xtd::span <type_t> object.
Definition span.hpp:215
auto operator[](size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition span.hpp:424
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition span.hpp:237
auto subspan() const -> span< type_t >
Forms a subspan of the current span starting at a specified index for a specified length.
Definition span.hpp:377
xtd::usize size_type
Represents the span size type (usually xtd::usize).
Definition span.hpp:68
constexpr span(range_t &&range) noexcept
Creates an xtd::span with specified range.
Definition span.hpp:149
const type_t * const_pointer
Represents the span const pointer type.
Definition span.hpp:74
auto clear() noexcept -> void
Clears the contents of this xtd::span <type> object.
Definition span.hpp:272
auto to_array() const noexcept -> xtd::array< value_type >
Copies the contents of this span into a new array.
Definition span.hpp:392
const std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > > const_reverse_iterator
Represents the const reverse iterator of span value type.
Definition span.hpp:86
auto first(xtd::usize count) const -> span< type_t >
Obtains a subspan consisting of the first count elements of the sequence.
Definition span.hpp:313
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition span.hpp:320
constexpr auto length() const noexcept -> size_type
Returns the length of the current span.
Definition span.hpp:256
constexpr auto size_bytes() const noexcept -> size_type
Returns the size of the sequence in bytes.
Definition span.hpp:264
type_t * pointer
Represents the span pointer type.
Definition span.hpp:72
const type_t & const_reference
Represents the span const reference type.
Definition span.hpp:78
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition span.hpp:260
constexpr span(xtd::array< array_type_t > &items)
Creates an xtd::span with specified collection and count.
Definition span.hpp:139
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>.
Definition span.hpp:281
auto end() const -> const_iterator
Returns an iterator to the end.
Definition span.hpp:245
constexpr span()
Creates an empty xtd::span whose xtd::span::data is null and xtd::span::size is 0.
Definition span.hpp:94
constexpr span(const xtd::array< array_type_t > &items)
Creates an xtd::span with specified collection and count.
Definition span.hpp:133
constexpr span(iterator_t first, iterator_t last)
Creates an xtd::span with specified iterators.
Definition span.hpp:101
auto slice(size_type start) const -> span< type_t >
Forms a slice out of the current span that begins at a specified index.
Definition span.hpp:357
auto begin() -> iterator
Returns an iterator to the beginning.
Definition span.hpp:226
auto operator[](size_type index) -> reference
Gets the element at the specified zero-based index.
Definition span.hpp:432
constexpr span(std::array< array_type_t, len > &array) noexcept
Creates an xtd::span with specified std::array.
Definition span.hpp:127
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition span.hpp:223
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.
Definition span.hpp:386
constexpr span(collection_t &items, size_type start, size_type length)
Creates an xtd::span with specified collection, offest and count.
Definition span.hpp:181
auto slice() const -> span< type_t >
Forms a slice out of the current span starting at a specified index for a specified length.
Definition span.hpp:349
std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > > reverse_iterator
Represents the reverse iterator of span value type.
Definition span.hpp:84
xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of span value type.
Definition span.hpp:80
auto equals(const span &rhs) const noexcept -> bool override
Indicates whether the current object is equal to another object of the same type.
Definition span.hpp:293
constexpr auto empty() const noexcept -> bool
Returns a value that indicates whether the current xtd::span <type_t> is empty.
Definition span.hpp:241
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > const_iterator
Represents the const iterator of span value type.
Definition span.hpp:82
auto cbegin() const -> const_iterator
Returns an iterator to the beginning.
Definition span.hpp:230
type_t element_type
Represents the span elemeent type.
Definition span.hpp:64
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.
Definition span.hpp:366
std::remove_cv_t< type_t > value_type
Represents the span value type.
Definition span.hpp:66
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 val...
Definition span.hpp:409
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition span.hpp:289
type_t & reference
Represents the span reference type.
Definition span.hpp:76
auto fill(const type_t &value) -> void
Fills the elements of this span with a specified value.
Definition span.hpp:297
xtd::ptrdiff difference_type
Represents the span difference type (usually xtd::ptrdiff).
Definition span.hpp:70
constexpr span(type_t *const data, size_type length)
Creates an xtd::span with specified data pointer and count.
Definition span.hpp:187
auto cend() const -> const_iterator
Returns an iterator to the end.
Definition span.hpp:233
auto last() const -> span< type_t, count >
Obtains a subspan consisting of the last N elements of the sequence.
Definition span.hpp:331
auto end() -> iterator
Returns an iterator to the end.
Definition span.hpp:248
constexpr span(collection_t &items, size_type length)
Creates an xtd::span with specified collection and count.
Definition span.hpp:174
constexpr auto is_empty() const noexcept -> bool
Returns a value that indicates whether the current xtd::span <type_t> is empty.
Definition span.hpp:252
constexpr span(collection_t &items, const xtd::range &range)
Creates an xtd::span with specified collection, and range.
Definition span.hpp:195
constexpr span(std::initializer_list< type_t > items) noexcept
Creates an xtd::span with specified initializer list.
Definition span.hpp:158
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::span <type_t> object.
Definition span.hpp:399
auto first() const -> span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition span.hpp:306
Contains xtd::dynamic_extent field.
@ argument
The argument is not valid.
Definition exception_case.hpp:31
@ index_out_of_range
The index is out of range.
Definition exception_case.hpp:61
@ argument_null
The argument is null.
Definition exception_case.hpp:33
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
#define typeof_
Used to obtain the type object of a specified type or object.
Definition typeof.hpp:24
constexpr auto dynamic_extent
Represents the constant of type xtd::usize signifying that the span has dynamic extent.
Definition dynamic_extent.hpp:23
null_ptr null
Represents a null pointer value.
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
auto is(xtd::any value) -> bool
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
Contains xtd::iequatable interface.
Contains xtd::iterable concept.
Contains xtd::iterable_value_type alias.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
xtd::usize size_type
Represents the read_only_span size type (usually xtd::usize).
Definition read_only_span.hpp:62
const type_t * pointer
Represents the read_only_span pointer type.
Definition read_only_span.hpp:66
Contains xtd::null pointer valiue.
Contains xtd::object class.
Contains xtd::ptrdiff type.
Contains xtd::range class.
Contains typeof_ keyword.
Contains xtd::views alias namespace.
Contains xtd::collections::generic::helpers::wrap_pointer_iterator class.