xtd 1.0.0
Loading...
Searching...
No Matches
index.hpp
Go to the documentation of this file.
1
4#pragma once
8#include "iequatable.hpp"
9#include "integer.hpp"
10#include "is.hpp"
11#include "logical.hpp"
12#include "object.hpp"
13#include "usize.hpp"
14#include "npos.hpp"
15
17namespace xtd {
31 struct index : public xtd::object, xtd::iequatable<index> {
33
36 using value_type = xtd::usize;
38
40
43 constexpr index() noexcept = default;
48 constexpr index(xtd::integer auto value, xtd::logical auto from_end) noexcept : __v__{static_cast<value_type>(from_end ? ~value : value)} {}
52 constexpr explicit index(xtd::integer auto value) noexcept : index {value, false} {}
54
56
60 [[nodiscard]] constexpr auto value() const noexcept -> value_type {return is_from_end() ? ~__v__ : __v__;}
61
62 [[nodiscard]] constexpr auto is_from_end() const noexcept -> bool {return __v__ > std::numeric_limits<value_type>::max() / 2;}
64
71 [[nodiscard]] constexpr auto equals(const object& obj) const noexcept -> bool override {return is<index>(obj) && equals(static_cast<const index&>(obj));}
75 [[nodiscard]] constexpr auto equals(const index& value) const noexcept -> bool override {return xtd::collections::generic::helpers::equator<value_type> {}(__v__, value.__v__);}
76
79 [[nodiscard]] constexpr auto get_hash_code() const noexcept -> xtd::usize override {return hash_code::combine(__v__);}
80
84 [[nodiscard]] constexpr auto get_offset(value_type length) const noexcept -> xtd::usize {return is_from_end() ? length - value() : value();}
85
88 [[nodiscard]] auto to_string() const noexcept -> xtd::string override;
90
96 operator value_type() {return __v__;}
99 constexpr operator value_type() const {return __v__;}
101
120 static const index end;
121
138 static const index last;
139
156 static const index start;
158
165 inline static constexpr auto from_end(xtd::integer auto value) {return index {value, true};}
166
170 inline static constexpr auto from_start(xtd::integer auto value) {return index {value};}
172
174 value_type __v__ = value_type {0};
176 };
177}
178
180inline constexpr const xtd::index xtd::index::end {0, true};
181inline constexpr const xtd::index xtd::index::last {1, true};
182inline constexpr const xtd::index xtd::index::start {0};
184
185#include "literals/index.hpp"
186
188template<typename type_t, typename allocator_t>
189auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator [](const xtd::index& index) const -> const_reference {return operator [](index.get_offset(size()));}
190
191template<typename type_t, typename allocator_t>
192auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator [](const xtd::index& index) -> reference {return operator [](index.get_offset(size()));}
193
194template<typename type_t, typename list_t>
195auto xtd::collections::generic::extensions::list_common<type_t, list_t>::operator [](const xtd::index& index) const -> const type_t& {return self().operator [](index.get_offset(self().count()));}
196
197template<typename type_t, typename list_t>
198auto xtd::collections::generic::extensions::list_common<type_t, list_t>::operator [](const xtd::index& index) -> type_t& {return self().operator [](index.get_offset(self().count()));}
199
200template<typename type_t, typename list_t>
201auto xtd::collections::generic::extensions::list_common<type_t, list_t>::operator ()(const xtd::index& index) const -> const type_t& {return self().operator [](index);}
202
203template<typename type_t, typename list_t>
205 return self().operator [](index);
206}
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:34
Contains xtd::collections::generic::helpers::equator struct.
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
@ integer
Indicates that the allow_leading_white, allow_trailing_white, and allow_leading_sign styles are used....
Definition number_styles.hpp:44
@ start
Starting of a logical operation.
Definition trace_event_type.hpp:37
Contains xtd::iequatable interface.
Contains xtd::integer concept.
Contains xtd::is method.
Contains xtd::collections::generic::extensions::list_common class.
Contains xtd::usize suffixes.
Contains xtd::logical concept.
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:70
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:355
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:72
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:252
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:287
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:226
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
Definition read_only_span.hpp:276
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:218
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:230
std::add_cv_t< type_t > value_type
Represents the read_only_span value type.
Definition read_only_span.hpp:60
Contains xtd::npos constant.
Contains xtd::object class.
Contains xtd::collections::generic::helpers::raw_array class.
Contains xtd::usize type.