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 {
38 struct index : public xtd::object, xtd::iequatable<index> {
40
45
47
50 constexpr index() noexcept = default;
55 constexpr index(xtd::integer auto value, xtd::logical auto from_end) noexcept : __v__{static_cast<value_type>(from_end ? ~value : value)} {}
59 constexpr explicit index(xtd::integer auto value) noexcept : index {value, false} {}
61
63
67 [[nodiscard]] constexpr auto value() const noexcept -> value_type {return is_from_end() ? ~__v__ : __v__;}
68
71 [[nodiscard]] constexpr auto is_from_end() const noexcept -> bool {return __v__ > std::numeric_limits<value_type>::max() / 2;}
73
75
80 [[nodiscard]] auto equals(const object& obj) const noexcept -> bool override;
84 [[nodiscard]] auto equals(const index& value) const noexcept -> bool override;
85
88 [[nodiscard]] auto get_hash_code() const noexcept -> xtd::usize override;
89
93 [[nodiscard]] auto get_offset(value_type length) const noexcept -> xtd::usize;
94
97 [[nodiscard]] auto to_string() const noexcept -> xtd::string override;
98
101 [[nodiscard]] constexpr auto to_usize() const noexcept -> value_type {return __v__;}
103
105 auto operator ++() noexcept -> xtd::index&;
106 auto operator --() noexcept -> xtd::index&;
107 auto operator ++(int) noexcept -> xtd::index;
108 auto operator --(int) noexcept -> xtd::index;
109 constexpr auto operator ~() const noexcept -> xtd::index {return xtd::index {~__v__};}
110 constexpr auto operator +() const noexcept -> xtd::index {return xtd::index {+__v__};}
111 constexpr auto operator +(xtd::integer auto v) const noexcept -> xtd::index {return xtd::index {__v__ + static_cast<value_type>(v)};}
112 constexpr auto operator -(xtd::integer auto v) const noexcept -> xtd::index {return xtd::index {__v__ - static_cast<value_type>(v)};}
113 constexpr auto operator *(xtd::integer auto v) const noexcept -> xtd::index {return xtd::index {__v__ * static_cast<value_type>(v)};}
114 constexpr auto operator /(xtd::integer auto v) const noexcept -> xtd::index {return xtd::index {__v__ / static_cast<value_type>(v)};}
115 constexpr auto operator %(xtd::integer auto v) const noexcept -> xtd::index {return xtd::index {__v__ % static_cast<value_type>(v)};}
117
119
136 static const index end;
137
154 static const index last;
155
172 static const index start;
174
176
181 inline static constexpr auto from_end(xtd::integer auto value) {return index {value, true};}
182
186 inline static constexpr auto from_start(xtd::integer auto value) {return index {value};}
187
191 [[nodiscard]] static auto parse(const xtd::string& value) -> xtd::index;
192
197 [[nodiscard]] static auto try_parse(const xtd::string& value, xtd::index& result) noexcept -> bool;
199
201 value_type __v__ = value_type {0};
203 };
204}
205
207inline constexpr const xtd::index xtd::index::end {0, true};
208inline constexpr const xtd::index xtd::index::last {1, true};
209inline constexpr const xtd::index xtd::index::start {0};
211
212#include "literals/index.hpp"
213
215template<typename type_t, typename allocator_t>
216auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator [](const xtd::index& index) const -> const_reference {return operator [](index.get_offset(size()));}
217
218template<typename type_t, typename allocator_t>
219auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator [](const xtd::index& index) -> reference {return operator [](index.get_offset(size()));}
220
221template<typename type_t, typename allocator_t>
222auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator ()(const xtd::index& index) const -> const_reference {return operator [](index.get_offset(size()));}
223
224template<typename type_t, typename allocator_t>
225auto xtd::collections::generic::helpers::raw_array<type_t, allocator_t>::operator ()(const xtd::index& index) -> reference {return operator [](index.get_offset(size()));}
226
227template<typename type_t, typename list_t>
228auto 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()));}
229
230template<typename type_t, typename list_t>
231auto 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()));}
232
233template<typename type_t, typename list_t>
234auto xtd::collections::generic::extensions::list_common<type_t, list_t>::operator ()(const xtd::index& index) const -> const type_t& {return self().operator [](index);}
235
236template<typename type_t, typename list_t>
238 return self().operator [](index);
239}
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
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:23
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:40
Definition integer.hpp:12
Definition logical.hpp:13
Contains xtd::collections::generic::helpers::equator struct.
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
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
@ v
The V key.
Definition console_key.hpp:130
Contains xtd::iequatable interface.
Contains xtd::integer concept.
Contains xtd::is method.
Contains xtd::collections::generic::extensions::list_common class.
Contains xtd::index 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:73
const type_t & const_reference
Represents the read_only_span const reference type.
Definition read_only_span.hpp:75
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:209
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:213
Contains xtd::npos constant.
Contains xtd::object class.
Contains xtd::collections::generic::helpers::raw_array class.
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38
static constexpr auto from_end(xtd::integer auto value)
Creates an xtd::ndex from the end of a collection at a specified index position.
Definition index.hpp:181
auto to_string() const noexcept -> xtd::string override
Returns the string representation of the current Range object.
xtd::usize value_type
Represents the xtd::index index type.
Definition index.hpp:43
static constexpr auto from_start(xtd::integer auto value)
Creates an xtd::ndex from the start of a collection at a specified index position.
Definition index.hpp:186
static const index start
Represents the index of the first valid element in a collection.
Definition index.hpp:172
static auto parse(const xtd::string &value) -> xtd::index
Converts the string to xtd::index equivalent.
static const index end
Represents a value that is not a valid position in a collection.
Definition index.hpp:136
static const index last
Represents the index of the last valid element in a collection.
Definition index.hpp:154
constexpr index() noexcept=default
Instantiates a new xtd::index instance.
constexpr index(xtd::integer auto value) noexcept
Initializes a new xtd::index with a specified index position and a value that indicates if the index ...
Definition index.hpp:59
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
constexpr auto to_usize() const noexcept -> value_type
Returns the xtd::usize representation of the current Range object.
Definition index.hpp:101
static auto try_parse(const xtd::string &value, xtd::index &result) noexcept -> bool
Converts the string to xtd::index equivalent. A return value indicates whether the conversion succeed...
constexpr auto is_from_end() const noexcept -> bool
Gets a value that indicates whether the index is from the start or the end.
Definition index.hpp:71
auto get_offset(value_type length) const noexcept -> xtd::usize
Calculates the offset from the start of the collection using the specified collection length.
constexpr auto value() const noexcept -> value_type
Gets an xtd::index that represents the exclusive end index of the range.
Definition index.hpp:67
auto get_hash_code() const noexcept -> xtd::usize override
Serves as a hash function for a particular type.
auto equals(const index &value) const noexcept -> bool override
Indicates whether the current object is equal to another object of the same type.
Contains xtd::usize type.