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>
110 for (
auto iterator = first; iterator !=
last; ++iterator)
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>
410 for (
const auto& item : source)
415template<xtd::iterable source_t, xtd::func_callable<
bool, xtd::iterable_value_type<source_t>> predicate_t>
419 for (
const auto& item : source)
424template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
426 auto result =
where(std::forward<source_t>(source), std::forward<prediacte_t>(predicate));
427 return any(result) ? *result.begin() : std::move(default_value);
430template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> prediacte_t>
435template<xtd::iterable source_t>
437 return any(std::forward<source_t>(source)) ? *source.begin() : std::move(default_value);
440template<xtd::iterable source_t>
445template<xtd::iterable source_t>
447 return as_enumerable(source);
450template<xtd::iterable source_t>
452 return as_enumerable(source);
455template<
typename value_t>
457 return as_enumerable(source);
460template<std::forward_iterator iterator_t>
462 return as_enumerable(first, last);
465template<std::forward_iterator iterator_t>
467 return as_enumerable(iterator, length);
470template<
typename value_t, xtd::usize length>
472 return as_enumerable(array);
475template<
typename value_t, xtd::usize length>
477 return as_enumerable(array);
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<
typename value_t,
typename container_t>
492 return as_enumerable(source);
495template<
typename value_t,
typename container_t>
497 return as_enumerable(source);
500template<
typename value_t,
typename container_t>
502 return as_enumerable(source);
505template<
typename value_t,
typename container_t>
507 return as_enumerable(source);
510template<xtd::iterable source_t>
512 auto reversed = std::vector<xtd::iterable_value_type<source_t>>(source.begin(), source.end());
513 std::reverse(reversed.begin(), reversed.end());
514 for (
const auto& item : reversed)
519template<xtd::iterable source_t, xtd::func_callable<
bool, xtd::iterable_value_type<source_t>> predicate_t>
521 auto reversed = std::vector(source.begin(), source.end());
522 std::reverse(reversed.begin(), reversed.end());
523 for (
const auto& item : reversed)
528template<xtd::iterable source_t>
534 for (
const auto& item : source)
535 if (!result || item > result) result = item;
539template<xtd::iterable source_t, xtd::callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> selector_t>
545 for (
const auto& item : source) {
546 auto val = selector(item);
547 if (!result || val > result) result = val;
552template<
typename result_t, xtd::iterable source_t, xtd::callable<result_t, xtd::iterable_value_type<source_t>> selector_t>
558 for (
const auto& item : source) {
559 auto val = selector(item);
560 if (!result || val > result) result = val;
562 return result.value_or(result_t {});
565template<xtd::iterable source_t>
571 for (
const auto& item : source)
572 if (!result || item < result) result = item;
576template<xtd::iterable source_t, xtd::callable<xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> selector_t>
582 for (
const auto& item : source) {
583 auto val = selector(item);
584 if (!result || val < result) result = val;
589template<
typename result_t, xtd::iterable source_t, xtd::callable<result_t, xtd::iterable_value_type<source_t>> selector_t>
595 for (
const auto& item : source) {
596 auto val = selector(item);
597 if (!result || val < result) result = val;
599 return result.value_or(result_t {});
602template<xtd::iterable source_t>
608template<xtd::iterable source_t>
613template<xtd::
integer
integer_t>
615 auto step = integer_t {};
616 return range(integer_t {}, count, ++step);
619template<xtd::
integer
integer_t>
621 auto step = integer_t {};
622 return range(start, count, ++step);
625template<xtd::
integer
integer_t>
630 for (
auto index = integer_t {}; index < count; ++index)
631 co_yield start + (index * step);
634template<
typename element_t>
636 for (
auto index =
xtd::usize {}; index < count; ++index)
640template<xtd::iterable source_t>
642 auto reversed = std::vector<xtd::iterable_value_type<source_t>>(source.begin(), source.end());
643 std::reverse(reversed.begin(), reversed.end());
644 for (
const auto& item : reversed)
648template<xtd::iterable source_t>
652 for (
const auto& item : source)
653 co_yield selector(item);
667template<xtd::iterable first_t, xtd::iterable second_t>
669 return sequence_equal(first, second, [](
auto&& f,
auto&& s) {
return f ==
s;});
672template<xtd::iterable first_t, xtd::iterable second_t>
677template<xtd::iterable first_t, xtd::iterable second_t, xtd::func_callable<
bool, xtd::iterable_value_type<first_t>, xtd::iterable_value_type<second_t>> equality_comparer_t>
682 for (
auto index =
xtd::usize {};
const auto& item : second) {
692template<xtd::iterable source_t>
697 for (
const auto& item : source) {
698 if (index++ < count)
continue;
703template<xtd::iterable source_t>
709 for (
const auto& item : source) {
710 if (skip && !invoke_predicate_with_optional_index(predicate, item, index++)) skip =
false;
711 if (!skip)
co_yield item;
715template<xtd::iterable source_t>
720 for (
const auto& item : source) {
721 if (index++ == count)
break;
726template<xtd::iterable source_t>
731 for (
const auto& item : source) {
732 if (!invoke_predicate_with_optional_index(predicate, item, index++))
break;
737template<xtd::iterable source_t>
742 for (
const auto& item : source)
743 if (invoke_predicate_with_optional_index(predicate, item, index++))
co_yield item;
746template<xtd::iterable first_t, xtd::iterable second_t>
748 return zip(std::forward<first_t>(first), std::forward<second_t>(second), [](
const auto& first,
const auto& second) {
return std::make_tuple(first, second);});
750template<xtd::iterable first_t, xtd::iterable second_t>
755 for (
const auto& item : first) {
756 co_yield selector(item, *(second.begin() + index));
760template<xtd::iterable first_t, xtd::iterable second_t, xtd::iterable third_t>
762 return zip(std::forward<first_t>(first), std::forward<second_t>(second), std::forward<third_t>(third), [](
const auto& first,
const auto& second,
const auto& third) {
return std::make_tuple(first, second, third);});
764template<xtd::iterable first_t, xtd::iterable second_t, xtd::iterable third_t>
769 for (
const auto& item : first) {
770 co_yield selector(item, *(second.begin() + index), *(third.begin() + index));
775template<
typename predicate_t,
typename value_t>
776constexpr auto xtd::linq::enumerable::invoke_predicate_with_optional_index(predicate_t&& predicate, value_t&& value,
xtd::usize index) ->
bool {
779 else static_assert(always_false_v<predicate_t>,
"Predicate must accept either (value) or (value, index).");
782template<
typename result_t,
typename selector_t,
typename value_t>
783auto xtd::linq::enumerable::invoke_selector_with_optional_index(selector_t&& selector, value_t&& value,
xtd::usize index) -> result_t {
786 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:45
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 last(source_t &&source) -> xtd::iterable_value_type< source_t >
Returns the last element of a sequence.
static auto sequence_equal(first_t &&first, second_t &&second) -> bool
Determines whether two sequences are equal by comparing the elements by using the default equality co...
static auto zip(first_t &&first, second_t &&second) -> xtd::collections::generic::enumerable_generator< std::tuple< xtd::iterable_value_type< first_t >, xtd::iterable_value_type< second_t > > >
Produces a sequence of tuples with elements from the two specified sequences.
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 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 repeat(const element_t &element, xtd::usize count) -> xtd::collections::generic::enumerable_generator< element_t >
Generates a sequence that contains one repeated value.
static auto first(source_t &&source) -> xtd::iterable_value_type< source_t >
Returns the first element of a 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 reverse(source_t &&source) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Inverts the order of the elements in a sequence.
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 select(source_t &&source, auto &&selector) -> xtd::collections::generic::enumerable_generator< xtd::raw_type< decltype(selector(xtd::iterable_value_type< source_t > {}))> >
Projects each element of a sequence into a new form.
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
@ s
The S key.
Definition console_key.hpp:124
@ f
The F key.
Definition console_key.hpp:98
@ 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
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:245
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:286
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