9#define __XTD_STD_INTERNAL__
11#undef __XTD_STD_INTERNAL__
12#define __XTD_CORE_INTERNAL__
17#undef __XTD_CORE_INTERNAL__
30struct __opaque_xtd_linq_enumerable_collection__;
31template<
class type_t,
class param_t>
32struct __opaque_xtd_linq_lazy_enumerable__;
39 template<
class type_t>
68 template<
class type_t>
72 template<
class type_t>
76 template<
class type_t>
80 template<
class type_t>
84 template<
class key_t,
class value_t>
99 template<
class source_t>
102 auto aggregated = source_t {};
103 for (
const auto& item : source)
104 if (nb++ == 0) aggregated = item;
105 else aggregated =
func(aggregated, item);
117 template<
class source_t>
119 auto aggregated = seed;
120 for (
const auto& item : source)
121 aggregated =
func(aggregated, item);
134 template<
class accumulate_t,
class source_t>
136 auto aggregated = seed;
137 for (
const auto& item : source)
138 aggregated =
func(aggregated, item);
151 template<
class source_t>
152 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) {
153 auto aggregated = seed;
154 for (
const auto& item : source)
155 aggregated =
func(aggregated, item);
156 return result_selector(aggregated);
170 template<
class result_t,
class accumulate_t,
class source_t>
171 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) {
172 auto aggregated = seed;
173 for (
const auto& item : source)
174 aggregated =
func(aggregated, item);
175 return result_selector(aggregated);
186 template<
class source_t>
188 for (
const auto& item : source)
201 template<
class source_t>
203 return source.begin() != source.end();
213 template<
class source_t>
215 for (
const auto& item : source)
228 template<
class source_t>
230 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
231 for (
const auto& item : source)
232 result.items.push_back(item);
233 result.items.push_back(element);
285 template<
class source_t>
296 template<
class source_t>
297 static auto as_enumerable(std::initializer_list<source_t> source)
noexcept {
298 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
299 for (
const auto& item : source)
300 result.items.push_back(item);
310 template<
class collection_t>
312 #if defined(__xtd__cpp_lib_ranges)
313 using source_t = std::ranges::range_value_t<collection_t>;
315 using source_t =
typename collection_t::value_type;
317 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
318 for (
auto&& item : source)
319 result.items.push_back(item);
330 template<
class input_iterator_t>
332 using source_t =
typename std::decay<
decltype(*first)>
::type;
333 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
334 for (
auto iterator =
first; iterator !=
last; ++iterator)
335 result.items.push_back(*iterator);
346 template<
class input_iterator_t>
358 template<
class source_t,
size_t length>
417 template<
class result_t,
class source_t>
426 template<
class source_t>
434 template<
class source_t>
436 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
437 for (
const auto& item :
first)
438 result.items.push_back(item);
439 for (
const auto& item : second)
440 result.items.push_back(item);
449 template<
class source_t>
451 for (
const auto& item : source)
452 if (item == value)
return true;
462 template<
class source_t>
464 for (
const auto& item : source)
465 if (comparer.
equals(item, value))
return true;
476 template<
class source_t>
492 template<
class source_t>
502 template<
class source_t>
504 return count<source_t>(source, [value](
const source_t& item) ->
bool {
return item == value;});
516 template<
class key_t,
class source_t>
531 template<
class key_t,
class source_t>
533 auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
537 auto key = key_selector(
enumerator.current());
538 auto index =
size_t {0};
539 for (; index < keys.size(); ++index)
540 if (key_comparer.equals(keys[index], key))
break;
541 if (index < keys.size()) result.items[index] = {key, result.items[index].value() + 1};
544 result.items.push_back({key, 1});
557 template<
class source_t>
570 template<
class source_t>
572 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
573 if (!
any(source)) result.items.push_back(default_value);
574 else for (
const auto& item : source)
575 result.items.push_back(item);
582 template<
class source_t>
584 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
585 for (
const auto& item : source)
587 result.items.push_back(item);
595 template<
class source_t>
597 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
598 for (
const auto& item : source)
599 if (!
contains(result, item, comparer))
600 result.items.push_back(item);
610 template<
class source_t>
613 return any(result) ? *result.begin() : default_value;
620 template<
class source_t>
629 template<
class source_t>
631 return any(source) ? *source.begin() : default_value;
637 template<
class source_t>
650 template<
class source_t>
662 template<
class source_t>
663 static auto from(std::initializer_list<source_t> source)
noexcept {
674 template<
class collection_t>
675 static auto from(collection_t&& source)
noexcept {
689 template<
class input_iterator_t>
702 template<
class input_iterator_t>
703 static auto from(input_iterator_t iterator,
size_t length)
noexcept {
715 template<
class source_t,
size_t length>
726 template<
class key_t,
class source_t>
728 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
729 result.items = std::vector<source_t> {source.begin(), source.end()};
730 std::sort(result.items.begin(), result.items.end(), [key_selector](
const source_t&
a,
const source_t&
b) {return key_selector(a) < key_selector(b);});
740 template<
class source_t>
742 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
743 result.items = std::vector<source_t> {source.begin(), source.end()};
744 std::sort(result.items.begin(), result.items.end(), [key_selector](
const source_t&
a,
const source_t&
b) {return key_selector(a) < key_selector(b);});
754 template<
class key_t,
class source_t>
756 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
757 result.items = std::vector<source_t> {source.begin(), source.end()};
758 std::sort(result.items.begin(), result.items.end(), [key_selector](
const source_t&
a,
const source_t&
b) {return key_selector(a) > key_selector(b);});
768 template<
class source_t>
770 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
771 result.items = std::vector<source_t> {source.begin(), source.end()};
772 std::sort(result.items.begin(), result.items.end(), [key_selector](
const source_t&
a,
const source_t&
b) {return key_selector(a) > key_selector(b);});
783 template<
class type_t>
785 auto step = type_t {};
796 template<
class type_t>
798 auto step = type_t {};
807 template<
class type_t>
809 using param_type = std::tuple<type_t, type_t, type_t, type_t>;
810 auto numbers = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {};
815 numbers = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {
816 std::make_tuple(start,
count, step, type_t {}),
817 [](param_type & params) {
818 auto& result = std::get<0>(params);
819 auto&
count = std::get<1>(params);
820 auto& step = std::get<2>(params);
821 auto& index = std::get<3>(params);
822 if (index != 0) result += step;
823 return index++ <
count;
825 [start,
count, step](param_type & params) {
826 params = std::make_tuple(start,
count, step, type_t {});
841 template<
class result_t,
class source_t>
843 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
844 for (
const auto& item : source)
845 result.items.push_back(selector(item));
856 template<
class source_t>
858 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
859 for (
const auto& item : source)
860 result.items.push_back(selector(item));
872 template<
class result_t,
class source_t>
874 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
876 for (
const auto& item : source)
877 result.items.push_back(selector(item, index++));
888 template<
class source_t>
890 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
892 for (
const auto& item : source)
893 result.items.push_back(selector(item, index++));
905 template<
class source_t>
916 template<
class source_t>
918 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
919 for (
const auto& item : source)
920 if (
predicate(item)) result.items.push_back(item);
931 template<
class source_t>
933 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
935 for (
const auto& item : source)
936 if (
predicate(item, index++)) result.items.push_back(item);
Contains xtd::array definitions.
Contains xtd::collections::generic::key_value_pair definitions.
Contains xtd::collections::generic::list definitions.
Contains xtd_raw_array_data class.
Contains __xtd_std_version definitions.
Contains xtd::collections::generic::helpers::allocator alias.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:63
static const equality_comparer & default_equality_comparer()
Gets the default equality comparer for the type specified by the generic argument.
Definition equality_comparer.hpp:42
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
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:62
static auto 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:842
static auto 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:532
static xtd::decimal average(const ienumerable< xtd::decimal > &source)
Computes the average of a sequence of xtd::decimal values.
static auto 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:558
static auto append(const ienumerable< source_t > &source, const source_t &element) noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:229
static auto order_by_descending(const ienumerable< source_t > &source, const std::function< source_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in descending order according to a key.
Definition enumerable.hpp:769
static 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:347
static 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:690
static xtd::optional< float > average(const ienumerable< xtd::optional< float > > &source) noexcept
Computes the average of a sequence of optional float values.
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:187
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:77
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:69
static auto cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static auto from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:716
static 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:331
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:202
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:214
static auto to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
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:152
static const auto & as_enumerable(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:286
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:463
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:73
static auto distinct(const ienumerable< source_t > &source, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable.hpp:596
static auto range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:797
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:81
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 auto from(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:703
static auto 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:873
static auto chunk(const ienumerable< source_t > &source, xtd::size size)
Splits the elements of a sequence into chunks of size at most size.
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:171
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:450
static double average(const ienumerable< xtd::int64 > &source)
Computes the average of a sequence of xtd::int64 values.
static auto 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:932
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:611
static auto 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:889
static auto from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:663
static auto 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:571
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:630
static auto 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:857
static auto concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:435
static auto 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:808
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:755
static auto distinct(const ienumerable< source_t > &source) noexcept
Returns distinct elements from a sequence by using the default equality comparer to compare values.
Definition enumerable.hpp:583
static auto as_enumerable(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:359
static auto order_by(const ienumerable< source_t > &source, const std::function< source_t(const source_t &)> &key_selector)
Sorts the elements of a sequence in ascending order according to a key.
Definition enumerable.hpp:741
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:727
static xtd::optional< double > average(const ienumerable< xtd::optional< double > > &source) noexcept
Computes the average of a sequence of optional double values.
static float average(const ienumerable< float > &source)
Computes the average of a sequence of float values.
static auto from(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:675
static auto 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:917
static auto 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:517
xtd::collections::generic::key_value_pair< key_t, value_t > key_value_pair
Represents the key value pair value type.
Definition enumerable.hpp:85
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:118
static auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:784
static auto as_enumerable(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:297
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:493
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:135
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:621
static xtd::size count(const ienumerable< source_t > &source) noexcept
Returns the number of elements in a sequence.
Definition enumerable.hpp:477
static const auto & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:651
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:638
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:100
static auto as_enumerable(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:311
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:503
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
Contains xtd::collections::generic::extensions::enumerable <type_t> class.
Contains xtd::decimal type.
Contains xtd::collections::generic::equality_comparer <type_t> class.
Contains xtd::linq::from methods.
Contains xtd::collections::generic::enumerator <type_t> class.
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.
Definition exception_case.hpp:31
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
std::type_info type
Stores information about a type.
Definition type.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:25
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
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
@ a
The A key.
Definition console_key.hpp:88
@ b
The B key.
Definition console_key.hpp:90
Contains xtd::iequatable interface.
Contains xtd::int32 type.
Contains xtd::int64 type.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
Provides classes and interfaces that support queries that use Language-Integrated Query (LINQ).
Definition enumerable.hpp:45
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
Contains xtd::optional type.
Contains xtd::static_object class.
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