xtd 1.0.0
Loading...
Searching...
No Matches
enumerable_.hpp
Go to the documentation of this file.
1
4#pragma once
10#define __XTD_STD_INTERNAL__
12#undef __XTD_STD_INTERNAL__
13#define __XTD_CORE_INTERNAL__
17#undef __XTD_CORE_INTERNAL__
18#include "../callable.hpp"
19#include "../decimal.hpp"
20#include "../iterable.hpp"
22#include "../func_callable.hpp"
23#include "../iequatable.hpp"
24#include "../int32.hpp"
25#include "../int64.hpp"
26#include "../numeric.hpp"
27#include "../optional.hpp"
29#include "../static.hpp"
30#include "../usize.hpp"
31#include <algorithm>
32#include <bitset>
33#include <functional>
34#include <queue>
35#include <stack>
36
38template<typename type_t>
39struct __opaque_xtd_linq_enumerable_collection__;
40template<typename type_t, typename param_t>
41struct __opaque_xtd_linq_lazy_enumerable__;
43
45namespace xtd {
47 namespace collections::generic {
48 template<typename type_t>
50 template<typename type_t>
51 class ienumerable;
52 }
54
56 namespace linq {
57
74 public:
76
79 template<typename type_t>
81
83 template<typename type_t>
85
87 template<typename type_t>
89
91 template<typename type_t>
93
95 template<typename key_t, typename value_t>
98
100
110 template<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>
111 [[nodiscard]] static auto aggregate(const source_t& source, func_t&& func) -> xtd::iterable_value_type<source_t>;
122 template<typename accumulate_t, xtd::iterable source_t, xtd::func_callable<accumulate_t, accumulate_t, xtd::iterable_value_type<source_t>> func_t>
123 [[nodiscard]] static auto aggregate(const source_t& source, accumulate_t&& seed, func_t&& func) -> accumulate_t;
136 template<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>
137 [[nodiscard]] static auto aggregate(const source_t& source, accumulate_t&& seed, func_t&& func, result_selector_t&& result_selector) -> result_t;
138
147 template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
148 [[nodiscard]] static auto all(const source_t& source, predicate_t&& predicate) -> bool;
149
158 template<xtd::iterable source_t>
159 [[nodiscard]] static auto any(const source_t& source) noexcept -> bool;
168 template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
169 [[nodiscard]] static auto any(const source_t& source, predicate_t&& predicate) -> bool;
170
179 template<xtd::iterable source_t>
181
189 template<xtd::iterable source_t>
190 [[nodiscard]] static auto as_enumerable(source_t&& source) noexcept; // Defined in include/xtd/collections/generic/list.hpp
198 template<xtd::iterable source_t>
199 [[nodiscard]] static auto as_enumerable(const source_t& source) noexcept -> xtd::collections::generic::enumerable_generator<xtd::iterable_value_type<source_t>>;
207 template<xtd::iterable source_t>
216 template<typename value_t>
217 [[nodiscard]] static auto as_enumerable(std::initializer_list<value_t> source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
226 template<std::forward_iterator iterator_t>
227 [[nodiscard]] static auto as_enumerable(iterator_t first, iterator_t last) noexcept -> xtd::collections::generic::enumerable_generator<typename std::decay<decltype(*first)>::type>;
236 template<std::forward_iterator iterator_t>
237 [[nodiscard]] static auto as_enumerable(iterator_t iterator, xtd::usize length) noexcept -> xtd::collections::generic::enumerable_generator<typename std::decay<decltype(*iterator)>::type>;
246 template<typename value_t, xtd::usize length>
247 [[nodiscard]] static auto as_enumerable(const value_t (&array)[length]) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
256 template<typename value_t, xtd::usize length>
257 [[nodiscard]] static auto as_enumerable(value_t (&array)[length]) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
258
260 template<xtd::usize size_>
261 [[nodiscard]] static auto as_enumerable(const std::bitset<size_>& source) noexcept -> xtd::collections::generic::enumerable_generator<bool>; // defined in xtd/collections/bit_array.hpp
262 template<xtd::usize size_>
263 [[nodiscard]] static auto as_enumerable(std::bitset<size_>& source) noexcept -> xtd::collections::generic::enumerable_generator<bool>; // defined in xtd/collections/bit_array.hpp
264 template<typename value_t, typename container_t>
265 [[nodiscard]] static auto as_enumerable(const std::queue<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
266 template<typename value_t, typename container_t>
267 [[nodiscard]] static auto as_enumerable(std::queue<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
268 template<typename value_t, typename container_t>
269 [[nodiscard]] static auto as_enumerable(const std::priority_queue<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
270 template<typename value_t, typename container_t>
271 [[nodiscard]] static auto as_enumerable(std::priority_queue<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
272 template<typename value_t, typename container_t>
273 [[nodiscard]] static auto as_enumerable(const std::stack<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
274 template<typename value_t, typename container_t>
275 [[nodiscard]] static auto as_enumerable(std::stack<value_t, container_t>& source) noexcept -> xtd::collections::generic::enumerable_generator<value_t>;
277
282 template<xtd::iterable source_t>
284 [[nodiscard]] static auto average(const source_t& source) -> xtd::decimal;
289 template<xtd::iterable source_t>
291 [[nodiscard]] static auto average(const source_t& source) -> double;
296 template<xtd::iterable source_t>
298 [[nodiscard]] static auto average(const source_t& source) -> xtd::single;
303 template<xtd::iterable source_t>
305 [[nodiscard]] static auto average(const source_t& source) -> double;
310 template<xtd::iterable source_t>
312 [[nodiscard]] static auto average(const source_t& source) -> double;
313
317 template<xtd::iterable source_t>
318 requires std::same_as<xtd::iterable_value_type<source_t>, xtd::optional<xtd::decimal>>
319 [[nodiscard]] static auto average(const source_t& source) -> xtd::optional<xtd::decimal>;
323 template<xtd::iterable source_t>
324 requires std::same_as<xtd::iterable_value_type<source_t>, xtd::optional<double>>
325 [[nodiscard]] static auto average(const source_t& source) -> xtd::optional<double>;
329 template<xtd::iterable source_t>
330 requires std::same_as<xtd::iterable_value_type<source_t>, xtd::optional<xtd::single>>
331 [[nodiscard]] static auto average(const source_t& source) -> xtd::optional<xtd::single>;
335 template<xtd::iterable source_t>
336 requires std::same_as<xtd::iterable_value_type<source_t>, xtd::optional<xtd::int32>>
337 [[nodiscard]] static auto average(const source_t& source) -> xtd::optional<double>;
341 template<xtd::iterable source_t>
342 requires std::same_as<xtd::iterable_value_type<source_t>, xtd::optional<xtd::int64>>
343 [[nodiscard]] static auto average(const source_t& source) -> xtd::optional<double>;
344
352 template<typename result_t, xtd::iterable source_t>
353 [[nodiscard]] static auto cast(source_t&& source) -> xtd::collections::generic::enumerable_generator<result_t>; // Defined include/xtd/as.hpp
354
361 template<xtd::iterable source_t>
362 [[nodiscard]] static auto chunk(source_t&& source, xtd::usize size) -> xtd::collections::generic::enumerable_generator<xtd::array<xtd::iterable_value_type<source_t>>>; // Defined in include/xtd/array.hpp
363
369 template<xtd::iterable first_t,xtd::iterable second_t>
370 [[nodiscard]] static auto concat(first_t&& first, second_t&& second) noexcept -> xtd::collections::generic::enumerable_generator<xtd::iterable_value_type<first_t>>;
371
377 template<xtd::iterable source_t>
378 [[nodiscard]] static auto contains(const source_t& source, const xtd::iterable_value_type<source_t>& value) noexcept -> bool;
385 template<xtd::iterable source_t>
386 [[nodiscard]] static auto contains(const source_t& source, const xtd::iterable_value_type<source_t>& value, const iequality_comparer<xtd::iterable_value_type<source_t>>& comparer) noexcept -> bool;
393 template<xtd::iterable source_t, xtd::func_callable<bool, xtd::iterable_value_type<source_t>, xtd::iterable_value_type<source_t>> equater_t>
394 [[nodiscard]] static auto contains(const source_t& source, const xtd::iterable_value_type<source_t>& value, equater_t&& equater) noexcept -> bool;
395
403 template<xtd::iterable source_t>
404 [[nodiscard]] static auto count(const source_t& source) noexcept -> xtd::usize;
413 template<xtd::iterable source_t, xtd::predicate_callable<xtd::iterable_value_type<source_t>> predicate_t>
414 [[nodiscard]] static auto count(const source_t& source, predicate_t&& predicate) noexcept -> xtd::usize;
420 template<xtd::iterable source_t>
421 [[nodiscard]] static auto count(const source_t& source, xtd::iterable_value_type<source_t>&& value) noexcept -> xtd::usize;
422
432 template<typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
433 [[nodiscard]] static auto count_by(const source_t& source, key_selector_t&& key_selector) noexcept -> xtd::collections::generic::enumerable_generator<xtd::collections::generic::key_value_pair<key_t, xtd::usize>>;
444 template<typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t>
445 [[nodiscard]] static auto count_by(const source_t& source, key_selector_t&& key_selector, const iequality_comparer<key_t>& key_comparer) noexcept -> xtd::collections::generic::enumerable_generator<xtd::collections::generic::key_value_pair<key_t, xtd::usize>>;
456 template<typename key_t, xtd::iterable source_t, xtd::callable<key_t, xtd::iterable_value_type<source_t>> key_selector_t, xtd::callable<bool, key_t, key_t> key_equater_t>
457 [[nodiscard]] static auto count_by(const source_t& source, key_selector_t&& key_selector, key_equater_t&& key_equater) noexcept -> xtd::collections::generic::enumerable_generator<xtd::collections::generic::key_value_pair<key_t, xtd::usize>>; // Defined in include/xtd/collections/generic/list.hpp
458
466 template<typename source_t>
467 [[nodiscard]] static auto default_if_empty(const ienumerable<source_t>& source) noexcept {
468 return default_if_empty(source, source_t {});
469 }
470
479 template<typename source_t>
480 [[nodiscard]] static auto default_if_empty(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
481 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
482 if (!any(source)) result.items.push_back(default_value);
483 else for (const auto& item : source)
484 result.items.push_back(item);
485 return result;
486 }
487
491 template<typename source_t>
492 [[nodiscard]] static auto distinct(const ienumerable<source_t>& source) noexcept {
493 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
494 for (const auto& item : source)
495 if (!contains(result, item))
496 result.items.push_back(item);
497 return result;
498 }
499
504 template<typename source_t>
505 [[nodiscard]] static auto distinct(const ienumerable<source_t>& source, const iequality_comparer<source_t>& comparer) noexcept {
506 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
507 for (const auto& item : source)
508 if (!contains(result, item, comparer))
509 result.items.push_back(item);
510 return result;
511 }
512
519 template<typename source_t>
520 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate, const source_t& default_value) noexcept -> source_t {
521 const auto& result = where(source, predicate);
522 return any(result) ? *result.begin() : default_value;
523 }
524
529 template<typename source_t>
530 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept -> source_t {
531 return first_or_default(source, predicate, source_t {});
532 }
533
538 template<typename source_t>
539 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source, const source_t& default_value) noexcept -> source_t {
540 return any(source) ? *source.begin() : default_value;
541 }
542
546 template<typename source_t>
547 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source) noexcept -> source_t {
548 return first_or_default(source, source_t {});
549 }
550
559 template<typename source_t>
560 [[nodiscard]] static const auto& from(const ienumerable<source_t>& source) noexcept {
561 return as_enumerable(source);
562 }
563
571 template<typename source_t>
572 [[nodiscard]] static auto from(std::initializer_list<source_t> source) noexcept {
573 return as_enumerable(source);
574 }
575
583 template<typename collection_t>
584 [[nodiscard]] static auto from(const collection_t& source) noexcept {
585 return as_enumerable(source);
586 }
587
598 template<typename input_iterator_t>
599 [[nodiscard]] static auto from(input_iterator_t first, input_iterator_t last) noexcept {
600 return as_enumerable(first, last);
601 }
602
611 template<typename input_iterator_t>
612 [[nodiscard]] static auto from(input_iterator_t iterator, xtd::usize length) noexcept {
614 }
615
624 template<typename source_t, xtd::usize length>
625 [[nodiscard]] static auto from(const source_t (&array)[length]) noexcept {
626 return as_enumerable(array, array + length);
627 }
628
630 template<typename source_t, typename container_t>
631 [[nodiscard]] static auto from(const std::queue<source_t, container_t>& source) noexcept {
632 return as_enumerable(source);
633 }
634 template<typename source_t, typename container_t>
635 [[nodiscard]] static auto from(const std::stack<source_t, container_t>& source) noexcept {
636 return as_enumerable(source);
637 }
639
640 template<typename result_t, typename source_t>
642 [[nodiscard]] static auto max(const ienumerable<source_t>& source, auto&& selector) {
643 auto result = std::optional<result_t> {};
644 for (const auto& item : source) {
645 auto val = selector(item);
646 if (!result || val > result) result = val;
647 }
648 return result.value_or(result_t {});
649 }
650
651 template<typename source_t>
652 requires xtd::numeric<source_t>
653 [[nodiscard]] static auto max(const ienumerable<source_t>& source, auto&& selector) {
654 auto result = std::optional<source_t> {};
655 for (const auto& item : source) {
656 auto val = selector(item);
657 if (!result || val > result) result = val;
658 }
659 return result.value_or(source_t {});
660 }
661
662 template<typename source_t>
663 requires xtd::numeric<source_t>
664 [[nodiscard]] static auto max(const ienumerable<source_t>& source) {
665 auto result = std::optional<source_t> {};
666 for (const auto& item : source)
667 if (!result || item > result) result = item;
668 return result.value_or(source_t {});
669 }
670
671 template<typename result_t, typename source_t>
672 requires xtd::numeric<result_t>
673 [[nodiscard]] static auto min(const ienumerable<source_t>& source, auto&& selector) {
674 auto result = std::optional<result_t> {};
675 for (const auto& item : source) {
676 auto val = selector(item);
677 if (!result || val < result) result = val;
678 }
679 return result.value_or(result_t {});
680 }
681
682 template<typename source_t>
683 requires xtd::numeric<source_t>
684 [[nodiscard]] static auto min(const ienumerable<source_t>& source, auto&& selector) {
685 auto result = std::optional<source_t> {};
686 for (const auto& item : source) {
687 auto val = selector(item);
688 if (!result || val < result) result = val;
689 }
690 return result.value_or(source_t {});
691 }
692
693 template<typename source_t>
694 requires xtd::numeric<source_t>
695 [[nodiscard]] static auto min(const ienumerable<source_t>& source) {
696 auto result = std::optional<source_t> {};
697 for (const auto& item : source)
698 if (!result || item < result) result = item;
699 return result.value_or(source_t {});
700 }
701
705 template<typename source_t>
706 [[nodiscard]] static auto order(const ienumerable<source_t>& source) {
708 }
709
713 template<typename source_t>
714 [[nodiscard]] static auto order(const ienumerable<source_t>& source, const xtd::collections::generic::icomparer<source_t>& comparer) {
715 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
716 for (const auto& item : source)
717 result.items.push_back(item);
718 std::sort(result.items.begin(), result.items.end(), xtd::collections::generic::helpers::lesser<source_t>(comparer));
719 return result;
720 }
721
728 template<typename key_t, typename source_t>
729 [[nodiscard]] static auto order_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
730 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
731 for (const auto& item : source)
732 result.items.push_back(item);
733 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);});
734 return result;
735 }
736
743 template<typename source_t>
744 [[nodiscard]] static auto order_by(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
745 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
746 for (const auto& item : source)
747 result.items.push_back(item);
748 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);});
749 return result;
750 }
751
758 template<typename key_t, typename source_t>
759 [[nodiscard]] static auto order_by_descending(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
760 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
761 for (const auto& item : source)
762 result.items.push_back(item);
763 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);});
764 return result;
765 }
766
773 template<typename source_t>
774 [[nodiscard]] static auto order_by_descending(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
775 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
776 for (const auto& item : source)
777 result.items.push_back(item);
778 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);});
779 return result;
780 }
781
789 template<typename type_t>
790 [[nodiscard]] static auto range(type_t count) {
791 auto step = type_t {};
792 return range(type_t {}, count, ++step);
793 }
794
802 template<typename type_t>
803 [[nodiscard]] static auto range(type_t start, type_t count) {
804 auto step = type_t {};
805 return range(start, count, ++step);
806 }
807
813 template<typename type_t>
814 [[nodiscard]] static auto range(type_t start, type_t count, type_t step) {
817
818 auto result = __opaque_xtd_linq_enumerable_collection__<type_t> {};
819 for (auto index = type_t {}; index < count; ++index)
820 result.items.push_back(start + (index * step));
821 return result;
822 }
823
833 template<typename result_t, xtd::iterable source_t>
834 [[nodiscard]] static auto select(source_t&& source, auto&& selector) -> xtd::collections::generic::enumerable_generator<result_t>;
844 template<xtd::iterable source_t>
845 [[nodiscard]] static auto select(source_t&& source, auto&& selector) -> xtd::collections::generic::enumerable_generator<xtd::iterable_value_type<source_t>>;
846
855 template<typename source_t>
856 [[nodiscard]] static auto to_array(const ienumerable<source_t>& source); // Defined in include/xtd/array.hpp
857
866 template<typename source_t>
867 [[nodiscard]] static auto to_list(const ienumerable<source_t>& source); // Defined in include/xtd/collections/generic/list.hpp
868
880 template<typename source_t>
881 [[nodiscard]] static auto where(const ienumerable<source_t>& source, auto&& predicate) {
882 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
883 auto index = xtd::usize {0};
884 for (const auto& item : source)
885 if (invoke_predicate_with_optional_index(predicate, item, index++)) result.items.push_back(item);
886 return result;
887 }
888
889
890 private:
891 template<typename...>
892 static inline constexpr bool always_false_v = false;
893
894 template<typename predicate_t, typename value_t>
895 [[nodiscard]] static constexpr auto invoke_predicate_with_optional_index(predicate_t&& predicate, value_t&& value, xtd::usize index) -> bool;
896
897 template<typename result_t, typename selector_t, typename value_t>
898 [[nodiscard]] static auto invoke_selector_with_optional_index(selector_t&& selector, value_t&& value, xtd::usize index) -> result_t;
899 };
900 }
901}
Contains xtd::callable concept.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
static const comparer< xtd::any_object > default_comparer
Definition comparer.hpp:50
Represents an enumerable generator that supports deferred, lazy iteration over a collection of a spec...
Definition enumerable_generator.hpp:44
Exposes a method that compares two objects.
Definition icomparer.hpp:30
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:82
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable_.hpp:73
static auto chunk(source_t &&source, xtd::usize size) -> xtd::collections::generic::enumerable_generator< xtd::array< xtd::iterable_value_type< source_t > > >
Splits the elements of a sequence into chunks of size at most size.
static auto from(const collection_t &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:584
static auto average(const source_t &source) -> double
Computes the average of a sequence of xtd::int64 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:467
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:774
static auto count(const source_t &source, predicate_t &&predicate) noexcept -> xtd::usize
Returns a number that represents how many elements in the specified sequence satisfy a condition.
static auto count_by(const 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 from(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:599
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable_.hpp:88
static auto first_or_default(const ienumerable< source_t > &source) noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable_.hpp:547
static auto from(input_iterator_t iterator, xtd::usize length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:612
typename xtd::collections::generic::enumerator< type_t > enumerator
Represents the enumerator value type.
Definition enumerable_.hpp:80
static auto from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:625
static auto contains(const source_t &source, const xtd::iterable_value_type< source_t > &value, const iequality_comparer< xtd::iterable_value_type< source_t > > &comparer) noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
static auto count(const source_t &source, xtd::iterable_value_type< source_t > &&value) noexcept -> xtd::usize
Returns the number of elements with the specified value.
static auto concat(first_t &&first, second_t &&second) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< first_t > >
Concatenates two sequences.
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable_.hpp:84
static auto range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable_.hpp:803
static auto as_enumerable(iterator_t first, iterator_t last) noexcept -> xtd::collections::generic::enumerable_generator< typename std::decay< decltype(*first)>::type >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable_.hpp:92
static auto as_enumerable(value_t(&array)[length]) noexcept -> xtd::collections::generic::enumerable_generator< value_t >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
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 distinct(const ienumerable< source_t > &source, const iequality_comparer< source_t > &comparer) noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable_.hpp:505
static auto any(const source_t &source, predicate_t &&predicate) -> bool
Determines whether any element of a sequence satisfies a condition.
static auto as_enumerable(const value_t(&array)[length]) noexcept -> xtd::collections::generic::enumerable_generator< value_t >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto count(const source_t &source) noexcept -> xtd::usize
Returns the number of elements in a sequence.
static auto average(const source_t &source) -> xtd::optional< xtd::single >
Computes the average of a sequence of optional float values.
static auto as_enumerable(const source_t &source) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto aggregate(const source_t &source, func_t &&func) -> xtd::iterable_value_type< source_t >
Applies an accumulator function over a sequence.
static auto aggregate(const source_t &source, accumulate_t &&seed, func_t &&func) -> accumulate_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
static auto average(const source_t &source) -> xtd::decimal
Computes the average of a sequence of xtd::decimal values.
static auto average(const source_t &source) -> xtd::optional< xtd::decimal >
Computes the average of a sequence of optional xtd::decimal values.
static auto as_enumerable(iterator_t iterator, xtd::usize length) noexcept -> xtd::collections::generic::enumerable_generator< typename std::decay< decltype(*iterator)>::type >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto count_by(const source_t &source, key_selector_t &&key_selector, const iequality_comparer< key_t > &key_comparer) 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 first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate, const source_t &default_value) noexcept -> source_t
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable_.hpp:520
static auto any(const source_t &source) noexcept -> bool
Determines whether a sequence contains any elements.
static auto order(const ienumerable< source_t > &source, const xtd::collections::generic::icomparer< source_t > &comparer)
Sorts the elements of a sequence in ascending order.
Definition enumerable_.hpp:714
static auto first_or_default(const ienumerable< source_t > &source, const source_t &default_value) noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable_.hpp:539
static auto cast(source_t &&source) -> xtd::collections::generic::enumerable_generator< result_t >
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static auto from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:572
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:480
static auto as_enumerable(source_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto as_enumerable(source_t &source) noexcept -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto all(const source_t &source, predicate_t &&predicate) -> bool
Determines whether all elements of a sequence satisfy a condition.
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:814
static auto average(const source_t &source) -> double
Computes the average of a sequence of xtd::int32 values.
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:759
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:492
static auto select(source_t &&source, auto &&selector) -> xtd::collections::generic::enumerable_generator< xtd::iterable_value_type< source_t > >
Projects each element of a sequence into a new form by incorporating the element's index.
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:744
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:729
static auto order(const ienumerable< source_t > &source)
Sorts the elements of a sequence in ascending order.
Definition enumerable_.hpp:706
static auto to_array(const ienumerable< source_t > &source)
Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
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 where(const ienumerable< source_t > &source, auto &&predicate)
Filters a sequence of values based on a predicate.
Definition enumerable_.hpp:881
static auto average(const source_t &source) -> xtd::single
Computes the average of a sequence of float values.
static auto average(const source_t &source) -> xtd::optional< double >
Computes the average of a sequence of optional xtd::int32 values.
static auto as_enumerable(std::initializer_list< value_t > source) noexcept -> xtd::collections::generic::enumerable_generator< value_t >
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
static auto average(const source_t &source) -> xtd::optional< double >
Computes the average of a sequence of optional xtd::int64 values.
xtd::collections::generic::key_value_pair< key_t, value_t > key_value_pair
Represents the key value pair value type.
Definition enumerable_.hpp:96
static auto first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept -> source_t
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable_.hpp:530
static auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable_.hpp:790
static auto aggregate(const source_t &source, accumulate_t &&seed, func_t &&func, result_selector_t &&result_selector) -> result_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
static auto contains(const source_t &source, const xtd::iterable_value_type< source_t > &value, equater_t &&equater) noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
static auto average(const source_t &source) -> xtd::optional< double >
Computes the average of a sequence of optional double values.
static auto average(const source_t &source) -> double
Computes the average of a sequence of double values.
static const auto & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable_.hpp:560
static auto to_list(const ienumerable< source_t > &source)
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
static auto contains(const 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(const source_t &source, key_selector_t &&key_selector, key_equater_t &&key_equater) 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.
Definition numeric.hpp:12
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::decimal type.
Contains xtd::collections::generic::equality_comparer <type_t> class.
Contains xtd::func_callable concept.
Contains xtd::collections::generic::comparer <type_t> class.
Contains xtd::collections::generic::enumerator <type_t> class.
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
@ 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:38
std::type_info type
Stores information about a type.
Definition type.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:26
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
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
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.
Contains xtd::iterable concept.
Contains xtd::iterable_value_type alias.
Contains xtd::collections::generic::helpers::lesser struct.
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:56
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:70
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:248
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
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:212
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:216
Contains xtd::numeric concept.
Contains xtd::optional type.
Contains xtd::predicate_callable concept.
Contains xtd::collections::generic::helpers::raw_array class.
Contains xtd::static_object class.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:39
Implements a function object for compare data.
Definition lesser.hpp:39
Defines a key/value pair that can be set or retrieved.
Definition key_value_pair.hpp:37
Contains xtd::usize type.