12template<
typename type_t>
13struct __xtd_enumerable_holder {
14 __xtd_enumerable_holder(
const type_t& value) : ptr_(std::addressof(
value)) {}
16 __xtd_enumerable_holder(type_t&& value)
requires std::movable<type_t> : value_(std::move(value)), ptr_(std::addressof(*value_)) {}
21 std::optional<type_t> value_;
25template<xtd::iterable source_t, xtd::func_callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> func_t>
31 for (
const auto& item : source)
32 aggregated = nb++ == 0 ? item :
func(aggregated, item);
36template<
typename accumulate_t, xtd::iterable source_t, xtd::func_callable<accumulate_t, accumulate_t, xtd::iterable_value_type<source_t>> func_t>
38 auto aggregated = std::move(seed);
41 for (
const auto& item : source)
42 aggregated =
func(aggregated, item);
46template<
typename result_t,
typename accumulate_t, xtd::iterable source_t, xtd::func_callable<accumulate_t, accumulate_t, xtd::iterable_value_type<source_t>> func_t, xtd::func_callable<result_t, accumulate_t> result_selector_t>
48 auto aggregated = std::move(seed);
51 for (
const auto& item : source)
52 aggregated =
func(aggregated, item);
53 return result_selector(aggregated);
56template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
60 for (
const auto& item : source)
65template<xtd::iterable source_t>
67 return source.begin() != source.end();
70template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
74 for (
const auto& item : source)
79template<xtd::iterable source_t>
83 for (
const auto& item : source)
85 co_yield std::move(element);
88template<xtd::iterable source_t>
90 for (
const auto& item : source)
94template<xtd::iterable source_t>
96 for (
const auto& item : source)
100template<
typename value_t>
102 for (
const auto& item : source)
106template<std::forward_iterator iterator_t>
112template<std::forward_iterator iterator_t>
114 return as_enumerable(iterator, iterator + length);
117template<
typename value_t, xtd::usize length>
119 return as_enumerable(array, array + length);
122template<
typename value_t, xtd::usize length>
124 return as_enumerable(array, array + length);
127template<
typename value_t,
typename container_t>
129 struct accessor :
public std::queue<value_t> {
static auto get() {
return &accessor::c;}};
130 const auto& underlying_items = source.*accessor::get();
131 return as_enumerable(underlying_items.begin(), underlying_items.end());
133template<
typename value_t,
typename container_t>
135 struct accessor :
public std::queue<value_t> {
static auto get() {
return &accessor::c;}};
136 const auto& underlying_items = source.*accessor::get();
137 return as_enumerable(underlying_items.begin(), underlying_items.end());
139template<
typename value_t,
typename container_t>
141 struct accessor :
public std::priority_queue<value_t> {
static auto get() {
return &accessor::c;}};
142 const auto& underlying_items = source.*accessor::get();
143 return as_enumerable(underlying_items.begin(), underlying_items.end());
145template<
typename value_t,
typename container_t>
147 struct accessor :
public std::priority_queue<value_t> {
static auto get() {
return &accessor::c;}};
148 const auto& underlying_items = source.*accessor::get();
149 return as_enumerable(underlying_items.begin(), underlying_items.end());
151template<
typename value_t,
typename container_t>
153 struct accessor :
public std::stack<value_t> {
static auto get() {
return &accessor::c;}};
154 const auto& underlying_items = source.*accessor::get();
155 return as_enumerable(underlying_items.begin(), underlying_items.end());
157template<
typename value_t,
typename container_t>
159 struct accessor :
public std::stack<value_t> {
static auto get() {
return &accessor::c;}};
160 const auto& underlying_items = source.*accessor::get();
161 return as_enumerable(underlying_items.begin(), underlying_items.end());
164template<xtd::iterable source_t>
171 for (
const auto& item : source) {
176 return average / count;
179template<xtd::iterable source_t>
186 for (
const auto& item : source) {
191 return average / count;
194template<xtd::iterable source_t>
201 for (
const auto& item : source) {
206 return average / count;
209template<xtd::iterable source_t>
216 for (
const auto& item : source) {
221 return average / count;
224template<xtd::iterable source_t>
231 for (
const auto& item : source) {
236 return average / count;
239template<xtd::iterable source_t>
246 for (
const auto& item : source) {
251 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
254template<xtd::iterable source_t>
261 for (
const auto& item : source) {
266 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
269template<xtd::iterable source_t>
276 for (
const auto& item : source) {
281 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
284template<xtd::iterable source_t>
291 for (
const auto& item : source) {
296 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
299template<xtd::iterable source_t>
306 for (
const auto& item : source) {
311 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
314template<xtd::iterable first_t,xtd::iterable second_t>
322 for (
const auto& item : first)
324 for (
const auto& item : second)
328template<xtd::iterable source_t>
332 for (
const auto& item : source)
333 if (item == value)
return true;
337template<xtd::iterable source_t>
341 for (
const auto& item : source)
346template<xtd::iterable source_t, xtd::func_callable<
bool, xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> equater_t>
350 for (
const auto& item : source)
351 if (equater(item, value))
return true;
355template<xtd::iterable source_t>
363template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
365 return where(std::forward<source_t>(source), predicate).count();
368template<xtd::iterable source_t>
373template<
typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
379template<
typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
381 return count_by<key_t>(std::forward<source_t>(source), key_selector, [&key_comparer](
auto&& a,
auto&& b) {
return key_comparer.equals(a, b);});
384template<xtd::iterable source_t>
391 else for (
const auto& item : source)
395template<xtd::iterable source_t>
400 else for (
const auto& item : source)
404template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
406 auto result =
where(std::forward<source_t>(source), std::forward<prediacte_t>(predicate));
407 return any(result) ? *result.begin() : std::move(default_value);
410template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
415template<xtd::iterable source_t>
417 return any(std::forward<source_t>(source)) ? *source.begin() : std::move(default_value);
420template<xtd::iterable source_t>
425template<xtd::iterable source_t>
427 return as_enumerable(source);
430template<xtd::iterable source_t>
432 return as_enumerable(source);
435template<
typename value_t>
437 return as_enumerable(source);
440template<std::forward_iterator iterator_t>
442 return as_enumerable(first, last);
445template<std::forward_iterator iterator_t>
447 return as_enumerable(iterator, length);
450template<
typename value_t, xtd::usize length>
452 return as_enumerable(array);
455template<
typename value_t, xtd::usize length>
457 return as_enumerable(array);
460template<
typename value_t,
typename container_t>
462 return as_enumerable(source);
465template<
typename value_t,
typename container_t>
467 return as_enumerable(source);
470template<
typename value_t,
typename container_t>
472 return as_enumerable(source);
475template<
typename value_t,
typename container_t>
477 return as_enumerable(source);
480template<
typename value_t,
typename container_t>
482 return as_enumerable(source);
485template<
typename value_t,
typename container_t>
487 return as_enumerable(source);
490template<xtd::iterable source_t>
494 for (
const auto& item : source)
495 if (!result || item > result) result = item;
499template<xtd::iterable source_t, xtd::callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> selector_t>
503 for (
const auto& item : source) {
504 auto val = selector(item);
505 if (!result || val > result) result = val;
510template<
typename result_t, xtd::iterable source_t, xtd::callable<result_t, xtd::iterable_value_type<source_t>> selector_t>
514 for (
const auto& item : source) {
515 auto val = selector(item);
516 if (!result || val > result) result = val;
518 return result.value_or(result_t {});
521template<
typename result_t, xtd::iterable source_t>
526 for (
const auto& item : source)
527 co_yield invoke_selector_with_optional_index<result_t>(selector, item, index++);
530template<xtd::iterable source_t>
535 for (
const auto& item : source)
536 co_yield invoke_selector_with_optional_index<xtd::iterable_value_type<source_t>>(selector, item, index++);
539template<
typename predicate_t,
typename value_t>
540constexpr auto xtd::linq::enumerable::invoke_predicate_with_optional_index(predicate_t&& predicate, value_t&& value,
xtd::usize index) ->
bool {
543 else static_assert(always_false_v<predicate_t>,
"Predicate must accept either (value) or (value, index).");
546template<
typename result_t,
typename selector_t,
typename value_t>
547auto xtd::linq::enumerable::invoke_selector_with_optional_index(selector_t&& selector, value_t&& value,
xtd::usize index) -> result_t {
550 else static_assert(always_false_v<selector_t>,
"Selector must accept either (value) or (value, index).");
Represents an enumerable generator that supports deferred, lazy iteration over a collection of a spec...
Definition enumerable_generator.hpp:44
static auto default_equality_comparer() -> const equality_comparer &
Gets the default equality comparer for the type specified by the generic argument.
Definition equality_comparer.hpp:42
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
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...
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 from(source_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
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 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 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.
virtual auto equals(const object &obj) const noexcept -> bool
Determines whether the specified object is equal to the current object.
Contains xtd::collections::generic::extensions::enumerable <type_t> class.
Definition callable.hpp:11
Definition func_callable.hpp:11
Definition numeric.hpp:12
Definition predicate_callable.hpp:11
Definition real_decimal.hpp:13
Definition real_double.hpp:13
Definition real_single.hpp:13
Definition signed_integer_32.hpp:13
Definition signed_integer_64.hpp:14
Contains xtd::collections::generic::enumerable_generator <> class.
Contains xtd::linq::from methods.
generic::enumerator< xtd::any_object > enumerator
Supports a simple iteration over a non-generic collection.
Definition enumerator.hpp:28
xtd::collections::generic::comparer< xtd::any_object > comparer
Exposes a method that compares two objects.
Definition comparer.hpp:25
xtd::raw_type< decltype(*std::begin(std::declval< iterable_t & >()))> iterable_value_type
Represents the orward iterable value type.
Definition iterable_value_type.hpp:29
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
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ invalid_operation
The operation is not valid.
Definition exception_case.hpp:65
constexpr auto where
The xtd::ranges::views::where instance.
Definition where.hpp:40
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:26
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
constexpr null_opt nullopt
Represents a nullopt value. Used to indicate that an std::optional does not contain a value.
Definition nullopt.hpp:26
float single
Represents a single-precision floating-point number.
Definition single.hpp:23
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
std::remove_cvref_t< value_t > raw_type
Represents a raw type alias equivalent to std::remove_cvref_t<value_t>.
Definition raw_type.hpp:25
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
@ default_value
Default quality.
Definition compositing_quality.hpp:24
Contains xtd::linq::enumerable <type_t> class.
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:70
auto last() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:273
Contains xtd::nullopt valiue.
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:72