5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
52 template<
typename type_t, xtd::usize extent>
53 class read_only_span :
public xtd::object,
public xtd::iequatable<xtd::read_only_span<type_t, extent>> {
59 using element_type = std::add_cv_t<type_t>;
79 using reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
81 using const_reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
88 template <xtd::usize count = 0>
95 template<
typename iterator_t>
101 template<typename iterator_t>
102 read_only_span(iterator_t first, xtd::usize count) : data_ {&(*first)}, length_ {extent != dynamic_extent ? extent : count} {}
104 #if defined(__xtd__cpp_lib_type_identity)
107 template<xtd::usize len>
108 constexpr read_only_span(
const std::type_identity_t<element_type> (&array)[len]) noexcept : data_ {array}, length_ {extent !=
dynamic_extent ? extent : len} {}
112 template<xtd::usize len>
117 template<
typename array_type_t, xtd::usize len>
123 template<
typename array_type_t>
125 #if defined(__xtd__cpp_lib_ranges)
128 template<
typename range_t>
129 constexpr read_only_span(range_t&& range) noexcept : data_ {std::ranges::data(range)}, length_ {extent !=
dynamic_extent ? extent : std::ranges::size(range)} {}
133 template<
typename range_t>
138 constexpr read_only_span(std::initializer_list<type_t> items) noexcept : data_ {items.begin()}, length_ {extent !=
dynamic_extent ? extent : items.size()} {}
143 template<typename collection_t>
144 constexpr read_only_span(collection_t& items) noexcept : span {items, size_type {0}, items.size()} {}
150 template<
typename collection_t>
157 template<
typename collection_t>
171 template<
typename collection_t>
215 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return is_empty();}
223 [[nodiscard]]
constexpr auto is_empty() const noexcept ->
bool {
return !length_;}
244 template<xtd::usize length>
262 template<xtd::usize count>
279 for (
const auto& item : *
this)
281 return result.to_hash_code();
287 template<xtd::usize count>
305 template<xtd::usize start,
size_type lenght = xtd::dynamic_extent>
315 return slice(start, length_ - start);
333 template<xtd::usize offset,
size_type count = xtd::dynamic_extent>
356 [[nodiscard]]
auto to_string() const noexcept ->
xtd::
string override {
365 template<xtd::usize length>
367 if (destination.length() < this->length())
return false;
368 for (
auto index =
xtd::usize {}; index < length_; ++index)
369 destination[index] =
operator [](index);
383 return *(data_ + index);
392 template<
typename type_t, xtd::usize extent>
398 template<
typename iterator_t>
401 template<
typename type_t, xtd::usize len>
404 template<
class type_t, xtd::usize len>
407 template<xtd::iterable iterable_t>
410 template<
typename collection_t>
413 template<
typename collection_t>
416 template<
typename collection_t>
419 template<
typename collection_t>
422 template<
typename type_t>
429template<
typename type_t,
typename list_t>
434template<
typename type_t,
typename list_t>
439template<
typename type_t,
typename allocator_t>
444template<
typename type_t,
typename allocator_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:1231
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
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.
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:59
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
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:75
const type_t & reference
Represents the read_only_span reference type.
Definition read_only_span.hpp:71
constexpr auto size_bytes() const noexcept -> size_type
Returns the size of the sequence in bytes.
Definition read_only_span.hpp:235
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:334
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:349
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:263
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:200
auto operator[](size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:381
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:356
const std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > > reverse_iterator
Represents the reverse iterator of read_only_span value type.
Definition read_only_span.hpp:79
static const read_only_span empty_read_only_span
Returns an empty xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:192
xtd::usize size_type
Represents the read_only_span size type (usually xtd::usize).
Definition read_only_span.hpp:63
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:73
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:215
const std::reverse_iterator< xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > > const_reverse_iterator
Represents the const reverse iterator of read_only_span value type.
Definition read_only_span.hpp:81
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:211
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:253
const type_t * pointer
Represents the read_only_span pointer type.
Definition read_only_span.hpp:67
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:288
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:366
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:306
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:227
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:277
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:245
const type_t * const_pointer
Represents the read_only_span const pointer type.
Definition read_only_span.hpp:69
auto cend() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:207
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:219
auto cbegin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:204
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:89
xtd::ptrdiff difference_type
Represents the read_only_span difference type (usually xtd::ptrdiff).
Definition read_only_span.hpp:65
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:231
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:223
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > const_iterator
Represents the const iterator of read_only_span value type.
Definition read_only_span.hpp:77
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 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.