5#define __XTD_STD_INTERNAL__
7#undef __XTD_STD_INTERNAL__
51 template<
class type_t, xtd::size extent = dynamic_extent>
52 class read_only_span :
public xtd::object,
public xtd::iequatable<xtd::read_only_span<type_t, extent>> {
58 using element_type = std::add_cv_t<type_t>;
60 using value_type = std::add_cv_t<type_t>;
66 using pointer =
const type_t*;
68 using const_pointer =
const type_t*;
70 using reference =
const type_t&;
72 using const_reference =
const type_t&;
74 using iterator =
const xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>;
76 using const_iterator =
const xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>;
78 using reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
80 using const_reverse_iterator =
const std::reverse_iterator<xtd::collections::generic::helpers::wrap_pointer_iterator<pointer>>;
87 template <xtd::size count = 0>
94 template<
class iterator_t>
100 template<class iterator_t>
101 read_only_span(iterator_t first, xtd::size count) : data_ {&(*first)}, length_ {extent != dynamic_extent ? extent : count} {}
103#if defined(__xtd__cpp_lib_type_identity)
106 template<xtd::size len>
107 constexpr read_only_span(
const std::type_identity_t<element_type> (&array)[len]) noexcept : data_ {array}, length_ {extent !=
dynamic_extent ? extent : len} {}
111 template<xtd::size len>
116 template<
class array_type_t, xtd::size len>
118#if defined(__xtd__cpp_lib_ranges)
121 template<
class range_t>
122 constexpr read_only_span(range_t&& range) noexcept : data_ {xtd::ranges::data(range)}, length_ {extent !=
dynamic_extent ? extent : xtd::ranges::size(range)} {}
126 template<
class range_t>
131 constexpr read_only_span(std::initializer_list<type_t> items) noexcept : data_ {items.begin()}, length_ {extent !=
dynamic_extent ? extent : items.size()} {}
136 template<class collection_t>
137 constexpr read_only_span(collection_t& items) noexcept : span {items, size_type {0}, items.size()} {}
143 template<
class collection_t>
150 template<
class collection_t>
178 return *(data_ + length_ - 1);
187 const_iterator
cbegin()
const {
return const_iterator {data_};}
190 const_iterator
cend()
const {
return const_iterator {data_ + length_};}
194 const_reverse_iterator
crbegin()
const {
return const_reverse_iterator {iterator {data_ + length_}};}
197 const_reverse_iterator
crend()
const {
return const_reverse_iterator {iterator {data_}};}
201 constexpr const_pointer
data() const noexcept {
return data_;}
205 constexpr bool empty() const noexcept {
return is_empty();}
225 constexpr bool is_empty() const noexcept {
return !length_;}
229 constexpr size_type
length() const noexcept {
return length_;}
241 constexpr size_type
size() const noexcept {
return length();}
245 constexpr size_type
size_bytes() const noexcept {
return length_ *
sizeof(value_type);}
255 const_reference
at(size_type pos)
const {
257 return *(data_ + pos);
255 const_reference
at(size_type pos)
const {
…}
263 template<xtd::size length>
281 template<xtd::size count>
298 for (
const auto& item : *
this)
306 template<xtd::size count>
324 template<xtd::size start,
size_type lenght = xtd::dynamic_extent>
334 return slice(start, length_ - start);
352 template<xtd::size offset,
size_type count = xtd::dynamic_extent>
377 return xtd::string::format(
"[{}]", xtd::string::join(
", ", *
this));
384 template<xtd::size length>
386 if (destination.length() < this->length())
return false;
387 for (
auto index =
xtd::size {}; index < length_; ++index)
388 destination.at(index) =
at(index);
404 pointer data_ =
null;
405 size_type length_ = size_type {};
408 template<
class type_t, xtd::size extent>
414 template<
class iterator_t>
417 template<
class type_t, xtd::size len>
420 template<
class type_t, xtd::size len>
423#if defined(__xtd__cpp_lib_ranges)
424 template<
class range_t>
427 template<
class range_t>
431 template<
class collection_t>
434 template<
class collection_t>
437 template<
class collection_t>
440 template<
class type_t>
Contains __xtd_std_version definitions.
Contains xtd::argument_null_exception exception.
Contains xtd::argument_out_of_range_exception exception.
Contains xtd::array class.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
virtual pointer data() noexcept
Returns pointer to the underlying array serving as element storage.
Definition basic_array.hpp:166
Combines the hash code for multiple values into a single hash code.
Definition hash_code.hpp:26
xtd::size to_hash_code() const noexcept
Calculates the final hash code after consecutive xtd::hash_code::add invocations.
hash_code & add(const type_t &value) noexcept
Adds a single value to the hash code.
Definition hash_code.hpp:43
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Represents a non-owning view over a contiguous sequence of objects.
Definition span.hpp:58
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:59
@ 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:45
constexpr xtd::size dynamic_extent
Represents the constant of type xtd::size signifying that the span has dynamic extent.
Definition dynamic_extent.hpp:24
size_t size
Represents a size of any object in bytes.
Definition size.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
bool is(xtd::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:485
Contains xtd::iequatable interface.
Contains xtd::index_out_of_range_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const_reference front() const
Gets the first element.
Definition read_only_span.hpp:218
const_reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition read_only_span.hpp:237
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
constexpr read_only_span(const element_type(&array)[len]) noexcept
Creates an xtd::read_only_span with specified native array.
Definition read_only_span.hpp:112
read_only_span< type_t > subspan() const
Forms a subspan of the current read_only_span starting at a specified index for a specified length.
Definition read_only_span.hpp:353
const_iterator cbegin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:187
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
void copy_to(span< type_t, length > &destination) const
Copies the contents of this xtd::read_only_span <type_t> into a destination xtd:span <type_t>.
Definition read_only_span.hpp:264
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
constexpr bool is_empty() const noexcept
Returns a value that indicates whether the current xtd::read_only_span <type_t> is empty.
Definition read_only_span.hpp:225
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
const_iterator cend() const
Returns an iterator to the end.
Definition read_only_span.hpp:190
const_reference operator[](size_type index) const
Gets the element at the specified zero-based index.
Definition read_only_span.hpp:400
const_reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:233
const_reverse_iterator crbegin() const
Returns a reverse iterator to the beginning.
Definition read_only_span.hpp:194
bool try_copy_to(span< type_t, length > &destination) const noexcept
Attempts to copy the current xtd::read_only_span <type_t> to a destination xtd::read_only_span <type_...
Definition read_only_span.hpp:385
const_reference at(size_type pos) const
Gets the specified element with bounds checking.
Definition read_only_span.hpp:255
read_only_span< type_t > slice() const
Forms a slice out of the current read_only_span starting at a specified index for a specified length.
Definition read_only_span.hpp:325
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
constexpr size_type size_bytes() const noexcept
Returns the size of the sequence in bytes.
Definition read_only_span.hpp:245
const_reference back() const
Gets the last element.
Definition read_only_span.hpp:176
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201
const_reverse_iterator crend() const
Returns a reverse iterator to the end.
Definition read_only_span.hpp:197
xtd::array< std::remove_cv_t< type_t > > to_array() const noexcept
Copies the contents of this read_only_span into a new array.
Definition read_only_span.hpp:368
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:296
Contains xtd::null pointer valiue.
Contains xtd::object class.
Contains xtd::ptrdiff type.
Contains xtd::ranges and xtd::views namespaces.
Contains xtd::span class.
Contains typeof_ keyword.
Contains xtd::collections::generic::helpers::wrap_pointer_iterator class.