xtd 1.0.0
Loading...
Searching...
No Matches
enumerable.hpp
Go to the documentation of this file.
1
4#pragma once
8//#include "../collections/generic/iequality_comparer.hpp"
12#define __XTD_STD_INTERNAL__
14#undef __XTD_STD_INTERNAL__
15#define __XTD_CORE_INTERNAL__
19#undef __XTD_CORE_INTERNAL__
20#include "../decimal.hpp"
21#include "../iequatable.hpp"
22#include "../int32.hpp"
23#include "../int64.hpp"
24#include "../numeric.hpp"
25#include "../optional.hpp"
26#include "../static.hpp"
27#include "../usize.hpp"
28#include <algorithm>
29#include <bitset>
30#include <functional>
31#include <queue>
32#include <stack>
33
35template<typename type_t>
36struct __opaque_xtd_linq_enumerable_collection__;
37template<typename type_t, typename param_t>
38struct __opaque_xtd_linq_lazy_enumerable__;
40
42namespace xtd {
44 namespace collections::generic {
45 template<typename type_t>
46 class ienumerable;
47 }
49
51 namespace linq {
52
69 public:
71
74 template<typename type_t>
76
78 template<typename type_t>
80
82 template<typename type_t>
84
86 template<typename type_t>
88
90 template<typename key_t, typename value_t>
93
95
105 template<typename source_t>
106 [[nodiscard]] static auto aggregate(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, const source_t&)>& func) -> source_t {
107 auto nb = 0;
108 auto aggregated = source_t {};
109 for (const auto& item : source)
110 if (nb++ == 0) aggregated = item;
111 else aggregated = func(aggregated, item);
112 return aggregated;
113 }
114
123 template<typename source_t>
124 [[nodiscard]] static auto aggregate(const ienumerable<source_t>& source, const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func) -> source_t {
125 auto aggregated = seed;
126 for (const auto& item : source)
127 aggregated = func(aggregated, item);
128 return aggregated;
129 }
130
140 template<typename accumulate_t, typename source_t>
141 [[nodiscard]] static auto aggregate(const ienumerable<source_t>& source, const accumulate_t& seed, const std::function<accumulate_t(const accumulate_t&, const source_t&)>& func) -> accumulate_t {
142 auto aggregated = seed;
143 for (const auto& item : source)
144 aggregated = func(aggregated, item);
145 return aggregated;
146 }
147
157 template<typename source_t>
158 [[nodiscard]] static auto aggregate(const ienumerable<source_t>& source, const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func, const std::function<source_t(const source_t&)>& result_selector) -> source_t {
159 auto aggregated = seed;
160 for (const auto& item : source)
161 aggregated = func(aggregated, item);
162 return result_selector(aggregated);
163 }
164
176 template<typename result_t, typename accumulate_t, typename source_t>
177 [[nodiscard]] static auto aggregate(const ienumerable<source_t>& source, const accumulate_t& seed, const std::function<accumulate_t(const accumulate_t&, const source_t&)>& func, const std::function<result_t(const accumulate_t&)>& result_selector) -> result_t {
178 auto aggregated = seed;
179 for (const auto& item : source)
180 aggregated = func(aggregated, item);
181 return result_selector(aggregated);
182 }
183
192 template<typename source_t>
193 [[nodiscard]] static auto all(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) -> bool {
194 for (const auto& item : source)
195 if (!predicate(item)) return false;
196 return true;
197 }
198
207 template<typename source_t>
208 [[nodiscard]] static auto any(const ienumerable<source_t>& source) noexcept -> bool {
209 return source.begin() != source.end();
210 }
211
219 template<typename source_t>
220 [[nodiscard]] static auto any(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) -> bool {
221 for (const auto& item : source)
222 if (predicate(item)) return true;
223 return false;
224 }
225
234 template<typename source_t>
235 [[nodiscard]] static auto append(const ienumerable<source_t>& source, const source_t& element) noexcept {
236 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
237 for (const auto& item : source)
238 result.items.push_back(item);
239 result.items.push_back(element);
240 return result;
241 }
242
243 /*
244 template<typename source_t>
245 [[nodiscard]] static auto append(const ienumerable<source_t>& source, const source_t& element) noexcept {
246 using param_type = std::tuple<source_t, enumerator<source_t>, source_t, bool>;
247 auto result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {};
248
249 result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {
250 std::make_tuple(source_t {}, source.get_enumerator(), element, false),
251 [](param_type& params) {
252 auto& result = std::get<0>(params);
253 auto& source_enumerator = std::get<1>(params);
254 const auto& element = std::get<2>(params);
255 auto& appended = std::get<3>(params);
256
257 if (source_enumerator.move_next()) {
258 result = source_enumerator.current();
259 return true;
260 }
261
262 if (!appended) {
263 appended = true;
264 result = element;
265 return true;
266 }
267
268 return false;
269 },
270 [](param_type& params) {
271 auto& result = std::get<0>(params);
272 auto& source_enumerator = std::get<1>(params);
273 auto& appended = std::get<3>(params);
274
275 result = source_t {};
276 source_enumerator.reset();
277 appended = false;
278 }
279 };
280
281 return result;
282 }*/
283
291 template<typename source_t>
292 [[nodiscard]] static const auto& as_enumerable(const ienumerable<source_t>& source) noexcept {
293 return source;
294 }
295
302 template<typename source_t>
303 [[nodiscard]] static auto as_enumerable(std::initializer_list<source_t> source) noexcept {
304 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
305 for (const auto& item : source)
306 result.items.push_back(item);
307 return result;
308 }
309
316 template<typename collection_t>
317 [[nodiscard]] static auto as_enumerable(collection_t&& source) noexcept {
318#if defined(__xtd__cpp_lib_ranges)
319 using source_t = std::ranges::range_value_t<collection_t>;
320#else
321 using source_t = typename collection_t::value_type;
322#endif
323 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
324 for (auto&& item : source)
325 result.items.push_back(item);
326 return result;
327 }
328
336 template<typename input_iterator_t>
337 [[nodiscard]] static auto as_enumerable(input_iterator_t first, input_iterator_t last) noexcept {
338 using source_t = typename std::decay<decltype(*first)>::type;
339 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
340 for (auto iterator = first; iterator != last; ++iterator)
341 result.items.push_back(*iterator);
342 return result;
343 }
344
352 template<typename input_iterator_t>
353 [[nodiscard]] static auto as_enumerable(input_iterator_t iterator, xtd::usize length) noexcept {
355 }
356
364 template<typename source_t, xtd::usize length>
365 [[nodiscard]] static auto as_enumerable(const source_t (&array)[length]) noexcept {
366 return as_enumerable(array, array + length);
367 }
368
370 template<xtd::usize size_>
371 [[nodiscard]] static auto as_enumerable(std::bitset<size_> source); // defined in xtd/collections/bit_array.hpp
372 template<typename source_t, typename container_t>
373 static auto as_enumerable(std::queue<source_t, container_t> source) noexcept {
374 struct accessor : public std::queue<source_t> {static auto get() {return &accessor::c;}};
375 const auto& underlying_items = source.*accessor::get();
376 return as_enumerable(underlying_items.begin(), underlying_items.end());
377 }
378 template<typename source_t, typename container_t>
379 [[nodiscard]] static auto as_enumerable(std::priority_queue<source_t, container_t> source) noexcept {
380 struct accessor : public std::priority_queue<source_t> {static auto get() {return &accessor::c;}};
381 const auto& underlying_items = source.*accessor::get();
382 return as_enumerable(underlying_items.begin(), underlying_items.end());
383 }
384 template<typename source_t, typename container_t>
385 [[nodiscard]] static auto as_enumerable(std::stack<source_t, container_t> source) noexcept {
386 struct accessor : public std::stack<source_t> {static auto get() {return &accessor::c;}};
387 const auto& underlying_items = source.*accessor::get();
388 return as_enumerable(underlying_items.begin(), underlying_items.end());
389 }
391
396 [[nodiscard]] static auto average(const ienumerable<xtd::decimal>& source) -> xtd::decimal;
401 [[nodiscard]] static auto average(const ienumerable<double>& source) -> double;
406 [[nodiscard]] static auto average(const ienumerable<float>& source) -> float;
411 [[nodiscard]] static auto average(const ienumerable<xtd::int32>& source) -> double;
416 [[nodiscard]] static auto average(const ienumerable<xtd::int64>& source) -> double;
417
421 [[nodiscard]] static auto average(const ienumerable<xtd::optional<xtd::decimal >>& source) noexcept -> xtd::optional<xtd::decimal>;
425 [[nodiscard]] static auto average(const ienumerable<xtd::optional<double >>& source) noexcept -> xtd::optional<double>;
429 [[nodiscard]] static auto average(const ienumerable<xtd::optional<float >>& source) noexcept -> xtd::optional<float>;
433 [[nodiscard]] static auto average(const ienumerable<xtd::optional<xtd::int32 >>& source) noexcept -> xtd::optional<double>;
437 [[nodiscard]] static auto average(const ienumerable<xtd::optional<xtd::int64 >>& source) noexcept -> xtd::optional<double>;
438
446 template<typename result_t, typename source_t>
447 [[nodiscard]] static auto cast(const ienumerable<source_t>& source) noexcept; // Defined include/xtd/as.hpp
448
455 template<typename source_t>
456 [[nodiscard]] static auto chunk(const ienumerable<source_t>& source, xtd::usize size); // Defined in include/xtd/array.hpp
457
463 template<typename source_t>
464 [[nodiscard]] static auto concat(const ienumerable<source_t>& first, const ienumerable<source_t>& second) noexcept {
465 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
466 for (const auto& item : first)
467 result.items.push_back(item);
468 for (const auto& item : second)
469 result.items.push_back(item);
470 return result;
471 }
472
478 template<typename source_t>
479 [[nodiscard]] static auto contains(const ienumerable<source_t>& source, const source_t& value) noexcept -> bool {
480 for (const auto& item : source)
481 if (item == value) return true;
482 return false;
483 }
484
491 template<typename source_t>
492 [[nodiscard]] static auto contains(const ienumerable<source_t>& source, const source_t& value, const xtd::collections::generic::iequality_comparer<source_t>& comparer) noexcept -> bool {
493 for (const auto& item : source)
494 if (comparer.equals(item, value)) return true;
495 return false;
496 }
497
505 template<typename source_t>
506 [[nodiscard]] static auto count(const ienumerable<source_t>& source) noexcept -> xtd::usize {
507 auto count = xtd::usize {0};
508 auto enumerator = source.get_enumerator();
509 while (enumerator.move_next()) ++count;
510 return count;
511 }
512
521 template<typename source_t>
522 [[nodiscard]] static auto count(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept -> xtd::usize {
523 return where<source_t>(source, predicate).count();
524 }
525
531 template<typename source_t>
532 [[nodiscard]] static auto count(const ienumerable<source_t>& source, const source_t& value) noexcept -> xtd::usize {
533 return count<source_t>(source, [value](const source_t& item) -> bool {return item == value;});
534 }
535
545 template<typename key_t, typename source_t>
546 [[nodiscard]] static auto count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) noexcept {
548 }
549
560 template<typename key_t, typename source_t>
561 [[nodiscard]] static auto count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector, const iequality_comparer<key_t>& key_comparer) noexcept {
562 auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::usize>> {};
563 auto keys = list<key_t> {};
564 auto enumerator = source.get_enumerator();
565 while (enumerator.move_next()) {
566 auto key = key_selector(enumerator.current());
567 auto index = xtd::usize {0};
568 for (; index < keys.count(); ++index)
569 if (key_comparer.equals(keys[index], key)) break;
570 if (index < keys.count()) result.items[index] = {key, result.items[index].value() + 1};
571 else {
572 keys.add(key);
573 result.items.push_back({key, 1});
574 }
575 }
576 return result;
577 }
578
586 template<typename source_t>
587 [[nodiscard]] static auto default_if_empty(const ienumerable<source_t>& source) noexcept {
588 return default_if_empty(source, source_t {});
589 }
590
599 template<typename source_t>
600 [[nodiscard]] static auto default_if_empty(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
601 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
602 if (!any(source)) result.items.push_back(default_value);
603 else for (const auto& item : source)
604 result.items.push_back(item);
605 return result;
606 }
607
611 template<typename source_t>
612 [[nodiscard]] static auto distinct(const ienumerable<source_t>& source) noexcept {
613 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
614 for (const auto& item : source)
615 if (!contains(result, item))
616 result.items.push_back(item);
617 return result;
618 }
619
624 template<typename source_t>
625 [[nodiscard]] static auto distinct(const ienumerable<source_t>& source, const xtd::collections::generic::iequality_comparer<source_t>& comparer) noexcept {
626 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
627 for (const auto& item : source)
628 if (!contains(result, item, comparer))
629 result.items.push_back(item);
630 return result;
631 }
632
639 template<typename source_t>
640 [[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 {
641 const auto& result = where(source, predicate);
642 return any(result) ? *result.begin() : default_value;
643 }
644
649 template<typename source_t>
650 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept -> source_t {
651 return first_or_default(source, predicate, source_t {});
652 }
653
658 template<typename source_t>
659 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source, const source_t& default_value) noexcept -> source_t {
660 return any(source) ? *source.begin() : default_value;
661 }
662
666 template<typename source_t>
667 [[nodiscard]] static auto first_or_default(const ienumerable<source_t>& source) noexcept -> source_t {
668 return first_or_default(source, source_t {});
669 }
670
679 template<typename source_t>
680 [[nodiscard]] static const auto& from(const ienumerable<source_t>& source) noexcept {
681 return as_enumerable(source);
682 }
683
691 template<typename source_t>
692 [[nodiscard]] static auto from(std::initializer_list<source_t> source) noexcept {
693 return as_enumerable(source);
694 }
695
703 template<typename collection_t>
704 [[nodiscard]] static auto from(collection_t&& source) noexcept {
705 return as_enumerable(source);
706 }
707
718 template<typename input_iterator_t>
719 [[nodiscard]] static auto from(input_iterator_t first, input_iterator_t last) noexcept {
720 return as_enumerable(first, last);
721 }
722
731 template<typename input_iterator_t>
732 [[nodiscard]] static auto from(input_iterator_t iterator, xtd::usize length) noexcept {
734 }
735
744 template<typename source_t, xtd::usize length>
745 [[nodiscard]] static auto from(const source_t (&array)[length]) noexcept {
746 return as_enumerable(array, array + length);
747 }
748
750 template<typename source_t, typename container_t>
751 [[nodiscard]] static auto from(std::queue<source_t, container_t> source) noexcept {
752 return as_enumerable(source);
753 }
754 template<typename source_t, typename container_t>
755 [[nodiscard]] static auto from(std::stack<source_t, container_t> source) noexcept {
756 return as_enumerable(source);
757 }
759
760 template<typename result_t, typename source_t>
762 [[nodiscard]] static auto max(const ienumerable<source_t>& source, auto&& selector) {
763 auto result = std::optional<result_t> {};
764 for (const auto& item : source) {
765 auto val = selector(item);
766 if (!result || val > result) result = val;
767 }
768 return result.value_or(result_t {});
769 }
770
771 template<typename source_t>
772 requires xtd::numeric<source_t>
773 [[nodiscard]] static auto max(const ienumerable<source_t>& source, auto&& selector) {
774 auto result = std::optional<source_t> {};
775 for (const auto& item : source) {
776 auto val = selector(item);
777 if (!result || val > result) result = val;
778 }
779 return result.value_or(source_t {});
780 }
781
782 template<typename source_t>
783 requires xtd::numeric<source_t>
784 [[nodiscard]] static auto max(const ienumerable<source_t>& source) {
785 auto result = std::optional<source_t> {};
786 for (const auto& item : source)
787 if (!result || item > result) result = item;
788 return result.value_or(source_t {});
789 }
790
791 template<typename result_t, typename source_t>
792 requires xtd::numeric<result_t>
793 [[nodiscard]] static auto min(const ienumerable<source_t>& source, auto&& selector) {
794 auto result = std::optional<result_t> {};
795 for (const auto& item : source) {
796 auto val = selector(item);
797 if (!result || val < result) result = val;
798 }
799 return result.value_or(result_t {});
800 }
801
802 template<typename source_t>
803 requires xtd::numeric<source_t>
804 [[nodiscard]] static auto min(const ienumerable<source_t>& source, auto&& selector) {
805 auto result = std::optional<source_t> {};
806 for (const auto& item : source) {
807 auto val = selector(item);
808 if (!result || val < result) result = val;
809 }
810 return result.value_or(source_t {});
811 }
812
813 template<typename source_t>
814 requires xtd::numeric<source_t>
815 [[nodiscard]] static auto min(const ienumerable<source_t>& source) {
816 auto result = std::optional<source_t> {};
817 for (const auto& item : source)
818 if (!result || item < result) result = item;
819 return result.value_or(source_t {});
820 }
821
825 template<typename source_t>
826 [[nodiscard]] static auto order(const ienumerable<source_t>& source) {
828 }
829
833 template<typename source_t>
834 [[nodiscard]] static auto order(const ienumerable<source_t>& source, const xtd::collections::generic::icomparer<source_t>& comparer) {
835 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
836 for (const auto& item : source)
837 result.items.push_back(item);
838 std::sort(result.items.begin(), result.items.end(), xtd::collections::generic::helpers::lesser<source_t>(comparer));
839 return result;
840 }
841
848 template<typename key_t, typename source_t>
849 [[nodiscard]] static auto order_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
850 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
851 for (const auto& item : source)
852 result.items.push_back(item);
853 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);});
854 return result;
855 }
856
863 template<typename source_t>
864 [[nodiscard]] static auto order_by(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
865 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
866 for (const auto& item : source)
867 result.items.push_back(item);
868 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);});
869 return result;
870 }
871
878 template<typename key_t, typename source_t>
879 [[nodiscard]] static auto order_by_descending(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
880 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
881 for (const auto& item : source)
882 result.items.push_back(item);
883 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);});
884 return result;
885 }
886
893 template<typename source_t>
894 [[nodiscard]] static auto order_by_descending(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
895 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
896 for (const auto& item : source)
897 result.items.push_back(item);
898 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);});
899 return result;
900 }
901
909 template<typename type_t>
910 [[nodiscard]] static auto range(type_t count) {
911 auto step = type_t {};
912 return range(type_t {}, count, ++step);
913 }
914
922 template<typename type_t>
923 [[nodiscard]] static auto range(type_t start, type_t count) {
924 auto step = type_t {};
925 return range(start, count, ++step);
926 }
927
933 template<typename type_t>
934 [[nodiscard]] static auto range(type_t start, type_t count, type_t step) {
937
938 auto result = __opaque_xtd_linq_enumerable_collection__<type_t> {};
939 for (auto index = type_t {}; index < count; ++index)
940 result.items.push_back(start + (index * step));
941 return result;
942 }
943
953 template<typename result_t, typename source_t>
954 [[nodiscard]] static auto select(const ienumerable<source_t>& source, auto&& selector) {
955 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
956 auto index = xtd::usize {0};
957 for (const auto& item : source)
958 result.items.push_back(invoke_selector_wtih_optional_index(selector, item, index++));
959 return result;
960 }
961
970 template<typename source_t>
971 [[nodiscard]] static auto select(const ienumerable<source_t>& source, auto&& selector) {
972 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
973 auto index = xtd::usize {0};
974 for (const auto& item : source)
975 result.items.push_back(invoke_selector_wtih_optional_index(selector, item, index++));
976 return result;
977 }
978
987 template<typename source_t>
988 [[nodiscard]] static auto to_array(const ienumerable<source_t>& source) noexcept; // Defined in include/xtd/array.hpp
989
998 template<typename source_t>
999 [[nodiscard]] static auto to_list(const ienumerable<source_t>& source) noexcept; // Defined in include/xtd/collections/generic/list.hpp
1000
1012 template<typename source_t>
1013 [[nodiscard]] static auto where(const ienumerable<source_t>& source, auto&& predicate) {
1014 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
1015 auto index = xtd::usize {0};
1016 for (const auto& item : source)
1017 if (invoke_predicate_wtih_optional_index(predicate, item, index++)) result.items.push_back(item);
1018 return result;
1019 }
1020
1021
1022 private:
1023 template <typename predicate_t, typename source_t>
1024 static constexpr bool invoke_predicate_wtih_optional_index(predicate_t&& predicate, source_t&& value, xtd::usize index) {
1025 if constexpr (requires { predicate(value, index); }) return predicate(value, index);
1026 else return predicate(value);
1027 }
1028
1029 template <typename selector_t, typename source_t>
1030 static auto invoke_selector_wtih_optional_index(selector_t&& selector, source_t&& value, xtd::usize index) {
1031 if constexpr (requires { selector(value, index); }) return selector(value, index);
1032 else return selector(value);
1033 }
1034 };
1035 }
1036}
1037
1039#include "from.hpp"
Contains xtd::collections::generic::helpers::allocator alias.
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
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
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
Defines methods to support the comparison of objects for equality.
Definition iequality_comparer.hpp:34
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
static 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:68
static auto count(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept -> xtd::usize
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:522
static auto average(const ienumerable< double > &source) -> double
Computes the average of a sequence of double values.
static auto count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:561
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:587
static auto append(const ienumerable< source_t > &source, const source_t &element) noexcept
Appends a value to the end of the sequence.
Definition enumerable.hpp:235
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:894
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:719
static auto aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const source_t &)> &func) -> accumulate_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:141
static auto any(const ienumerable< source_t > &source) noexcept -> bool
Determines whether a sequence contains any elements.
Definition enumerable.hpp:208
static auto average(const ienumerable< xtd::optional< xtd::int32 > > &source) noexcept -> xtd::optional< double >
Computes the average of a sequence of optional xtd::int32 values.
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:83
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:667
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:732
typename xtd::collections::generic::enumerator< type_t > enumerator
Represents the enumerator value type.
Definition enumerable.hpp:75
static auto cast(const ienumerable< source_t > &source) noexcept
Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
static auto from(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:745
static auto average(const ienumerable< xtd::optional< xtd::int64 > > &source) noexcept -> xtd::optional< double >
Computes the average of a sequence of optional xtd::int64 values.
static auto as_enumerable(input_iterator_t first, input_iterator_t last) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:337
static auto average(const ienumerable< xtd::optional< float > > &source) noexcept -> xtd::optional< float >
Computes the average of a sequence of optional float values.
static auto aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func, const std::function< source_t(const source_t &)> &result_selector) -> source_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:158
static auto to_list(const ienumerable< source_t > &source) noexcept
Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <ty...
static const auto & as_enumerable(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:292
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:79
static auto count(const ienumerable< source_t > &source) noexcept -> xtd::usize
Returns the number of elements in a sequence.
Definition enumerable.hpp:506
static auto aggregate(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, const source_t &)> &func) -> source_t
Applies an accumulator function over a sequence.
Definition enumerable.hpp:106
static auto distinct(const ienumerable< source_t > &source, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept
Returns distinct elements from a sequence by using a specified xtd::collections::generic::iequality_c...
Definition enumerable.hpp:625
static auto range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:923
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:87
static auto average(const ienumerable< xtd::optional< double > > &source) noexcept -> xtd::optional< double >
Computes the average of a sequence of optional double values.
static auto average(const ienumerable< float > &source) -> float
Computes the average of a sequence of float values.
static auto average(const ienumerable< xtd::optional< xtd::decimal > > &source) noexcept -> xtd::optional< xtd::decimal >
Computes the average of a sequence of optional xtd::decimal values.
static auto as_enumerable(input_iterator_t iterator, xtd::usize length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:353
static auto all(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) -> bool
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:193
static auto select(const ienumerable< source_t > &source, auto &&selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:971
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:640
static auto average(const ienumerable< xtd::decimal > &source) -> xtd::decimal
Computes the average of a sequence of xtd::decimal values.
static auto to_array(const ienumerable< source_t > &source) noexcept
Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
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:834
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:659
static auto aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const source_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector) -> result_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:177
static auto from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:692
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:600
static auto average(const ienumerable< xtd::int32 > &source) -> double
Computes the average of a sequence of xtd::int32 values.
static auto concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:464
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:934
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:879
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:612
static auto contains(const ienumerable< source_t > &source, const source_t &value) noexcept -> bool
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:479
static auto as_enumerable(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:365
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:864
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:849
static auto aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func) -> source_t
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:124
static auto order(const ienumerable< source_t > &source)
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:826
static auto from(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:704
static auto contains(const ienumerable< source_t > &source, const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept -> bool
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:492
static auto where(const ienumerable< source_t > &source, auto &&predicate)
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:1013
static auto count_by(const ienumerable< source_t > &source, const std::function< key_t(const source_t &)> &key_selector) noexcept
Returns the count of elements in the source sequence grouped by key.
Definition enumerable.hpp:546
xtd::collections::generic::key_value_pair< key_t, value_t > key_value_pair
Represents the key value pair value type.
Definition enumerable.hpp:91
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:650
static auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:910
static auto as_enumerable(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:303
static auto any(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) -> bool
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:220
static auto average(const ienumerable< xtd::int64 > &source) -> double
Computes the average of a sequence of xtd::int64 values.
static auto chunk(const ienumerable< source_t > &source, xtd::usize size)
Splits the elements of a sequence into chunks of size at most size.
static auto count(const ienumerable< source_t > &source, const source_t &value) noexcept -> xtd::usize
Returns the number of elements with the specified value.
Definition enumerable.hpp:532
static auto select(const ienumerable< source_t > &source, auto &&selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:954
static const auto & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:680
static auto as_enumerable(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:317
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 numeric.hpp:12
Contains xtd::decimal type.
Contains xtd::collections::generic::equality_comparer <type_t> class.
Contains xtd::linq::from methods.
Contains xtd::collections::generic::comparer <type_t> class.
Contains xtd::collections::generic::enumerator <type_t> class.
xtd::delegate< result_t(arguments_t... arguments)> func
Represents a delegate that has variables parameters and returns a value of the type specified by the ...
Definition func.hpp:27
@ argument
The argument is not valid.
Definition exception_case.hpp:31
@ argument_out_of_range
The argument is out of range.
Definition exception_case.hpp:35
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp: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
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::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:51
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:71
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:249
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:274
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:213
constexpr auto size() const noexcept -> size_type
Returns the number of elements.
Definition read_only_span.hpp:217
Contains xtd::numeric concept.
Contains xtd::optional type.
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.