xtd 0.2.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
11
13namespace xtd {
16 template<class type_t>
18 }
20
49 template<>
50 class array<> static_ {
51 public:
53
56
58
69 template<class type_t, class allocator_t>
71
90 template<class type_t, class allocator_t>
113 template<class type_t, class allocator_t>
116 typename std::vector<type_t>::const_iterator first = array.array.begin();
117 typename std::vector<type_t>::const_iterator last = array.array.begin();
118 std::advance(first, index);
119 std::advance(last, index + count);
120 typename std::vector<type_t>::const_iterator position = std::lower_bound(first, last, value, xtd::array<type_t>::comparer(&comparer));
121
122 if (position != array.array.end() && !comparer->Compare(value, *position))
123 return (int32)std::distance(array.array.begin(), position);
124 return (int32)~std::distance(array.array.begin(), position);
125 }
126
141 template<class type_t, class allocator_t>
162 template<class type_t, class allocator_t>
163 inline static xtd::size binary_search(const array<type_t, 1, allocator_t>& array, const type_t& value, const xtd::collections::generic::icomparer<type_t>& comparer) {return binary_search(array, 0, array.Length, value, comparer);}
164
167 template<class type_t, xtd::size rank, class allocator_t>
168 inline static void clear(const array<type_t, rank, allocator_t>& array) {clear(array, 0, array.data_->items.size());}
177 template<class type_t, xtd::size rank, class allocator_t>
180 for (auto increment = xtd::size {}; increment < length; ++increment)
181 array.data_->items[index + increment] = type_t {};
182 }
183
193 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
194 static void constrained_copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const xtd::array<xtd::size>& source_indexes, array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, const xtd::array<xtd::size>& destination_indexes, xtd::size length) {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);}
204 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
206 if (source_array.rank() != destination_array.rank()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::rank);
207 for (auto r = xtd::size{0}; r < source_array.rank(); ++r)
209 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);
210 if (source_index + length > source_array.length() || destination_index + length > destination_array.length()) xtd::helpers::throw_helper::throws(xtd::helpers::exception_case::argument);
211
212 auto tmp_array = destination_array;
213 for (auto i = source_index; i < (source_index + length); ++i)
214 tmp_array.data_->items[destination_index++] = source_array.data_->items[i];
215 destination_array.data_->items.swap(tmp_array.data_->items);
216 }
217
225 template<class output_t, class input_t, xtd::size rank, class allocator_t, class converter_t, class destination_allocator_t = xtd::collections::generic::helpers::allocator<output_t>>
227 auto result = create_instance<output_t, rank>(array.get_lengths());
228 for (auto i = xtd::size {0}; i < array.length(); ++i)
229 result[i] = converter(array[i]);
230 return result;
231 }
232
238 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
239 inline static void 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) {copy(source_array, 0, destination_array, 0, destination_array.length());}
245 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
246 inline static void 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::size length) {copy(source_array, 0, destination_array, 0, length);}
254 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
255 inline static void copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, const xtd::array<xtd::size>& source_indexes, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, const xtd::array<xtd::size>& destination_indexes, xtd::size length) {
256 copy(source_array, source_array.compute_index(source_array, source_indexes), destination_array, destination_array.compute_index(destination_array, destination_indexes), length);
257 }
258
265 template<class source_type_t, xtd::size source_rank, class source_allocator_t, class destination_type_t, xtd::size destination_rank, class destination_allocator_t>
266 inline static void copy(const array<source_type_t, source_rank, source_allocator_t>& source_array, xtd::size source_index, const array<destination_type_t, destination_rank, destination_allocator_t>& destination_array, xtd::size destination_index, xtd::size length); // defined in as.hpp file
267
280 template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
295 template<class type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
311 template<typename type_t, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
312 static xtd::array<type_t, 3, allocator_t> create_instance(xtd::size length1, xtd::size length2, xtd::size length3) {return xtd::array<type_t, 3, allocator_t>(length1, length2, length3);}
323 template<class type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
325
331 template<class type_t, xtd::size rank, class allocator_t, class predicate_t>
332 static bool exists(const xtd::array<type_t, rank, allocator_t>& array, predicate_t match) {
333 for (const type_t& elem : array)
334 if (match(elem)) return true;
335 return false;
336 }
337
345 template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
346 static xtd::size index_of(const xtd::array<type_t, rank, allocator_t>& array, const type_t& value) noexcept {return array.index_of(value);}
356 template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
357 static xtd::size index_of(const xtd::array<type_t, rank, allocator_t>& array, const type_t& value, xtd::size index) {return array.index_of(value, index);}
368 template<typename type_t, xtd::size rank, class allocator_t = xtd::collections::generic::helpers::allocator<type_t>>
370 return array.index_of(value, index, count);
371 }
372
380 template<class type_t, class allocator_t>
381 static void resize(xtd::array<type_t, 1, allocator_t>& array, int32 new_size) {array.resize(new_size);}
382
386 template<class type_t, class allocator_t>
387 static void reverse(xtd::array<type_t, 1, allocator_t>& array) {array.reverse(0, array.length());}
394 template<class type_t, class allocator_t>
397 };
398}
static xtd::array< type_t, 3, allocator_t > create_instance(xtd::size length1, xtd::size length2, xtd::size length3)
Creates a three-dimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:312
static xtd::size index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::size index)
Determines the index of a specific item in the array specified.
Definition array_static.hpp:357
static xtd::array< type_t, rank, allocator_t > create_instance(const xtd::array< xtd::size > &lengths)
Creates a multidimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:324
static void 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::size length)
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:246
static bool exists(const xtd::array< type_t, rank, allocator_t > &array, predicate_t match)
Determines whether the xtd::array <type_t> contains elements that match the conditions defined by the...
Definition array_static.hpp:332
static void reverse(xtd::array< type_t, 1, allocator_t > &array)
Reverses the order of the elements in the entire xtd::basic_array.
Definition array_static.hpp:387
static xtd::size binary_search(const array< type_t, 1, allocator_t > &array, xtd::size index, xtd::size count, const type_t &value, const xtd::collections::generic::icomparer< type_t > &comparer)
Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::...
Definition array_static.hpp:114
static void 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)
Copies a range of elements from an xtd::array starting at the first element and pastes them into anot...
Definition array_static.hpp:239
static xtd::size binary_search(const array< type_t, 1, allocator_t > &array, const type_t &value, const xtd::collections::generic::icomparer< type_t > &comparer)
Searches a range of elements in a one-dimensional sorted array for a value, using the specified xtd::...
Definition array_static.hpp:163
static xtd::size binary_search(const array< type_t, 1, allocator_t > &array, const type_t &value)
Searches an entire one-dimensional sorted array for a specific element, using the xtd::icomparable in...
Definition array_static.hpp:142
static xtd::collections::object_model::read_only_collection< type_t > as_read_only(const xtd::array< type_t, 1, allocator_t > &array)
Returns a read-only wrapper for the specified array.
static void resize(xtd::array< type_t, 1, allocator_t > &array, int32 new_size)
Changes the number of elements of a one-dimensional array to the specified new size.
Definition array_static.hpp:381
static xtd::size index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value) noexcept
Determines the index of a specific item in the array specified.
Definition array_static.hpp:346
static void copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::size source_index, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size destination_index, xtd::size length)
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
static void copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::size > &source_indexes, const array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::size > &destination_indexes, xtd::size length)
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:255
static xtd::size index_of(const xtd::array< type_t, rank, allocator_t > &array, const type_t &value, xtd::size index, xtd::size count)
Determines the index of a specific item in the array specified.
Definition array_static.hpp:369
static void reverse(xtd::array< type_t, 1, allocator_t > &array, int32 index, int32 count)
Reverses the order of the elements in the specified range.
Definition array_static.hpp:395
static xtd::array< type_t, 2, allocator_t > create_instance(xtd::size length1, xtd::size length2)
Creates a two-dimensional xtd::array <type_t> of the specified Type and dimension lengths,...
Definition array_static.hpp:296
static xtd::array< output_t, rank, destination_allocator_t > convert_all(const xtd::array< input_t, rank, allocator_t > &array, converter_t converter)
Converts an array of one type to an array of another type.
Definition array_static.hpp:226
static void constrained_copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, xtd::size source_index, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, xtd::size destination_index, xtd::size length)
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:205
static xtd::array< type_t, 1, allocator_t > create_instance(xtd::size length)
Creates a one-dimensional xtd::array <type_t> of the specified Type and length, with zero-based index...
Definition array_static.hpp:281
static void constrained_copy(const array< source_type_t, source_rank, source_allocator_t > &source_array, const xtd::array< xtd::size > &source_indexes, array< destination_type_t, destination_rank, destination_allocator_t > &destination_array, const xtd::array< xtd::size > &destination_indexes, xtd::size length)
Copies a range of elements from an xtd::array starting at the specified source index and pastes them ...
Definition array_static.hpp:194
static void clear(const array< type_t, rank, allocator_t > &array, xtd::size index, xtd::size length)
Sets a range of elements in an array to the default value of each element type.
Definition array_static.hpp:178
static int32 binary_search(const array< type_t, 1, allocator_t > &array, int32 index, int32 length, const type_t &value)
Searches a range of elements in a one-dimensional sorted array for a value, using the xtd::icomparabl...
Definition array_static.hpp:91
static void clear(const array< type_t, rank, allocator_t > &array)
Clears the contents of an array.
Definition array_static.hpp:168
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
xtd::size rank() const noexcept override
Gets the rank (number of dimensions) of the array.
Definition array.hpp:136
array()=default
size_type count() const noexcept override
Definition basic_array.hpp:74
constexpr size_type get_length(size_type dimension) const
Gets the total number of elements in all the dimensions of the array.
Definition basic_array.hpp:257
constexpr size_type get_lower_bound(size_type dimension) const
Gets the lower bound of the specified dimension in the array.
Definition basic_array.hpp:279
virtual size_type length() const noexcept
Definition basic_array.hpp:124
virtual const base_type & items() const noexcept
Returns the underlying base type items.
Definition basic_array.hpp:113
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:38
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
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:37
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
@ r
The R key.
Definition console_key.hpp:122
@ i
The I key.
Definition console_key.hpp:104
Contains classes that can be used as collections in the object model of a reusable library....
Definition read_only_collection.hpp:15
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
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
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
Contains xtd::helpers::throw_helper class.