xtd 0.2.0
array.hpp
Go to the documentation of this file.
1
4#pragma once
5#define __XTD_CORE_INTERNAL__
7#undef __XTD_CORE_INTERNAL__
13#include "abstract.hpp"
14#include "byte.hpp"
15#include "core_export.hpp"
16#include "int64.hpp"
17#include "iequatable.hpp"
18#include "new_ptr.hpp"
19#include "null.hpp"
20#include "object.hpp"
21#include "static.hpp"
22#include <algorithm>
23#include <vector>
24
25#define __XTD_ARRAY_INTERNAL__
27#include "basic_array.hpp"
28#undef __XTD_ARRAY_INTERNAL__
29
31namespace xtd {
60 template<class type_t, xtd::size rank_, class allocator_t>
61 class array : public basic_array<type_t, allocator_t> {
62 public:
64
71 array() = default;
72
79 array(const array<xtd::size, 1>& lengths) : xtd::basic_array<type_t, allocator_t>(lengths) {}
81
83 array(const array& array) : xtd::basic_array<type_t, allocator_t>(array) {}
84 array(array&& array) = default;
86
88
90 xtd::size rank() const noexcept override {return rank_;}
92
94
96 array& operator=(const array&) = default;
97 array& operator=(array&&) = default;
99
100 private:
101 friend class array<>;
102 array(const array<xtd::size>& lengths, bool) : basic_array<type_t, allocator_t>(lengths) {}
103 };
104}
105
106#define __XTD_ARRAY_INTERNAL__
107#include "array_1.hpp"
108#include "array_2.hpp"
109#include "array_3.hpp"
110#include "array_static.hpp"
111#include "array_.hpp"
112#undef __XTD_ARRAY_INTERNAL__
113#define __XTD_CORE_INTERNAL__
115#undef __XTD_CORE_INTERNAL__
116
118template<class source_t>
119const xtd::linq::enumerable::ienumerable<xtd::array<source_t>>& xtd::linq::enumerable::chunk(const ienumerable<source_t>& source, size_t size) {
121 static thread_local auto chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
122 chunks = __opaque_xtd_linq_enumerable_collection__<xtd::array<source_t>> {};
123 auto chunk = std::vector<source_t> {};
124 for (auto index = size_t {0}; const auto& item : source) {
125 chunk.push_back(item);
126 if (++index % size == 0) {
127 chunks.items.push_back(chunk);
128 chunk = std::vector<source_t> {};
129 }
130 }
131 if (chunk.size() != 0) chunks.items.push_back(chunk);
132
133 return static_cast<const xtd::linq::enumerable::ienumerable<xtd::array<source_t>>&>(chunks);
134}
Contains xtd::array definitions.
Contains xtd::abstract_object class.
Contains xtd::array <type_t, 1> class.
Contains xtd::array <type_t, 2> class.
Contains xtd::array <type_t, 3> class.
Contains xtd::array class.
Contains xtd::array_abstract_object class.
Contains xtd::array <> class.
Contains xtd::basic_array class.
Contains xtd::byte type.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
array(const array< xtd::size, 1 > &lengths)
Initializes a new instance of the array class with lengths for each rank specified.
Definition array.hpp:79
xtd::size rank() const noexcept override
Gets the rank (number of dimensions) of the array.
Definition array.hpp:90
array()=default
Initializes a new instance of the array class that is empty.
Base object that represent array.
Definition basic_array.hpp:44
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
static const ienumerable< xtd::array< source_t > > & chunk(const ienumerable< source_t > &source, xtd::size size)
Splits the elements of a sequence into chunks of size at most size.
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:73
Contains core_export_ keyword.
Contains xtd::collections::generic::helpers::equator struct.
Contains xtd::collections::generic::enumerator <type_t> class.
Contains xtd::collections::generic::icomparer <type_t> interface.
Contains xtd::collections::generic::ilist <type_t> interface.
@ argument_out_of_range
The argument is out of range.
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
Contains xtd::iequatable interface.
Contains xtd::int64 type.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::new_ptr method.
Contains xtd::null pointer valiue.
Contains xtd::object class.
Contains xtd::static_object class.
Contains xtd::helpers::exception_case enum class.