5#include "../collections/generic/helpers/allocator.hpp"
7#include "../collections/generic/equality_comparer.hpp"
8#define __XTD_CORE_INTERNAL__
9#include "../internal/__array_definition.hpp"
10#include "../internal/__key_value_pair_definition.hpp"
11#include "../internal/__list_definition.hpp"
12#undef __XTD_CORE_INTERNAL__
13#include "../decimal.hpp"
14#include "../iequatable.hpp"
15#include "../int32.hpp"
16#include "../int64.hpp"
17#include "../optional.hpp"
19#include "../static.hpp"
25struct __opaque_xtd_linq_enumerable_collection__;
31 namespace collections::generic {
32 template<
class type_t>
61 template<
class type_t>
65 template<
class type_t>
69 template<
class type_t>
73 template<
class key_t,
class value_t>
88 template<
class source_t>
91 auto aggregated = source_t {};
92 for (
const auto& item : source)
93 if (nb++ == 0) aggregated = item;
94 else aggregated =
func(aggregated, item);
106 template<
class source_t>
108 auto aggregated = seed;
109 for (
const auto& item : source)
110 aggregated =
func(aggregated, item);
123 template<
class accumulate_t,
class source_t>
125 auto aggregated = seed;
126 for (
const auto& item : source)
127 aggregated =
func(aggregated, item);
140 template<
class source_t>
141 static source_t
aggregate(
const ienumerable<source_t>& source,
const source_t& seed,
const std::function<source_t(
const source_t&,
const source_t&)>&
func,
const std::function<source_t(
const source_t&)>& result_selector) {
142 auto aggregated = seed;
143 for (
const auto& item : source)
144 aggregated =
func(aggregated, item);
145 return result_selector(aggregated);
159 template<
class result_t,
class accumulate_t,
class source_t>
160 static result_t
aggregate(
const ienumerable<source_t>& source,
const accumulate_t& seed,
const std::function<accumulate_t(
const source_t&,
const accumulate_t&)>&
func,
const std::function<result_t(
const accumulate_t&)>& result_selector) {
161 auto aggregated = seed;
162 for (
const auto& item : source)
163 aggregated =
func(aggregated, item);
164 return result_selector(aggregated);
175 template<
class source_t>
177 for (
const auto& item : source)
190 template<
class source_t>
192 return source.begin() != source.end();
202 template<
class source_t>
204 for (
const auto& item : source)
217 template<
class source_t>
219 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
220 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
221 for (
const auto& item : source)
222 result.items.push_back(item);
223 result.items.push_back(element);
234 template<
class source_t>
245 template<
class source_t>
247 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
248 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
249 for (
const auto& item : source)
250 result.items.push_back(item);
260 template<
class collection_t>
262 using source_t =
typename collection_t::value_type;
263 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
264 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
265 for (
const auto& item : source)
266 result.items.push_back(item);
277 template<
class input_iterator_t>
278 static const auto&
as_enumerable(input_iterator_t first, input_iterator_t last)
noexcept {
279 using source_t =
typename std::decay<
decltype(*first)>
::type;
280 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
281 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
282 for (
auto iterator = first; iterator != last; ++iterator)
283 result.items.push_back(*iterator);
294 template<
class input_iterator_t>
295 static const auto&
as_enumerable(input_iterator_t iterator,
size_t length)
noexcept {
306 template<
class source_t,
size_t length>
365 template<
class result_t,
class source_t>
374 template<
class source_t>
382 template<
class source_t>
384 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
385 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
386 for (
const auto& item : first)
387 result.items.push_back(item);
388 for (
const auto& item : second)
389 result.items.push_back(item);
398 template<
class source_t>
400 for (
const auto& item : source)
401 if (item == value)
return true;
411 template<
class source_t>
413 for (
const auto& item : source)
414 if (comparer.equals(item, value))
return true;
425 template<
class source_t>
428 auto enumerator = source.get_enumerator();
429 while (enumerator.move_next()) ++
count;
441 template<
class source_t>
444 auto enumerator = source.get_enumerator();
445 while (enumerator.move_next())
459 template<
class key_t,
class source_t>
474 template<
class key_t,
class source_t>
476 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
477 result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
479 auto enumerator = source.get_enumerator();
480 while (enumerator.move_next()) {
481 auto key = key_selector(enumerator.current());
482 auto index =
size_t {0};
483 for (; index < keys.size(); ++index)
484 if (key_comparer.equals(keys[index], key))
break;
485 if (index < keys.size()) result.items[index] = {key, result.items[index].value() + 1};
488 result.items.push_back({key, 1});
501 template<
class source_t>
514 template<
class source_t>
516 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
517 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
518 if (!
any(source)) result.items.push_back(default_value);
519 else for (
const auto& item : source)
520 result.items.push_back(item);
530 template<
class source_t>
533 return any(result) ? *result.begin() : default_value;
540 template<
class source_t>
549 template<
class source_t>
551 return any(source) ? *source.begin() : default_value;
557 template<
class source_t>
580 template<
class source_t>
592 template<
class source_t>
604 template<
class collection_t>
605 static const auto&
from(
const collection_t& source)
noexcept {
619 template<
class input_iterator_t>
620 static const auto&
from(input_iterator_t first, input_iterator_t last)
noexcept {
632 template<
class input_iterator_t>
633 static const auto&
from(input_iterator_t iterator,
size_t length)
noexcept {
645 template<
class source_t,
size_t length>
646 static const auto&
from(
const source_t (&
array)[length])
noexcept {
659 template<
class result_t,
class source_t>
661 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
662 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
663 for (
const auto& item : source)
664 result.items.push_back(selector(item));
675 template<
class source_t>
677 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
678 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
679 for (
const auto& item : source)
680 result.items.push_back(selector(item));
692 template<
class result_t,
class source_t>
694 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
695 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
697 for (
const auto& item : source)
698 result.items.push_back(selector(item, index++));
709 template<
class source_t>
711 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
712 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
714 for (
const auto& item : source)
715 result.items.push_back(selector(item, index++));
727 template<
class source_t>
738 template<
class source_t>
740 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
741 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
742 for (
const auto& item : source)
743 if (
predicate(item)) result.items.push_back(item);
754 template<
class source_t>
756 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
757 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
759 for (
const auto& item : source)
760 if (
predicate(item, index++)) result.items.push_back(item);
766 template<
class source_t,
class collection_t>
767 static const list<source_t>& collection_to_list(
const collection_t& source)
noexcept;
768 template<
class source_t,
class input_iterator_t>
769 static const list<source_t>& input_iterator_to_list(input_iterator_t first, input_iterator_t last)
noexcept;
774#include "../collections/generic/extensions/enumerable.hpp"
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:59
Provides a base class for implementations of the xtd::collections::generic::iequality_comparer <type_...
Definition equality_comparer.hpp:35
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:55
static const auto & from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:646
static const auto & as_enumerable(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:278
static xtd::decimal average(const ienumerable< xtd::decimal > &source)
Computes the average of a sequence of xtd::decimal values.
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.
static const ienumerable< source_t > & from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:593
static const auto & from(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:620
static const ienumerable< result_t > & select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:660
static const auto & as_enumerable(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:295
static xtd::optional< float > average(const ienumerable< xtd::optional< float > > &source) noexcept
Computes the average of a sequence of optional float values.
static const ienumerable< result_t > & cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static bool all(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:176
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:66
static xtd::optional< xtd::decimal > average(const ienumerable< xtd::optional< xtd::decimal > > &source) noexcept
Computes the average of a sequence of optional xtd::decimal values.
static const ienumerable< result_t > & select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:693
static const ienumerable< source_t > & where(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:739
static double average(const ienumerable< xtd::int32 > &source)
Computes the average of a sequence of xtd::int32 values.
static bool any(const ienumerable< source_t > &source) noexcept
Determines whether a sequence contains any elements.
Definition enumerable.hpp:191
static bool any(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:203
static source_t aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func, const std::function< source_t(const source_t &)> &result_selector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:141
static bool contains(const ienumerable< source_t > &source, const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:412
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:62
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:70
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int32 > > &source) noexcept
Computes the average of a sequence of optional xtd::int32 values.
static const auto & from(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:633
static const ienumerable< key_value_pair< key_t, xtd::size > > & count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:460
static const ienumerable< source_t > & select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:676
static double average(const ienumerable< double > &source)
Computes the average of a sequence of double values.
static result_t aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const source_t &, const accumulate_t &)> &func, const std::function< 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:160
static bool contains(const ienumerable< source_t > &source, const source_t &value) noexcept
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:399
static const ienumerable< source_t > & default_if_empty(const ienumerable< source_t > &source, const source_t &default_value) noexcept
Returns the elements of the specified sequence or the specified value in a singleton collection if th...
Definition enumerable.hpp:515
static double average(const ienumerable< xtd::int64 > &source)
Computes the average of a sequence of xtd::int64 values.
static const ienumerable< source_t > & as_enumerable(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:246
static const ienumerable< source_t > & as_enumerable(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:235
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:531
static const ienumerable< source_t > & default_if_empty(const ienumerable< source_t > &source) noexcept
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
Definition enumerable.hpp:502
static source_t first_or_default(const ienumerable< source_t > &source, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:550
static const auto & as_enumerable(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:307
static const ienumerable< key_value_pair< key_t, xtd::size > > & count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:475
static xtd::optional< double > average(const ienumerable< xtd::optional< double > > &source) noexcept
Computes the average of a sequence of optional double values.
static const ienumerable< xtd::int32 > & range(xtd::int32 start, xtd::int32 count)
Generates a sequence of integral numbers within a specified range.
static const ienumerable< source_t > & append(const ienumerable< source_t > &source, const source_t &element) noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:218
static float average(const ienumerable< float > &source)
Computes the average of a sequence of float values.
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int64 > > &source) noexcept
Computes the average of a sequence of optional xtd::int64 values.
static source_t aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:107
static const ienumerable< source_t > & select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:710
static const ienumerable< source_t > & concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:383
static xtd::size count(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:442
static accumulate_t aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< 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:124
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:541
static const ienumerable< source_t > & where(const ienumerable< source_t > &source, const std::function< bool(const source_t &, xtd::size)> &predicate)
Filters a sequence of values based on a predicate. Each element's index is used in the logic of the p...
Definition enumerable.hpp:755
static xtd::size count(const ienumerable< source_t > &source) noexcept
Returns the number of elements in a sequence.
Definition enumerable.hpp:426
static const auto & from(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:605
static source_t first_or_default(const ienumerable< source_t > &source) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:558
static source_t aggregate(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:89
static const list< source_t > & to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
static const auto & as_enumerable(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:261
static const ienumerable< source_t > & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:581
Contains xtd::linq::from methods.
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
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
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
std::optional< type_t > optional
Represents the null_opt alias on std::nullopt_t.
Definition optional.hpp:175
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::type_info type
Stores information about a type.
Definition type.hpp:23
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
@ 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
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37