5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
54 template<
typename type_t, xtd::usize extent>
55 class read_only_span :
public xtd::object,
public xtd::iequatable<xtd::read_only_span<type_t, extent>>,
public xtd::collections::generic::ienumerable<type_t> {
61 using element_type = std::add_const_t<type_t>;
82 template <xtd::usize count = 0>
89 template<
typename iterator_t>
95 template<typename iterator_t>
96 read_only_span(iterator_t first, xtd::usize count) : data_ {&(*first)}, length_ {extent != dynamic_extent ? extent : count} {}
98 #if defined(__xtd__cpp_lib_type_identity)
101 template<xtd::usize len>
102 constexpr read_only_span(
const std::type_identity_t<element_type> (&array)[len]) noexcept : data_ {array}, length_ {extent !=
dynamic_extent ? extent : len} {}
106 template<xtd::usize len>
111 template<
typename array_type_t, xtd::usize len>
117 template<
typename array_type_t>
119 #if defined(__xtd__cpp_lib_ranges)
122 template<
typename range_t>
123 constexpr read_only_span(range_t&& range) noexcept : data_ {std::ranges::data(range)}, length_ {extent !=
dynamic_extent ? extent : std::ranges::size(range)} {}
127 template<
typename range_t>
132 constexpr read_only_span(std::initializer_list<type_t> items) noexcept : data_ {items.begin()}, length_ {extent !=
dynamic_extent ? extent : items.size()} {}
137 template<typename collection_t>
138 constexpr read_only_span(collection_t& items) noexcept : span {items, size_type {0}, items.size()} {}
144 template<
typename collection_t>
151 template<
typename collection_t>
165 template<
typename collection_t>
168 data_ = items.data() + start;
174 template<xtd::usize extent_>
201 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return is_empty();}
205 [[nodiscard]]
constexpr auto is_empty() const noexcept ->
bool {
return !length_;}
226 template<xtd::usize length>
244 template<xtd::usize count>
257 auto get_enumerator() const ->
xtd::collections::generic::enumerator<type_t>
override {
260 explicit read_only_span_enumerator(const_pointer data,
xtd::usize length) : data_(data), length_(length) {}
261 const type_t&
current()
const override {
return *(data_ + index_);}
262 bool move_next()
override {
return ++index_ < length_;}
263 void reset()
override {index_ =
xtd::npos;}
277 for (
const auto& item : *
this)
279 return result.to_hash_code();
285 template<xtd::usize count>
303 template<xtd::usize start,
size_type lenght = xtd::dynamic_extent>
313 return slice(start, length_ - start);
331 template<xtd::usize offset,
size_type count = xtd::dynamic_extent>
354 [[nodiscard]]
auto to_string() const noexcept ->
xtd::
string override {
363 template<xtd::usize length>
365 if (destination.length() < this->length())
return false;
381 return *(data_ +
index);
420 operator std::span<type_t, extent>()
const {
return std::span<type_t, extent>(data_, length_);}
428 template<
typename type_t, xtd::usize extent>
434 template<
typename iterator_t>
437 template<
typename type_t, xtd::usize len>
440 template<
class type_t, xtd::usize len>
443 template<xtd::iterable iterable_t>
446 template<
typename collection_t>
449 template<
typename collection_t>
452 template<
typename collection_t>
455 template<
typename collection_t>
458 template<
typename type_t>
465template<
typename type_t,
typename list_t>
470template<
typename type_t,
typename list_t>
475template<
typename type_t,
typename allocator_t>
480template<
typename type_t,
typename allocator_t>
485template<
typename type_t, xtd::usize extent>
490template<
typename type_t, xtd::usize extent>
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:1240
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.
Internal vector-like container used as a storage backend for xtd collections.
Definition raw_array.hpp:38
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
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.
Represents a range that has start and end indexes.
Definition range.hpp:38
auto get_offset_and_length(size_type length) const -> offset_and_length
Calculates the start offset and length of the range object using a collection length.
Definition range.hpp:112
Definition __span_definitions.hpp:16
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:62
auto operator()(size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition span.hpp:462
auto operator[](size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition span.hpp:421
Contains xtd::collections::generic::enumerable concept.
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
auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition range.hpp:39
constexpr auto dynamic_extent
Represents the constant of type xtd::usize signifying that the span has dynamic extent.
Definition dynamic_extent.hpp:23
constexpr auto npos
Represents a value that is not a valid position in a collection.
Definition npos.hpp:26
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
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.hpp:24
@ current
Specifies the current position within a stream.
Definition seek_origin.hpp:20
@ s
The S key.
Definition console_key.hpp:124
Contains xtd::iequatable interface.
Contains xtd::index struct.
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
const type_t & reference
Represents the read_only_span reference type.
Definition read_only_span.hpp:73
constexpr auto size_bytes() const noexcept -> size_type
Returns the size of the sequence in bytes.
Definition read_only_span.hpp:217
auto subspan() const -> read_only_span< type_t >
Forms a subspan of the current read_only_span starting at a specified index for a specified length.
Definition read_only_span.hpp:332
auto to_array() const noexcept -> xtd::array< std::remove_cv_t< type_t > >
Copies the contents of this read_only_span into a new array.
Definition read_only_span.hpp:347
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:245
auto operator[](size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:379
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:354
static const read_only_span empty_read_only_span
Returns an empty xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:189
xtd::usize size_type
Represents the read_only_span size type (usually xtd::usize).
Definition read_only_span.hpp:65
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:75
constexpr auto empty() const noexcept -> bool
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:201
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:235
const type_t * pointer
Represents the read_only_span pointer type.
Definition read_only_span.hpp:69
auto last() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:286
auto try_copy_to(span< type_t, length > &destination) const noexcept -> bool
Attempts to copy the current xtd::read_only_span <type_t> to a destination xtd::read_only_span <type_...
Definition read_only_span.hpp:364
auto slice() const -> read_only_span< type_t >
Forms a slice out of the current read_only_span starting at a specified index for a specified length.
Definition read_only_span.hpp:304
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:209
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:275
auto copy_to(span< type_t, length > &destination) const -> void
Copies the contents of this xtd::read_only_span <type_t> into a destination xtd:span <type_t>.
Definition read_only_span.hpp:227
const type_t * const_pointer
Represents the read_only_span const pointer type.
Definition read_only_span.hpp:71
auto operator()(size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:401
constexpr read_only_span()
Creates an empty xtd::read_only_span whose xtd::read_only_span::data is null and xtd::read_only_span:...
Definition read_only_span.hpp:83
xtd::ptrdiff difference_type
Represents the read_only_span difference type (usually xtd::ptrdiff).
Definition read_only_span.hpp:67
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:213
constexpr auto is_empty() const noexcept -> bool
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:205
Contains xtd::null pointer valiue.
Contains xtd::object class.
Contains xtd::ptrdiff type.
Contains xtd::range class.
Contains xtd::collections::generic::helpers::raw_array class.
Contains xtd::span class.
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38
auto get_offset(value_type length) const noexcept -> xtd::usize
Calculates the offset from the start of the collection using the specified collection length.
Represents a value_type struct.
Definition value_type.hpp:34
Contains typeof_ keyword.
Contains xtd::views alias namespace.
Contains xtd::collections::generic::helpers::wrap_pointer_iterator class.