xtd 0.2.0
Loading...
Searching...
No Matches
enumerable.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "../predicate.hpp"
7#include "../static.hpp"
8#include <algorithm>
9
11namespace xtd {
13 namespace linq {
30 public:
32
41 template<typename source_t>
43 auto nb = 0;
44 auto aggregated = source_t {};
45 for (const auto& item : source)
46 if (nb++ == 0) aggregated = item;
47 else aggregated = func(aggregated, item);
48 return aggregated;
49 }
57 template<typename source_t, typename func_t>
58 static source_t aggregate(const xtd::collections::generic::ienumerable<source_t>& source, const func_t& func) {
60 }
69 template<typename source_t, typename accumulate_t>
71 auto aggregated = seed;
72 for (const auto& item : source)
73 aggregated = func(aggregated, item);
74 return aggregated;
75 }
84 template<typename source_t, typename accumulate_t, typename func_t>
85 static accumulate_t aggregate(const xtd::collections::generic::ienumerable<source_t>& source, const accumulate_t& seed, const func_t& func) {
87 }
97 template<typename source_t, typename accumulate_t, typename result_t>
99 auto aggregated = seed;
100 for (const auto& item : source)
101 aggregated = func(aggregated, item);
102 return result_selector(aggregated);
103 }
113 template<typename source_t, typename accumulate_t, typename result_t, typename func_t, typename result_selector_t>
114 static result_t aggregate(const xtd::collections::generic::ienumerable<source_t>& source, const accumulate_t& seed, const func_t& func, const result_selector_t& result_selector) {
116 }
126 template<typename source_t, typename accumulate_t, typename func_t, typename result_selector_t>
127 static accumulate_t aggregate(const xtd::collections::generic::ienumerable<source_t>& source, const accumulate_t& seed, const func_t& func, const result_selector_t& result_selector) {
129 }
138 template<typename accumulate_t, typename input_iterator_t>
139 static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const xtd::func<accumulate_t, const accumulate_t&, const accumulate_t&>& func) {
140 auto nb = 0;
141 auto aggregated = accumulate_t {};
142 for (auto iterator = first; iterator != last; ++iterator)
143 if (nb++ == 0) aggregated = *iterator;
144 else aggregated = func(aggregated, *iterator);
145 return aggregated;
146 }
155 template<typename accumulate_t, typename input_iterator_t, typename func_t>
156 static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const func_t& func) {
158 }
167 template<typename accumulate_t, typename input_iterator_t>
168 static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t& seed, const xtd::func<accumulate_t, const accumulate_t&, const accumulate_t&>& func) {
169 auto aggregated = seed;
170 for (auto iterator = first; iterator != last; ++iterator)
171 aggregated = func(aggregated, *iterator);
172 return aggregated;
173 }
183 template<typename accumulate_t, typename input_iterator_t, typename func_t>
184 static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t& seed, const func_t& func) {
186 }
197 template<typename accumulate_t, typename result_t, typename input_iterator_t>
198 static result_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t& seed, const xtd::func<accumulate_t, const accumulate_t&, const accumulate_t&>& func, const xtd::func<result_t, const accumulate_t&>& result_selector) {
199 auto aggregated = seed;
200 for (auto iterator = first; iterator != last; ++iterator)
201 aggregated = func(aggregated, *iterator);
202 return result_selector(aggregated);
203 }
214 template<typename accumulate_t, typename result_t, typename input_iterator_t, typename func_t, typename result_selector_t>
215 static result_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t& seed, const func_t& func, const result_selector_t& result_selector) {
217 }
228 template<typename accumulate_t, typename input_iterator_t, typename func_t, typename result_selector_t>
229 static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t& seed, const func_t& func, const result_selector_t& result_selector) {
231 }
232
240 template<typename source_t>
242 for (const auto& item : source)
243 if (!predicate(item)) return false;
244 return true;
245 }
253 template<typename source_t, typename predicate_t>
254 static bool all(const xtd::collections::generic::ienumerable<source_t>& source, const predicate_t& predicate) {
256 }
265 template<typename source_t, typename input_iterator_t>
266 static bool all(input_iterator_t first, input_iterator_t last, const xtd::predicate<const source_t&>& predicate) {
267 for (auto iterator = first; iterator != last; ++iterator)
268 if (!predicate(*iterator)) return false;
269 return true;
270 }
279 template<typename source_t, typename input_iterator_t, typename predicate_t>
280 static bool all(input_iterator_t first, input_iterator_t last, const predicate_t& predicate) {
281 return all(first, last, xtd::predicate<const source_t&> {predicate});
282 }
283
291 template<typename source_t>
293 return source.get_enumerator().move_next();
294 }
302 template<typename source_t>
304 for (const auto& item : source)
305 if (predicate(item)) return true;
306 return false;
307 }
315 template<typename source_t, typename predicate_t>
316 static bool any(const xtd::collections::generic::ienumerable<source_t>& source, const predicate_t& predicate) {
318 }
326 template<typename source_t, typename input_iterator_t>
327 static bool any(input_iterator_t first, input_iterator_t last) {
328 return first != last;
329 }
338 template<typename source_t, typename input_iterator_t>
339 static bool any(input_iterator_t first, input_iterator_t last, const xtd::predicate<const source_t&>& predicate) {
340 for (auto iterator = first; iterator != last; ++iterator)
341 if (predicate(*iterator)) return true;
342 return false;
343 }
351 template<typename source_t, typename input_iterator_t, typename predicate_t>
352 static bool any(input_iterator_t first, input_iterator_t last, const predicate_t& predicate) {
353 return any(first, last, xtd::predicate<const source_t&> {predicate});
354 }
356 };
357 }
358}
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:35
virtual enumerator< type_t > get_enumerator() const =0
Returns an enumerator that iterates through a collection.
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition delegate.hpp:370
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:29
static bool all(input_iterator_t first, input_iterator_t last, const xtd::predicate< const source_t & > &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:266
static accumulate_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:85
static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const func_t &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:156
static result_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:215
static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:229
static source_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const func_t &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:58
static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:139
static bool any(input_iterator_t first, input_iterator_t last, const xtd::predicate< const source_t & > &predicate)
Determines whether any elements of a sequence satisfy a condition.
Definition enumerable.hpp:339
static bool all(const xtd::collections::generic::ienumerable< source_t > &source, const xtd::predicate< const source_t & > &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:241
static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const func_t &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:184
static accumulate_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:168
static accumulate_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:70
static result_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const xtd::func< accumulate_t, const source_t &, const accumulate_t & > &func, const xtd::func< result_t, const accumulate_t & > &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:98
static source_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const xtd::func< source_t, const source_t &, const source_t & > &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:42
static result_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:114
static accumulate_t aggregate(const xtd::collections::generic::ienumerable< source_t > &source, const accumulate_t &seed, const func_t &func, const result_selector_t &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:127
static bool any(const xtd::collections::generic::ienumerable< source_t > &source)
Determines whether a sequence contains any elements.
Definition enumerable.hpp:292
static result_t aggregate(input_iterator_t first, input_iterator_t last, const accumulate_t &seed, const xtd::func< accumulate_t, const accumulate_t &, const accumulate_t & > &func, const xtd::func< result_t, const accumulate_t & > &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:198
static bool any(const xtd::collections::generic::ienumerable< source_t > &source, const predicate_t &predicate)
Determines whether any elements of a sequence satisfy a condition.
Definition enumerable.hpp:316
static bool any(input_iterator_t first, input_iterator_t last, const predicate_t &predicate)
Determines whether any elements of a sequence satisfy a condition.
Definition enumerable.hpp:352
static bool all(const xtd::collections::generic::ienumerable< source_t > &source, const predicate_t &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:254
static bool all(input_iterator_t first, input_iterator_t last, const predicate_t &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:280
static bool any(const xtd::collections::generic::ienumerable< source_t > &source, const xtd::predicate< const source_t & > &predicate)
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:303
static bool any(input_iterator_t first, input_iterator_t last)
Determines whether a sequence contains any elements.
Definition enumerable.hpp:327
Contains xtd::linq::enumerable_collection <type_t> alias.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
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
delegate< result_t(arguments_t...)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:16
@ any
Indicates that all styles except allow_binary_specifier, allow_octal_specifier and allow_hex_specifie...
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10