12template<
typename type_t>
13xtd::linq::enumerable::enumerable_holder<type_t>::enumerable_holder(
const type_t& value) : ptr_(std::addressof(
value)) {
20template<
typename type_t>
21xtd::linq::enumerable::enumerable_holder<type_t>::enumerable_holder(type_t&& value)
requires std::movable<type_t> : value_(std::move(value)), ptr_(std::addressof(*value_)) {
24template<
typename type_t>
25auto xtd::linq::enumerable::enumerable_holder<type_t>::get() const -> const
xtd::raw_type<type_t>& {
return *ptr_;}
27template<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>
33 for (
const auto& item : source)
34 aggregated = nb++ == 0 ? item :
func(aggregated, item);
38template<
typename accumulate_t, xtd::iterable source_t, xtd::func_callable<accumulate_t, accumulate_t, xtd::iterable_value_type<source_t>> func_t>
40 auto aggregated = std::move(seed);
43 for (
const auto& item : source)
44 aggregated =
func(aggregated, item);
48template<
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>
50 auto aggregated = std::move(seed);
53 for (
const auto& item : source)
54 aggregated =
func(aggregated, item);
55 return result_selector(aggregated);
58template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
62 for (
const auto& item : source)
67template<xtd::iterable source_t>
69 return source.begin() != source.end();
72template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
76 for (
const auto& item : source)
81template<xtd::iterable source_t>
85 for (
const auto& item : source)
87 co_yield std::move(element);
90template<xtd::iterable source_t>
92 for (
const auto& item : source)
96template<xtd::iterable source_t>
98 for (
const auto& item : source)
102template<
typename value_t>
104 for (
const auto& item : source)
108template<std::forward_iterator iterator_t>
114template<std::forward_iterator iterator_t>
116 return as_enumerable(iterator, iterator + length);
119template<
typename value_t, xtd::usize length>
121 return as_enumerable(array, array + length);
124template<
typename value_t, xtd::usize length>
126 return as_enumerable(array, array + length);
129template<
typename value_t,
typename container_t>
131 struct accessor :
public std::queue<value_t> {
static auto get() {
return &accessor::c;}};
132 const auto& underlying_items = source.*accessor::get();
133 return as_enumerable(underlying_items.begin(), underlying_items.end());
135template<
typename value_t,
typename container_t>
137 struct accessor :
public std::queue<value_t> {
static auto get() {
return &accessor::c;}};
138 const auto& underlying_items = source.*accessor::get();
139 return as_enumerable(underlying_items.begin(), underlying_items.end());
141template<
typename value_t,
typename container_t>
143 struct accessor :
public std::priority_queue<value_t> {
static auto get() {
return &accessor::c;}};
144 const auto& underlying_items = source.*accessor::get();
145 return as_enumerable(underlying_items.begin(), underlying_items.end());
147template<
typename value_t,
typename container_t>
149 struct accessor :
public std::priority_queue<value_t> {
static auto get() {
return &accessor::c;}};
150 const auto& underlying_items = source.*accessor::get();
151 return as_enumerable(underlying_items.begin(), underlying_items.end());
153template<
typename value_t,
typename container_t>
155 struct accessor :
public std::stack<value_t> {
static auto get() {
return &accessor::c;}};
156 const auto& underlying_items = source.*accessor::get();
157 return as_enumerable(underlying_items.begin(), underlying_items.end());
159template<
typename value_t,
typename container_t>
161 struct accessor :
public std::stack<value_t> {
static auto get() {
return &accessor::c;}};
162 const auto& underlying_items = source.*accessor::get();
163 return as_enumerable(underlying_items.begin(), underlying_items.end());
166template<xtd::iterable source_t>
173 for (
const auto& item : source) {
178 return average / count;
181template<xtd::iterable source_t>
188 for (
const auto& item : source) {
193 return average / count;
196template<xtd::iterable source_t>
203 for (
const auto& item : source) {
208 return average / count;
211template<xtd::iterable source_t>
218 for (
const auto& item : source) {
223 return average / count;
226template<xtd::iterable source_t>
233 for (
const auto& item : source) {
238 return average / count;
241template<xtd::iterable source_t>
248 for (
const auto& item : source) {
253 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
256template<xtd::iterable source_t>
263 for (
const auto& item : source) {
268 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
271template<xtd::iterable source_t>
278 for (
const auto& item : source) {
283 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
286template<xtd::iterable source_t>
293 for (
const auto& item : source) {
298 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
301template<xtd::iterable source_t>
308 for (
const auto& item : source) {
313 return count == 0 ?
xtd::nullopt : std::make_optional(average / count);
316template<xtd::iterable first_t,xtd::iterable second_t>
324 for (
const auto& item : first)
326 for (
const auto& item : second)
330template<xtd::iterable source_t>
334 for (
const auto& item : source)
335 if (item == value)
return true;
339template<xtd::iterable source_t>
343 for (
const auto& item : source)
348template<xtd::iterable source_t, xtd::func_callable<
bool, xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> equater_t>
352 for (
const auto& item : source)
353 if (equater(item, value))
return true;
357template<xtd::iterable source_t>
365template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
367 return where(std::forward<source_t>(source), predicate).count();
370template<xtd::iterable source_t>
375template<
typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
381template<
typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
383 return count_by<key_t>(std::forward<source_t>(source), key_selector, [&key_comparer](
auto&& a,
auto&& b) {
return key_comparer.equals(a, b);});
386template<xtd::iterable source_t>
393 else for (
const auto& item : source)
397template<xtd::iterable source_t>
402 else for (
const auto& item : source)
406template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
408 auto result =
where(std::forward<source_t>(source), std::forward<prediacte_t>(predicate));
409 return any(result) ? *result.begin() : std::move(default_value);
412template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
417template<xtd::iterable source_t>
419 return any(std::forward<source_t>(source)) ? *source.begin() : std::move(default_value);
422template<xtd::iterable source_t>
427template<xtd::iterable source_t>
429 return as_enumerable(source);
432template<xtd::iterable source_t>
434 return as_enumerable(source);
437template<
typename value_t>
439 return as_enumerable(source);
442template<std::forward_iterator iterator_t>
444 return as_enumerable(first, last);
447template<std::forward_iterator iterator_t>
449 return as_enumerable(iterator, length);
452template<
typename value_t, xtd::usize length>
454 return as_enumerable(array);
457template<
typename value_t, xtd::usize length>
459 return as_enumerable(array);
462template<
typename value_t,
typename container_t>
464 return as_enumerable(source);
467template<
typename value_t,
typename container_t>
469 return as_enumerable(source);
472template<
typename value_t,
typename container_t>
474 return as_enumerable(source);
477template<
typename value_t,
typename container_t>
479 return as_enumerable(source);
482template<
typename value_t,
typename container_t>
484 return as_enumerable(source);
487template<
typename value_t,
typename container_t>
489 return as_enumerable(source);
492template<xtd::iterable source_t>
498 for (
const auto& item : source)
499 if (!result || item > result) result = item;
503template<xtd::iterable source_t, xtd::callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> selector_t>
509 for (
const auto& item : source) {
510 auto val = selector(item);
511 if (!result || val > result) result = val;
516template<
typename result_t, xtd::iterable source_t, xtd::callable<result_t, xtd::iterable_value_type<source_t>> selector_t>
522 for (
const auto& item : source) {
523 auto val = selector(item);
524 if (!result || val > result) result = val;
526 return result.value_or(result_t {});
529template<xtd::iterable source_t>
535 for (
const auto& item : source)
536 if (!result || item < result) result = item;
537 return result.value_or(source_t {});
540template<xtd::iterable source_t, xtd::callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> selector_t>
546 for (
const auto& item : source) {
547 auto val = selector(item);
548 if (!result || val < result) result = val;
550 return result.value_or(source_t {});
553template<
typename result_t, xtd::iterable source_t, xtd::callable<result_t, xtd::iterable_value_type<source_t>> selector_t>
559 for (
const auto& item : source) {
560 auto val = selector(item);
561 if (!result || val < result) result = val;
563 return result.value_or(result_t {});
566template<xtd::iterable source_t>
572template<xtd::iterable source_t>
577template<xtd::
integer
integer_t>
579 auto step = integer_t {};
580 return range(integer_t {}, count, ++step);
583template<xtd::
integer
integer_t>
585 auto step = integer_t {};
586 return range(start, count, ++step);
589template<xtd::
integer
integer_t>
594 for (
auto index = integer_t {}; index < count; ++index)
595 co_yield start + (index * step);
598template<
typename result_t, xtd::iterable source_t>
603 for (
const auto& item : source)
604 co_yield invoke_selector_with_optional_index<result_t>(selector, item, index++);
607template<xtd::iterable source_t>
612 for (
const auto& item : source)
613 co_yield invoke_selector_with_optional_index<xtd::iterable_value_type<source_t>>(selector, item, index++);
616template<xtd::iterable source_t>
621 for (
const auto& item : source) {
622 if (index++ < count)
continue;
627template<xtd::iterable source_t>
633 for (
const auto& item : source) {
634 if (skip && !invoke_predicate_with_optional_index(predicate, item, index++)) skip =
false;
635 if (!skip)
co_yield item;
639template<xtd::iterable source_t>
644 for (
const auto& item : source) {
645 if (index++ == count)
break;
650template<xtd::iterable source_t>
655 for (
const auto& item : source) {
656 if (!invoke_predicate_with_optional_index(predicate, item, index++))
break;
661template<xtd::iterable source_t>
666 for (
const auto& item : source)
667 if (invoke_predicate_with_optional_index(predicate, item, index++))
co_yield item;
671template<
typename predicate_t,
typename value_t>
672constexpr auto xtd::linq::enumerable::invoke_predicate_with_optional_index(predicate_t&& predicate, value_t&& value,
xtd::usize index) ->
bool {
675 else static_assert(always_false_v<predicate_t>,
"Predicate must accept either (value) or (value, index).");
678template<
typename result_t,
typename selector_t,
typename value_t>
679auto xtd::linq::enumerable::invoke_selector_with_optional_index(selector_t&& selector, value_t&& value,
xtd::usize index) -> result_t {
682 else static_assert(always_false_v<selector_t>,
"Selector must accept either (value) or (value, index).");
Provides a base class for implementations of the xtd::collections::generic::icomparer <type_t> generi...
Definition comparer.hpp:33
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
Exposes a method that compares two objects.
Definition icomparer.hpp:30
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 skip_while(source_t &&source, auto &&predicate) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaini...
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 min(source_t &&source) -> xtd::iterable_value_type< source_t >
Returns the minimum value in a sequence of xtd::numeric values.
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 take(source_t &&source, xtd::usize count) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns a specified number of contiguous elements from the start of a sequence.
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 order(source_t &&source) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Sorts the elements of a sequence in ascending order.
static auto where(source_t &&source, auto &&predicate) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Filters a sequence of values based on a predicate.
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 range(integer_t count) -> xtd::collections::generic::enumerable_generator< integer_t >
Generates a sequence of integral numbers within a specified range.
static auto skip(source_t &&source, xtd::usize count) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Bypasses a specified number of elements in a sequence and then returns the remaining elements.
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 take_while(source_t &&source, auto &&predicate) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns elements from a sequence as long as a specified condition is true, and then skips the remaini...
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
@ 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
@ 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
auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition range.hpp:39
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.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:75
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:288
Contains xtd::nullopt valiue.
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:72
Implements a function object for compare data.
Definition lesser.hpp:39