5#define __XTD_STD_INTERNAL__
7#undef __XTD_STD_INTERNAL__
48 template<
typename type_t, xtd::usize extent = xtd::dynamic_extent>
49 class read_only_span :
public xtd::object,
public xtd::iequatable<xtd::read_only_span<type_t, extent>> {
55 using element_type = std::add_cv_t<type_t>;
75 using reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
77 using const_reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
84 template <xtd::usize count = 0>
91 template<
typename iterator_t>
97 template<typename iterator_t>
98 read_only_span(iterator_t first, xtd::usize count) : data_ {&(*first)}, length_ {extent != dynamic_extent ? extent : count} {}
100 #if defined(__xtd__cpp_lib_type_identity)
103 template<xtd::usize len>
104 constexpr read_only_span(
const std::type_identity_t<element_type> (&array)[len]) noexcept : data_ {array}, length_ {extent !=
dynamic_extent ? extent : len} {}
108 template<xtd::usize len>
113 template<
typename array_type_t, xtd::usize len>
119 template<
typename array_type_t>
121 #if defined(__xtd__cpp_lib_ranges)
124 template<
typename range_t>
125 constexpr read_only_span(range_t&& range) noexcept : data_ {std::ranges::data(range)}, length_ {extent !=
dynamic_extent ? extent : std::ranges::size(range)} {}
129 template<
typename range_t>
134 constexpr read_only_span(std::initializer_list<type_t> items) noexcept : data_ {items.begin()}, length_ {extent !=
dynamic_extent ? extent : items.size()} {}
139 template<typename collection_t>
140 constexpr read_only_span(collection_t& items) noexcept : span {items, size_type {0}, items.size()} {}
146 template<
typename collection_t>
153 template<
typename collection_t>
201 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return is_empty();}
209 [[nodiscard]]
constexpr auto is_empty() const noexcept ->
bool {
return !length_;}
230 template<xtd::usize length>
248 template<xtd::usize count>
265 for (
const auto& item : *
this)
267 return result.to_hash_code();
273 template<xtd::usize count>
291 template<xtd::usize start,
size_type lenght = xtd::dynamic_extent>
301 return slice(start, length_ - start);
319 template<xtd::usize offset,
size_type count = xtd::dynamic_extent>
342 [[nodiscard]]
auto to_string() const noexcept ->
xtd::
string override {
351 template<xtd::usize length>
353 if (destination.length() < this->length())
return false;
354 for (
auto index =
xtd::usize {}; index < length_; ++index)
355 destination[index] =
operator [](index);
369 return *(data_ + index);
378 template<
typename type_t, xtd::usize extent>
384 template<
typename iterator_t>
387 template<
typename type_t, xtd::usize len>
390 template<
class type_t, xtd::usize len>
393 #if defined(__xtd__cpp_lib_ranges)
394 template<
typename range_t>
397 template<
typename range_t>
401 template<
typename collection_t>
404 template<
typename collection_t>
407 template<
typename collection_t>
410 template<
typename type_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
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:1258
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 non-owning view over a contiguous sequence of objects.
Definition span.hpp:55
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 xtd::usize dynamic_extent
Represents the constant of type xtd::usize signifying that the span has dynamic extent.
Definition dynamic_extent.hpp:24
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.
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:71
const type_t & reference
Represents the read_only_span reference type.
Definition read_only_span.hpp:67
constexpr auto size_bytes() const noexcept -> size_type
Returns the size of the sequence in bytes.
Definition read_only_span.hpp:221
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:320
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:335
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:249
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:186
auto operator[](size_type index) const -> const_reference
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:367
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:342
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:75
static const read_only_span empty_read_only_span
Returns an empty xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:178
xtd::usize size_type
Represents the read_only_span size type (usually xtd::usize).
Definition read_only_span.hpp:59
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:69
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
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:77
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:239
const type_t * pointer
Represents the read_only_span pointer type.
Definition read_only_span.hpp:63
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:274
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:352
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:292
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:213
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:263
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:231
const type_t * const_pointer
Represents the read_only_span const pointer type.
Definition read_only_span.hpp:65
auto cend() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:193
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:205
auto cbegin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:190
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:85
xtd::ptrdiff difference_type
Represents the read_only_span difference type (usually xtd::ptrdiff).
Definition read_only_span.hpp:61
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:217
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:209
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:73
Contains xtd::null pointer valiue.
Contains xtd::object class.
Contains xtd::ptrdiff type.
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.