xtd 1.0.0
Loading...
Searching...
No Matches
enumerable.hpp
Go to the documentation of this file.
1
4#pragma once
7
9namespace xtd {
11 namespace collections {
13 namespace generic {
15 namespace extensions {
31 template<typename value_t, typename enumerable_t>
32 class enumerable {
33 public:
35
38 using enumerable_type = enumerable_t;
40 using value_type = value_t;
42 template<typename type_t>
44
46 template<typename type_t>
49
51
59 template<xtd::func_callable<value_t, value_t, value_t> func_t>
60 [[nodiscard]] auto aggregate(func_t&& func) const -> value_t {
61 return xtd::linq::enumerable::aggregate(self(), std::forward<func_t>(func));
62 }
63
71 template<typename accumulate_t, xtd::func_callable<accumulate_t, accumulate_t, value_t> func_t>
72 [[nodiscard]] auto aggregate(accumulate_t&& seed, func_t&& func) const -> accumulate_t {
73 return xtd::linq::enumerable::aggregate(self(), std::forward<accumulate_t>(seed), std::forward<func_t>(func));
74 }
75
85 template<typename result_t, typename accumulate_t, xtd::func_callable<accumulate_t, accumulate_t, value_t> func_t, xtd::func_callable<result_t, value_t> result_selector_t>
86 [[nodiscard]] auto aggregate(accumulate_t&& seed, func_t&& func, result_selector_t&& result_selector) const -> result_t {
87 return xtd::linq::enumerable::aggregate(self(), std::forward<accumulate_t>(seed), std::forward<func_t>(func), std::forward<result_selector_t>(result_selector));
88 }
89
96 template<xtd::predicate_callable<value_t> predicate_t>
97 [[nodiscard]] auto all(predicate_t&& predicate) const -> bool {
98 return xtd::linq::enumerable::all(self(), std::forward<predicate_t>(predicate));
99 }
100
106 [[nodiscard]] auto any() const noexcept -> bool {
107 return xtd::linq::enumerable::any(self());
108 }
109
115 template<xtd::predicate_callable<value_t> predicate_t>
116 [[nodiscard]] auto any(predicate_t&& predicate) const -> bool {
117 return xtd::linq::enumerable::any(self(), std::forward<predicate_t>(predicate));
118 }
119
126 template<typename element_t>
127 [[nodiscard]] auto append(element_t&& element) const noexcept {
128 return xtd::linq::enumerable::append(self(), std::forward<element_t>(element));
129 }
130
136 [[nodiscard]] auto as_enumerable() const noexcept {
138 }
139
143 [[nodiscard]] auto average() const noexcept {
144 return xtd::linq::enumerable::average(self());
145 }
146
151 template<typename result_t>
152 [[nodiscard]] auto cast() const noexcept {
154 }
155
161 [[nodiscard]] auto chunk(xtd::usize size) const {
162 return xtd::linq::enumerable::chunk(self(), size);
163 }
164
168 template<xtd::forward_iterable second_t>
169 [[nodiscard]] auto concat(second_t&& second) const noexcept {
170 return xtd::linq::enumerable::concat(self(), std::forward<second_t>(second));
171 }
172
176 [[nodiscard]] auto contains(value_t&& value) const noexcept -> bool {
177 return xtd::linq::enumerable::contains(self(), std::forward<value_t>(value));
178 }
179
183 [[nodiscard]] auto contains(value_t&& value, xtd::collections::generic::iequality_comparer<value_t>&& comparer) const noexcept -> bool {
184 return xtd::linq::enumerable::contains(self(), std::forward<value_t>(value), std::forward<xtd::collections::generic::iequality_comparer<value_t>>(comparer));
185 }
186
190 template<xtd::func_callable<bool, value_t, value_t> equater_t>
191 [[nodiscard]] auto contains(value_t&& value, equater_t&& equater) const noexcept -> bool {
192 return xtd::linq::enumerable::contains(self(), std::forward<value_t>(value), std::forward<equater_t>(equater));
193 }
194
200 [[nodiscard]] auto count() const noexcept -> xtd::usize {
201 return xtd::linq::enumerable::count(self());
202 }
203
209 template<xtd::predicate_callable<value_t> predicate_t>
210 [[nodiscard]] auto count(predicate_t&& predicate) const noexcept -> xtd::usize {
211 return xtd::linq::enumerable::count(self(), std::forward<predicate_t>(predicate));
212 }
213
216 [[nodiscard]] auto count(value_t&& value) const noexcept -> xtd::usize {
217 return xtd::linq::enumerable::count(self(), std::forward<value_t>(value));
218 }
219
227 template<typename key_t, xtd::callable<key_t, value_t> key_selector_t>
228 [[nodiscard]] auto count_by(key_selector_t&& key_selector) const noexcept {
229 return xtd::linq::enumerable::count_by<key_t, value_t>(self(), std::forward<key_selector_t>(key_selector));
230 }
231
239 template<typename key_t, xtd::callable<key_t, value_t> key_selector_t>
240 [[nodiscard]] auto count_by(key_selector_t&& key_selector, xtd::collections::generic::iequality_comparer<key_t>&& key_comparer) const noexcept {
241 return xtd::linq::enumerable::count_by<key_t, value_t>(self(), std::forward<key_selector_t>(key_selector), std::forward<xtd::collections::generic::iequality_comparer<key_t>>(key_comparer));
242 }
243
251 template<typename key_t, xtd::callable<key_t, value_t> key_selector_t, xtd::callable<bool, key_t, key_t> key_equater_t>
252 [[nodiscard]] auto count_by(key_selector_t&& key_selector, key_equater_t&& key_equater) const noexcept {
253 return xtd::linq::enumerable::count_by<key_t, value_t>(self(), std::forward<key_selector_t>(key_selector), std::forward<key_equater_t>(key_equater));
254 }
255
258 [[nodiscard]] auto default_if_empty() const noexcept {
260 }
261
264 [[nodiscard]] auto default_if_empty(value_t&& default_value) const noexcept {
265 return xtd::linq::enumerable::default_if_empty(self(), std::forward<value_t>(default_value));
266 }
267
270 [[nodiscard]] auto distinct() const noexcept {
271 return xtd::linq::enumerable::distinct(self());
272 }
273
280
284 template<xtd::func_callable<bool, value_t, value_t> equater_t>
285 [[nodiscard]] auto distinct(equater_t&& equater) const noexcept {
286 return xtd::linq::enumerable::distinct(self(), std::forward<equater_t>(equater));
287 }
288
293 template<xtd::predicate_callable<value_t> predicate_t>
294 [[nodiscard]] auto first_or_default(predicate_t&& predicate, value_t&& default_value) const noexcept -> value_t {
295 return xtd::linq::enumerable::first_or_default(self(), std::forward<predicate_t>(predicate), std::forward<value_t>(default_value));
296 }
297
300 template<xtd::predicate_callable<value_t> predicate_t>
301 [[nodiscard]] auto first_or_default(predicate_t&& predicate) const noexcept -> value_t {
302 return xtd::linq::enumerable::first_or_default(self(), std::forward<predicate_t>(predicate));
303 }
304
307 [[nodiscard]] auto first_or_default(value_t&& default_value) const noexcept -> value_t {
308 return xtd::linq::enumerable::first_or_default(self(), std::forward<value_t>(default_value));
309 }
310
312 [[nodiscard]] auto first_or_default() const noexcept -> value_t {
314 }
315
316 [[nodiscard]] auto max() const requires xtd::numeric<value_t> {
317 return xtd::linq::enumerable::max(self());
318 }
319 template<typename result_t, xtd::callable<result_t, value_t> selector_t>
321 [[nodiscard]] auto max(selector_t&& selector) const {
322 return xtd::linq::enumerable::max<result_t>(self(), std::forward<selector_t>(selector));
323 }
324 template<xtd::callable<value_t, value_t> selector_t>
325 [[nodiscard]] auto max(selector_t&& selector) const requires xtd::numeric<value_t> {
326 return xtd::linq::enumerable::max(self(), std::forward<selector_t>(selector));
327 }
328
329 template<typename result_t>
331 [[nodiscard]] auto min(auto&& selector) const {
332 return xtd::linq::enumerable::min<result_t, value_t>(self(), selector);
333 }
334 [[nodiscard]] auto min(auto&& selector) const requires xtd::numeric<value_t> {
335 return xtd::linq::enumerable::min(self(), selector);
336 }
337 [[nodiscard]] auto min() const requires xtd::numeric<value_t> {
338 return xtd::linq::enumerable::min(self());
339 }
340
344 [[nodiscard]] auto order() const {
345 return xtd::linq::enumerable::order(self());
346 }
347
353 }
354
360 [[nodiscard]] auto order_by(const std::function<value_t(const value_t&)>& key_selector) const {
361 return xtd::linq::enumerable::order_by(self(), key_selector);
362 }
363
369 template<typename key_t>
370 [[nodiscard]] auto order_by_descending(const std::function<key_t(const value_t&)>& key_selector) const {
372 }
373
379 [[nodiscard]] auto order_by_descending(const std::function<value_t(const value_t&)>& key_selector) const {
380 return xtd::linq::enumerable::order_by_descending(self(), key_selector);
381 }
382
388 template<typename key_t>
389 [[nodiscard]] auto order_by(const std::function<key_t(const value_t&)>& key_selector) const {
390 return xtd::linq::enumerable::order_by<key_t, value_t>(self(), key_selector);
391 }
392
400 [[nodiscard]] auto select(auto&& selector) const {
401 return xtd::linq::enumerable::select(self(), selector);
402 }
403
411 template<typename result_t>
412 [[nodiscard]] auto select(auto&& selector) const {
413 return xtd::linq::enumerable::select<result_t>(self(), selector);
414 }
415
421 [[nodiscard]] auto to_array() const -> xtd::array<value_t>;
422
428 [[nodiscard]] auto to_list() const -> xtd::collections::generic::list<value_t>;
429
439 auto where(auto&& predicate) const {
441 }
442
443
444 private:
445 auto self() const noexcept -> const enumerable_t& {return static_cast<const enumerable_t&>(*this);}
446 };
447 }
448 }
449 }
450}
451
452#define __XTD_CORE_INTERNAL__
454#undef __XTD_CORE_INTERNAL__
455#include "../ienumerable.hpp"
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
auto contains(value_t &&value) const noexcept -> bool
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:176
auto order(const xtd::collections::generic::icomparer< value_t > &comparer) const
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:351
auto to_list() const -> xtd::collections::generic::list< value_t >
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
value_t value_type
Represents the ienumerable value type.
Definition enumerable.hpp:40
auto chunk(xtd::usize size) const
Splits the elements of a sequence into chunks of size at most size.
Definition enumerable.hpp:161
auto count(predicate_t &&predicate) const noexcept -> xtd::usize
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:210
auto concat(second_t &&second) const noexcept
Concatenates two sequences.
Definition enumerable.hpp:169
auto average() const noexcept
Computes the average of a sequence of value_t values.
Definition enumerable.hpp:143
auto first_or_default(predicate_t &&predicate) const noexcept -> value_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:301
auto append(element_t &&element) const noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:127
auto default_if_empty(value_t &&default_value) const noexcept
Returns the elements of the specified sequence or the specified value in a singleton collection if th...
Definition enumerable.hpp:264
auto count_by(key_selector_t &&key_selector, xtd::collections::generic::iequality_comparer< key_t > &&key_comparer) const noexcept
Returns the count of elements in the current sequence grouped by key.
Definition enumerable.hpp:240
auto first_or_default() const noexcept -> value_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:312
auto default_if_empty() const noexcept
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
Definition enumerable.hpp:258
auto aggregate(accumulate_t &&seed, func_t &&func, result_selector_t &&result_selector) const -> result_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:86
auto count_by(key_selector_t &&key_selector) const noexcept
Returns the count of elements in the current sequence grouped by key.
Definition enumerable.hpp:228
auto any(predicate_t &&predicate) const -> bool
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:116
enumerable_t enumerable_type
Represents the ienumerable enumerable type.
Definition enumerable.hpp:38
auto to_array() const -> xtd::array< value_t >
Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto order() const
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:344
auto order_by_descending(const std::function< key_t(const value_t &)> &key_selector) const
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:370
auto select(auto &&selector) const
Projects each element of a sequence into a new form.
Definition enumerable.hpp:400
auto any() const noexcept -> bool
Determines whether a sequence contains any elements.
Definition enumerable.hpp:106
auto order_by(const std::function< key_t(const value_t &)> &key_selector) const
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:389
auto aggregate(accumulate_t &&seed, func_t &&func) const -> accumulate_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:72
auto distinct(xtd::collections::generic::iequality_comparer< value_t > &&comparer) const noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable.hpp:277
typename xtd::linq::enumerable::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:47
auto contains(value_t &&value, equater_t &&equater) const noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:191
auto cast() const noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
Definition enumerable.hpp:152
auto order_by_descending(const std::function< value_t(const value_t &)> &key_selector) const
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:379
auto all(predicate_t &&predicate) const -> bool
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:97
auto select(auto &&selector) const
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:412
auto first_or_default(predicate_t &&predicate, value_t &&default_value) const noexcept -> value_t
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:294
auto count() const noexcept -> xtd::usize
Returns the number of elements in current sequence.
Definition enumerable.hpp:200
auto contains(value_t &&value, xtd::collections::generic::iequality_comparer< value_t > &&comparer) const noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:183
auto as_enumerable() const noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:136
auto order_by(const std::function< value_t(const value_t &)> &key_selector) const
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:360
auto count_by(key_selector_t &&key_selector, key_equater_t &&key_equater) const noexcept
Returns the count of elements in the current sequence grouped by key.
Definition enumerable.hpp:252
auto aggregate(func_t &&func) const -> value_t
Applies an accumulator function over a sequence.
Definition enumerable.hpp:60
auto distinct() const noexcept
Returns distinct elements from a sequence by using the default equality comparer to compare values.
Definition enumerable.hpp:270
typename xtd::linq::enumerable::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:43
auto first_or_default(value_t &&default_value) const noexcept -> value_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:307
auto where(auto &&predicate) const
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:439
auto count(value_t &&value) const noexcept -> xtd::usize
Returns the number of elements with the specified value.
Definition enumerable.hpp:216
auto distinct(equater_t &&equater) const noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable.hpp:285
Exposes a method that compares two objects.
Definition icomparer.hpp:30
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
static auto chunk(source_t &&source, xtd::usize size) -> xtd::collections::generic::enumerable_generator< xtd::array< xtd::iterable_value_type< source_t > > >
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:88
static auto distinct(source_t &&source) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns distinct elements from a sequence by using the default equality comparer to compare values.
static auto concat(first_t &&first, second_t &&second) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< first_t > >
Concatenates two sequences.
static auto first_or_default(source_t &&source, prediacte_t &&predicate, xtd::iterable_value_type< source_t > &&default_value) noexcept -> xtd::iterable_value_type< source_t >
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable_.hpp:92
static auto select(source_t &&source, auto &&selector) -> xtd::collections::generic::enumerable_generator< result_t >
Projects each element of a sequence into a new form.
static auto default_if_empty(source_t &&source) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
static auto contains(source_t &&source, const xtd::iterable_value_type< source_t > &value) noexcept -> bool
Determines whether a sequence contains a specified element by using the default equality comparer.
static auto count_by(source_t &&source, key_selector_t &&key_selector) noexcept -> xtd::collections::generic::enumerable_generator< xtd::collections::generic::key_value_pair< key_t, xtd::usize > >
Returns the count of elements in the source sequence grouped by key.
static auto all(source_t &&source, predicate_t &&predicate) -> bool
Determines whether all elements of a sequence satisfy a condition.
static auto cast(source_t &&source) -> xtd::collections::generic::enumerable_generator< result_t >
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static auto aggregate(source_t &&source, func_t &&func) -> xtd::iterable_value_type< source_t >
Applies an accumulator function over a sequence.
static auto as_enumerable(source_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto average(source_t &&source) -> xtd::decimal
Computes the average of a sequence of xtd::decimal values.
static auto order_by_descending(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable_.hpp:738
static auto order_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable_.hpp:708
static auto order(const ienumerable< source_t > &source)
Sorts the elements of a sequence in ascending order.
Definition enumerable_.hpp:685
static auto append(source_t &&source, xtd::iterable_value_type< source_t > &&element) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Appends a value to the end of the sequence.
static auto where(const ienumerable< source_t > &source, auto &&predicate)
Filters a sequence of values based on a predicate.
Definition enumerable_.hpp:860
static auto count(source_t &&source) noexcept -> xtd::usize
Returns the number of elements in a sequence.
static auto max(source_t &&source) -> xtd::iterable_value_type< source_t >
Returns the maximum value in a sequence of xtd::numeric values.
static auto any(source_t &&source) noexcept -> bool
Determines whether a sequence contains any elements.
Definition enumerable.hpp:17
Definition numeric.hpp:12
Contains foreach_ keyword.
Contains xtd::collections::generic::ienumerable <type_t> interface.
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
xtd::func< bool, type_t > predicate
Represents a delegate that defines a set of criteria and determines whether the specified object meet...
Definition predicate.hpp:16
Contains xtd::linq::enumerable <type_t> class.
The xtd::extensions namespace contains interface extensions.
Definition collection_common.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:216