5#include "../collections/generic/helpers/allocator.hpp"
7#include "../collections/generic/equality_comparer.hpp"
8#include "../collections/generic/enumerator.hpp"
9#define __XTD_CORE_INTERNAL__
10#include "../internal/__array_definition.hpp"
11#include "../internal/__key_value_pair_definition.hpp"
12#include "../internal/__list_definition.hpp"
13#undef __XTD_CORE_INTERNAL__
14#include "../decimal.hpp"
15#include "../iequatable.hpp"
16#include "../int32.hpp"
17#include "../int64.hpp"
18#include "../optional.hpp"
20#include "../static.hpp"
26struct __opaque_xtd_linq_enumerable_collection__;
27template<
class type_t,
class param_t>
28struct __opaque_xtd_linq_lazy_enumerable__;
34 namespace collections::generic {
35 template<
class type_t>
64 template<
class type_t>
68 template<
class type_t>
72 template<
class type_t>
76 template<
class type_t>
80 template<
class key_t,
class value_t>
95 template<
class source_t>
98 auto aggregated = source_t {};
99 for (
const auto& item : source)
100 if (nb++ == 0) aggregated = item;
101 else aggregated =
func(aggregated, item);
113 template<
class source_t>
115 auto aggregated = seed;
116 for (
const auto& item : source)
117 aggregated =
func(aggregated, item);
130 template<
class accumulate_t,
class source_t>
132 auto aggregated = seed;
133 for (
const auto& item : source)
134 aggregated =
func(aggregated, item);
147 template<
class source_t>
148 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) {
149 auto aggregated = seed;
150 for (
const auto& item : source)
151 aggregated =
func(aggregated, item);
152 return result_selector(aggregated);
166 template<
class result_t,
class accumulate_t,
class source_t>
167 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) {
168 auto aggregated = seed;
169 for (
const auto& item : source)
170 aggregated =
func(aggregated, item);
171 return result_selector(aggregated);
182 template<
class source_t>
184 for (
const auto& item : source)
197 template<
class source_t>
199 return source.begin() != source.end();
209 template<
class source_t>
211 for (
const auto& item : source)
224 template<
class source_t>
226 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
227 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
228 for (
const auto& item : source)
229 result.items.push_back(item);
230 result.items.push_back(element);
282 template<
class source_t>
293 template<
class source_t>
295 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
296 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
297 for (
const auto& item : source)
298 result.items.push_back(item);
308 template<
class collection_t>
310 using source_t =
typename collection_t::value_type;
311 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
312 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
313 for (
const auto& item : source)
314 result.items.push_back(item);
325 template<
class input_iterator_t>
326 static const auto&
as_enumerable(input_iterator_t first, input_iterator_t last)
noexcept {
327 using source_t =
typename std::decay<
decltype(*first)>
::type;
328 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
329 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
330 for (
auto iterator = first; iterator != last; ++iterator)
331 result.items.push_back(*iterator);
342 template<
class input_iterator_t>
343 static const auto&
as_enumerable(input_iterator_t iterator,
size_t length)
noexcept {
354 template<
class source_t,
size_t length>
413 template<
class result_t,
class source_t>
422 template<
class source_t>
430 template<
class source_t>
432 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
433 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
434 for (
const auto& item : first)
435 result.items.push_back(item);
436 for (
const auto& item : second)
437 result.items.push_back(item);
446 template<
class source_t>
448 for (
const auto& item : source)
449 if (item == value)
return true;
459 template<
class source_t>
461 for (
const auto& item : source)
462 if (comparer.equals(item, value))
return true;
473 template<
class source_t>
489 template<
class source_t>
491 return where<source_t>(source,
predicate).count();
499 template<
class source_t>
501 return count<source_t>(source, [value](
const source_t& item) ->
bool {
return item == value;});
513 template<
class key_t,
class source_t>
528 template<
class key_t,
class source_t>
530 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
531 result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
535 auto key = key_selector(
enumerator.current());
536 auto index =
size_t {0};
537 for (; index < keys.size(); ++index)
538 if (key_comparer.equals(keys[index], key))
break;
539 if (index < keys.size()) result.items[index] = {key, result.items[index].value() + 1};
542 result.items.push_back({key, 1});
555 template<
class source_t>
568 template<
class source_t>
570 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
571 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
572 if (!
any(source)) result.items.push_back(default_value);
573 else for (
const auto& item : source)
574 result.items.push_back(item);
584 template<
class source_t>
587 return any(result) ? *result.begin() : default_value;
594 template<
class source_t>
603 template<
class source_t>
605 return any(source) ? *source.begin() : default_value;
611 template<
class source_t>
623 template<
class type_t>
625 auto step = type_t {};
636 template<
class type_t>
638 auto step = type_t {};
647 template<
class type_t>
649 using param_type = std::tuple<type_t, type_t, type_t, type_t>;
650 static thread_local auto result = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {};
655 result = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {
656 std::make_tuple(start,
count, step, type_t {}),
657 [](param_type& params) {
658 auto& result = std::get<0>(params);
659 auto&
count = std::get<1>(params);
660 auto& step = std::get<2>(params);
661 auto& index = std::get<3>(params);
662 if (index != 0) result += step;
663 return index++ <
count;
665 [start,
count, step](param_type& params) {
666 params = std::make_tuple(start,
count, step, type_t {});
680 template<
class source_t>
692 template<
class source_t>
704 template<
class collection_t>
705 static const auto&
from(
const collection_t& source)
noexcept {
719 template<
class input_iterator_t>
720 static const auto&
from(input_iterator_t first, input_iterator_t last)
noexcept {
732 template<
class input_iterator_t>
733 static const auto&
from(input_iterator_t iterator,
size_t length)
noexcept {
745 template<
class source_t,
size_t length>
746 static const auto&
from(
const source_t (&
array)[length])
noexcept {
759 template<
class result_t,
class source_t>
761 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
762 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
763 for (
const auto& item : source)
764 result.items.push_back(selector(item));
775 template<
class source_t>
777 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
778 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
779 for (
const auto& item : source)
780 result.items.push_back(selector(item));
792 template<
class result_t,
class source_t>
794 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
795 result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
797 for (
const auto& item : source)
798 result.items.push_back(selector(item, index++));
809 template<
class source_t>
811 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
812 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
814 for (
const auto& item : source)
815 result.items.push_back(selector(item, index++));
827 template<
class source_t>
838 template<
class source_t>
840 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
841 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
842 for (
const auto& item : source)
843 if (
predicate(item)) result.items.push_back(item);
854 template<
class source_t>
856 static thread_local auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
857 result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
859 for (
const auto& item : source)
860 if (
predicate(item, index++)) result.items.push_back(item);
866 template<
class source_t,
class collection_t>
867 static const list<source_t>& collection_to_list(
const collection_t& source)
noexcept;
868 template<
class source_t,
class input_iterator_t>
869 static const list<source_t>& input_iterator_to_list(input_iterator_t first, input_iterator_t last)
noexcept;
874#include "../collections/generic/extensions/enumerable.hpp"
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
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
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:58
static const auto & from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:746
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:326
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:693
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:720
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:760
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:343
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:183
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:73
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.
typename xtd::collections::generic::enumerator< type_t > enumerator
Represents the enumerator value type.
Definition enumerable.hpp:65
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:793
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:839
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:198
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:210
static const ienumerable< type_t > & range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:637
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:148
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:460
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:69
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:77
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:733
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:514
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:776
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:167
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:447
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:569
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:294
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:283
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:585
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:556
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:604
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:355
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:529
static const ienumerable< type_t > & range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:624
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< 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:225
static float average(const ienumerable< float > &source)
Computes the average of a sequence of float values.
static const ienumerable< type_t > & range(type_t start, type_t count, type_t step)
Generates a sequence of integral numbers within a specified range and step.
Definition enumerable.hpp:648
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:114
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:810
static const ienumerable< source_t > & concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:431
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:490
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:131
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:595
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:855
static xtd::size count(const ienumerable< source_t > &source) noexcept
Returns the number of elements in a sequence.
Definition enumerable.hpp:474
static const auto & from(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:705
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:612
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:96
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 xtd::size count(const ienumerable< source_t > &source, const source_t &value) noexcept
Returns the number of elements with the specified value.
Definition enumerable.hpp:500
static const auto & as_enumerable(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:309
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:681
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
@ argument
The argument is not valid.
@ argument_out_of_range
The argument is out of range.
#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
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
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37