xtd 1.0.0
Loading...
Searching...
No Matches
array_static.hpp
Go to the documentation of this file.
1
4
5#if !defined(__XTD_ARRAY_INTERNAL__)
6#error "Do not include this file: Internal use only. Include <xtd/array> or <xtd/array.hpp> instead."
7#endif
8
12
14namespace xtd {
17 template<typename type_t>
19 }
21
50 template<>
51 class array<> static_ {
52 public:
54
57
59
70 template<typename type_t, typename allocator_t>
72
91 template<typename type_t, typename allocator_t, typename value_t>
114 template<typename type_t, typename allocator_t, typename value_t>
117 auto first = array.data_->items.begin();
118 auto last = array.data_->items.begin();
119 std::advance(first, index);
120 std::advance(last, index + count);
121 auto position = std::lower_bound(first, last, value, xtd::collections::generic::helpers::lesser<type_t> {comparer});
122
123 if (position != array.data_->items.end() && !comparer.compare(value, *position))
124 return std::distance(array.data_->items.begin(), position);
125 return ~std::distance(array.data_->items.begin(), position);
126 }
127
142 template<typename type_t, typename allocator_t, typename value_t>
143 [[nodiscard]] static auto binary_search(const array<type_t, 1, allocator_t>& array, const value_t& value) -> xtd::usize {return binary_search(array, 0, array.length(), value, xtd::collections::generic::comparer<type_t>::default_comparer);}
163 template<typename type_t, typename allocator_t, typename value_t>
164 [[nodiscard]] static auto binary_search(const array<type_t, 1, allocator_t>& array, const value_t& value, const xtd::collections::generic::icomparer<type_t>& comparer) -> xtd::usize {return binary_search(array, 0, array.length(), value, comparer);}
165
168 template<typename type_t, xtd::usize rank, typename allocator_t>
169 static auto clear(const array<type_t, rank, allocator_t>& array) -> void {clear(array, 0, array.data_->items.size());}
178 template<typename type_t, xtd::usize rank, typename allocator_t>
181 for (auto increment = xtd::usize {}; increment < length; ++increment)
182 array.data_->items[index + increment] = type_t {};
183 }
184
194 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
195 static auto constrained_copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const xtd::array<xtd::usize>& source_indexes, array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, const xtd::array<xtd::usize>& destination_indexes, xtd::usize length) -> void {constrained_copy(source_array, xtd::basic_array<source_type_t, source_allocator_t>::compute_index(source_indexes), destination_array, xtd::basic_array<destination_type_t, destination_allocator_t>::compute_index(destination_indexes), length);}
205 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
207 if (source_array.rank() != destination_array.rank()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::rank);
208 for (auto r = xtd::usize {0}; r < source_array.rank(); ++r)
209 if (source_array.get_length(r) != destination_array.get_length(r)) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument);
210 if (source_index < source_array.get_lower_bound(0) || destination_index < destination_array.get_lower_bound(0)) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument_out_of_range);
211 if (source_index + length > source_array.length() || destination_index + length > destination_array.length()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument);
212
213 auto tmp_array = destination_array;
214 for (auto i = source_index; i < (source_index + length); ++i)
215 tmp_array.data_->items[destination_index++] = source_array.data_->items[i];
216 destination_array.data_->items.swap(tmp_array.data_->items);
217 }
218
226 template<typename output_t, typename input_t, xtd::usize rank, typename allocator_t, typename converter_t, typename destination_allocator_t = xtd::collections::generic::helpers::allocator<output_t>>
228 auto result = create_instance<output_t, rank>(array.get_lengths());
229 for (auto i = xtd::usize {0}; i < array.length(); ++i)
230 result[i] = converter(array[i]);
231 return result;
232 }
233
239 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
240 static auto copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array) -> void {copy(source_array, 0, destination_array, 0, destination_array.length());}
246 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
247 static auto copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, xtd::usize length) -> void {copy(source_array, 0, destination_array, 0, length);}
255 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
256 static auto copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const xtd::array<xtd::usize>& source_indexes, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, const xtd::array<xtd::usize>& destination_indexes, xtd::usize length) -> void {
257 copy(source_array, source_array.compute_index(source_array, source_indexes), destination_array, destination_array.compute_index(destination_array, destination_indexes), length);
258 }
259
266 template<typename source_type_t, xtd::usize source_rank, typename source_allocator_t, typename destination_type_t, xtd::usize destination_rank, typename destination_allocator_t>
267 static auto copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, xtd::usize source_index, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, xtd::usize destination_index, xtd::usize length) -> void; // defined in as.hpp file
268
281 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
296 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
297 [[nodiscard]] static auto create_instance(xtd::usize length1, xtd::usize length2) -> xtd::array<type_t, 2, allocator_t> {return xtd::array<type_t, 2, allocator_t>(length1, length2);}
312 template<typename type_t, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
313 [[nodiscard]] static auto create_instance(xtd::usize length1, xtd::usize length2, xtd::usize length3) -> xtd::array<type_t, 3, allocator_t> {return xtd::array<type_t, 3, allocator_t>(length1, length2, length3);}
324 template<typename type_t, xtd::usize rank, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
325 [[nodiscard]] static auto create_instance(const xtd::array<xtd::usize>& lengths) -> xtd::array<type_t, rank, allocator_t> {return xtd::array<type_t, rank, allocator_t>(lengths, type_t {});}
326
332 template<typename type_t, xtd::usize rank, typename allocator_t, typename predicate_t>
333 [[nodiscard]] static auto exists(const xtd::array<type_t, rank, allocator_t>& array, predicate_t match) -> bool {
334 for (const type_t& elem : array)
335 if (match(elem)) return true;
336 return false;
337 }
338
346 template<typename type_t, xtd::usize rank, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
347 [[nodiscard]] static auto index_of(const xtd::array<type_t, rank, allocator_t>& array, const type_t& value) noexcept -> xtd::usize {return array.index_of(value);}
357 template<typename type_t, xtd::usize rank, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
358 [[nodiscard]] static auto index_of(const xtd::array<type_t, rank, allocator_t>& array, const type_t& value, xtd::usize index) -> xtd::usize {return array.index_of(value, index);}
369 template<typename type_t, xtd::usize rank, typename allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
370 [[nodiscard]] static auto index_of(const xtd::array<type_t, rank, allocator_t>& array, const type_t& value, xtd::usize index, xtd::usize count) -> xtd::usize {
371 return array.index_of(value, index, count);
372 }
373
381 template<typename type_t, typename allocator_t>
382 static auto resize(xtd::array<type_t, 1, allocator_t>& array, int32 new_size) -> void {array.resize(new_size);}
383
387 template<typename type_t, typename allocator_t>
388 static auto reverse(xtd::array<type_t, 1, allocator_t>& array) -> void {array.reverse(0, array.length());}
395 template<typename type_t, typename allocator_t>
398 };
399}
static auto binary_search(const array< type_t, 1, allocator_t > &array, const value_t &value, const xtd::collections::generic::icomparer< type_t > &comparer) -> xtd::usize
Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::...
Definition array_static.hpp:164
static auto exists(const xtd::array< type_t, rank, allocator_t > &array, predicate_t match) -> bool
Determines whether the xtd::array <type_t> contains elements that match the conditions defined by the...
Definition array_static.hpp:333
static auto binary_search(const array< type_t, 1, allocator_t > &array, xtd::usize index, xtd::usize count, const value_t &value, const xtd::collections::generic::icomparer< type_t > &comparer) -> xtd::usize
Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::...
Definition array_static.hpp:115
static auto copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array) -> void
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:240
static auto resize(xtd::array< type_t, 1, allocator_t > &array, int32 new_size) -> void
Changes the number of elements of a one-dimensional array to the specified new size.
Definition array_static.hpp:382
static auto binary_search(const array< type_t, 1, allocator_t > &array, const value_t &value) -> xtd::usize
Searches an entire one-dimensional sorted array for a specific element, using the xtd::icomparable in...
Definition array_static.hpp:143
static auto constrained_copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::usize source_index, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::usize destination_index, xtd::usize length) -> void
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:206
static auto constrained_copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::usize > &source_indexes, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::usize > &destination_indexes, xtd::usize length) -> void
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:195
static auto copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::usize source_index, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::usize destination_index, xtd::usize length) -> void
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
static auto as_read_only(const xtd::array< type_t, 1, allocator_t > &array) -> xtd::collections::object_model::read_only_collection< type_t >
Returns a read-only wrapper for the specified array.
static auto binary_search(const array< type_t, 1, allocator_t > &array, int32 index, int32 length, const value_t &value) -> xtd::usize
Searches a range of elements in a one-dimensional sorted array for a value, using the xtd::icomparabl...
Definition array_static.hpp:92
static auto create_instance(xtd::usize length1, xtd::usize length2) -> xtd::array< type_t, 2, allocator_t >
Creates a two-dimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:297
static auto reverse(xtd::array< type_t, 1, allocator_t > &array, int32 index, int32 count) -> void
Reverses the order of the elements in the specified range.
Definition array_static.hpp:396
static auto copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::usize > &source_indexes, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::usize > &destination_indexes, xtd::usize length) -> void
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:256
static auto create_instance(xtd::usize length) -> xtd::array< type_t, 1, allocator_t >
Creates a one-dimensional xtd::array <type_t> of the specified Type and length, with zero-based index...
Definition array_static.hpp:282
static auto convert_all(const xtd::array< input_t, rank, allocator_t > &array, converter_t converter) -> xtd::array< output_t, rank, destination_allocator_t >
Converts an array of one type to an array of another type.
Definition array_static.hpp:227
static auto create_instance(const xtd::array< xtd::usize > &lengths) -> xtd::array< type_t, rank, allocator_t >
Creates a multidimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:325
static auto index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::usize index, xtd::usize count) -> xtd::usize
Determines the index of a specific item in the array specified.
Definition array_static.hpp:370
static auto clear(const array< type_t, rank, allocator_t > &array, xtd::usize index, xtd::usize length) -> void
Sets a range of elements in an array to the default value of each element type.
Definition array_static.hpp:179
static auto reverse(xtd::array< type_t, 1, allocator_t > &array) -> void
Reverses the order of the elements in the entire xtd::basic_array.
Definition array_static.hpp:388
static auto copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::usize length) -> void
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:247
static auto index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::usize index) -> xtd::usize
Determines the index of a specific item in the array specified.
Definition array_static.hpp:358
static auto create_instance(xtd::usize length1, xtd::usize length2, xtd::usize length3) -> xtd::array< type_t, 3, allocator_t >
Creates a three-dimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:313
static auto clear(const array< type_t, rank, allocator_t > &array) -> void
Clears the contents of an array.
Definition array_static.hpp:169
static auto index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value) noexcept -> xtd::usize
Determines the index of a specific item in the array specified.
Definition array_static.hpp:347
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
array()=default
auto count() const noexcept -> size_type override
Definition basic_array.hpp:72
virtual auto length() const noexcept -> size_type
Definition basic_array.hpp:122
auto compare(const first_argument_type &x, const second_argument_type &y) const -> result_type override
Compares two entities and returns a value indicating whether one is less than, equal to,...
Definition comparer.hpp:66
static const comparer< xtd::any_object > default_comparer
Definition comparer.hpp:50
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Provides the base class for a generic read-only collection.
Definition read_only_collection.hpp:39
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Contains xtd::collections::generic::comparer <type_t> class.
xtd::delegate< output_t(input_t input)> converter
Represents a method that converts an object from one type to another type.
Definition converter.hpp:33
@ 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
@ rank
The rank is not valid.
Definition exception_case.hpp:93
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:25
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
@ r
The R key.
Definition console_key.hpp:122
@ i
The I key.
Definition console_key.hpp:104
Contains xtd::collections::generic::helpers::lesser struct.
Contains classes that can be used as collections in the object model of a reusable library....
Definition read_only_collection.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
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:245
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:286
Implements a function object for compare data.
Definition lesser.hpp:39
Represents a type that can be used to index a collection either from the beginning or the end.
Definition index.hpp:38
Contains xtd::helpers::throw_helper class.