xtd 0.2.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 "../optional.hpp"
25#include "../size.hpp"
26#include "../static.hpp"
27#include <algorithm>
28#include <bitset>
29#include <functional>
30#include <queue>
31#include <stack>
32
34template<class type_t>
35struct __opaque_xtd_linq_enumerable_collection__;
36template<class type_t, class param_t>
37struct __opaque_xtd_linq_lazy_enumerable__;
39
41namespace xtd {
43 namespace collections::generic {
44 template<class type_t>
45 class ienumerable;
46 }
48
50 namespace linq {
51
68 public:
70
73 template<class type_t>
75
77 template<class type_t>
79
81 template<class type_t>
83
85 template<class type_t>
87
89 template<class key_t, class value_t>
92
94
104 template<class source_t>
105 inline static source_t aggregate(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, const source_t&)>& func) {
106 auto nb = 0;
107 auto aggregated = source_t {};
108 for (const auto& item : source)
109 if (nb++ == 0) aggregated = item;
110 else aggregated = func(aggregated, item);
111 return aggregated;
112 }
113
122 template<class source_t>
123 inline static source_t aggregate(const ienumerable<source_t>& source, const source_t& seed, const std::function<source_t(const source_t&, const source_t&)>& func) {
124 auto aggregated = seed;
125 for (const auto& item : source)
126 aggregated = func(aggregated, item);
127 return aggregated;
128 }
129
139 template<class accumulate_t, class source_t>
140 inline static accumulate_t aggregate(const ienumerable<source_t>& source, const accumulate_t& seed, const std::function<accumulate_t(const accumulate_t&, const source_t&)>& func) {
141 auto aggregated = seed;
142 for (const auto& item : source)
143 aggregated = func(aggregated, item);
144 return aggregated;
145 }
146
156 template<class source_t>
157 inline static source_t 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) {
158 auto aggregated = seed;
159 for (const auto& item : source)
160 aggregated = func(aggregated, item);
161 return result_selector(aggregated);
162 }
163
175 template<class result_t, class accumulate_t, class source_t>
176 inline static result_t 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) {
177 auto aggregated = seed;
178 for (const auto& item : source)
179 aggregated = func(aggregated, item);
180 return result_selector(aggregated);
181 }
182
191 template<class source_t>
192 inline static bool all(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
193 for (const auto& item : source)
194 if (!predicate(item)) return false;
195 return true;
196 }
197
206 template<class source_t>
207 inline static bool any(const ienumerable<source_t>& source) noexcept {
208 return source.begin() != source.end();
209 }
210
218 template<class source_t>
219 inline static bool any(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
220 for (const auto& item : source)
221 if (predicate(item)) return true;
222 return false;
223 }
224
233 template<class source_t>
234 inline static auto append(const ienumerable<source_t>& source, const source_t& element) noexcept {
235 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
236 for (const auto& item : source)
237 result.items.push_back(item);
238 result.items.push_back(element);
239 return result;
240 }
241
242 /*
243 template<class source_t>
244 inline static auto append(const ienumerable<source_t>& source, const source_t& element) noexcept {
245 using param_type = std::tuple<source_t, enumerator<source_t>, source_t, bool>;
246 auto result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {};
247
248 result = __opaque_xtd_linq_lazy_enumerable__<source_t, param_type> {
249 std::make_tuple(source_t {}, source.get_enumerator(), element, false),
250 [](param_type& params) {
251 auto& result = std::get<0>(params);
252 auto& source_enumerator = std::get<1>(params);
253 const auto& element = std::get<2>(params);
254 auto& appended = std::get<3>(params);
255
256 if (source_enumerator.move_next()) {
257 result = source_enumerator.current();
258 return true;
259 }
260
261 if (!appended) {
262 appended = true;
263 result = element;
264 return true;
265 }
266
267 return false;
268 },
269 [](param_type& params) {
270 auto& result = std::get<0>(params);
271 auto& source_enumerator = std::get<1>(params);
272 auto& appended = std::get<3>(params);
273
274 result = source_t {};
275 source_enumerator.reset();
276 appended = false;
277 }
278 };
279
280 return result;
281 }*/
282
290 template<class source_t>
291 inline static const auto& as_enumerable(const ienumerable<source_t>& source) noexcept {
292 return source;
293 }
294
301 template<class source_t>
302 inline static auto as_enumerable(std::initializer_list<source_t> source) noexcept {
303 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
304 for (const auto& item : source)
305 result.items.push_back(item);
306 return result;
307 }
308
315 template<class collection_t>
316 inline static auto as_enumerable(collection_t&& source) noexcept {
317 #if defined(__xtd__cpp_lib_ranges)
318 using source_t = std::ranges::range_value_t<collection_t>;
319 #else
320 using source_t = typename collection_t::value_type;
321 #endif
322 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
323 for (auto&& item : source)
324 result.items.push_back(item);
325 return result;
326 }
327
335 template<class input_iterator_t>
336 inline static auto as_enumerable(input_iterator_t first, input_iterator_t last) noexcept {
337 using source_t = typename std::decay<decltype(*first)>::type;
338 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
339 for (auto iterator = first; iterator != last; ++iterator)
340 result.items.push_back(*iterator);
341 return result;
342 }
343
351 template<class input_iterator_t>
352 inline static auto as_enumerable(input_iterator_t iterator, size_t length) noexcept {
353 return as_enumerable(iterator, iterator + length);
354 }
355
363 template<class source_t, size_t length>
364 inline static auto as_enumerable(const source_t (&array)[length]) noexcept {
365 return as_enumerable(array, array + length);
366 }
367
369 template<xtd::size size_>
370 inline static auto as_enumerable(std::bitset<size_> source); // defined in xtd/collections/bit_array.hpp
371 template<class source_t, class container_t>
372 inline static auto as_enumerable(std::queue<source_t, container_t> source) noexcept {
373 struct std_queue : public std::queue<source_t> {
374 std_queue(const std::queue<source_t>& queue) : ptr {reinterpret_cast<const std_queue*>(&queue)} {}
375 auto begin() const {return ptr->c.begin();}
376 auto end() const {return ptr->c.end();}
377 const std_queue* ptr;
378 };
379 auto items = std_queue {source};
380 return as_enumerable(items.begin(), items.end());
381 }
382 template<class source_t, class container_t>
383 inline static auto as_enumerable(std::priority_queue<source_t, container_t> source) noexcept {
384 struct std_priority_queue : public std::priority_queue<source_t> {
385 std_priority_queue(const std::priority_queue<source_t>& queue) : ptr {reinterpret_cast<const std_priority_queue*>(&queue)} {}
386 auto begin() const {return ptr->c.begin();}
387 auto end() const {return ptr->c.end();}
388 const std_priority_queue* ptr;
389 };
390 auto items = std_priority_queue {source};
391 return as_enumerable(items.begin(), items.end());
392 }
393 template<class source_t, class container_t>
394 inline static auto as_enumerable(std::stack<source_t, container_t> source) noexcept {
395 struct std_stack : public std::stack<source_t> {
396 std_stack(const std::stack<source_t>& stack) : ptr {reinterpret_cast<const std_stack*>(&stack)} {}
397 auto begin() const {return ptr->c.begin();}
398 auto end() const {return ptr->c.end();}
399 const std_stack* ptr;
400 };
401 auto items = std_stack {source};
402 return as_enumerable(items.begin(), items.end());
403 }
405
415 static double average(const ienumerable<double>& source);
420 static float average(const ienumerable<float>& source);
425 static double average(const ienumerable<xtd::int32>& source);
430 static double average(const ienumerable<xtd::int64>& source);
431
452
460 template<class result_t, class source_t>
461 inline static auto cast(const ienumerable<source_t>& source) noexcept; // Defined include/xtd/as.hpp
462
469 template<class source_t>
470 inline static auto chunk(const ienumerable<source_t>& source, xtd::size size); // Defined in include/xtd/array.hpp
471
477 template<class source_t>
478 inline static auto concat(const ienumerable<source_t>& first, const ienumerable<source_t>& second) noexcept {
479 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
480 for (const auto& item : first)
481 result.items.push_back(item);
482 for (const auto& item : second)
483 result.items.push_back(item);
484 return result;
485 }
486
492 template<class source_t>
493 inline static bool contains(const ienumerable<source_t>& source, const source_t& value) noexcept {
494 for (const auto& item : source)
495 if (item == value) return true;
496 return false;
497 }
498
505 template<class source_t>
506 inline static bool contains(const ienumerable<source_t>& source, const source_t& value, const xtd::collections::generic::iequality_comparer<source_t>& comparer) noexcept {
507 for (const auto& item : source)
508 if (comparer.equals(item, value)) return true;
509 return false;
510 }
511
519 template<class source_t>
520 inline static xtd::size count(const ienumerable<source_t>& source) noexcept {
521 auto count = xtd::size {0};
522 auto enumerator = source.get_enumerator();
523 while (enumerator.move_next()) ++count;
524 return count;
525 }
526
535 template<class source_t>
536 inline static xtd::size count(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept {
537 return where<source_t>(source, predicate).count();
538 }
539
545 template<class source_t>
546 inline static xtd::size count(const ienumerable<source_t>& source, const source_t& value) noexcept {
547 return count<source_t>(source, [value](const source_t& item) -> bool {return item == value;});
548 }
549
559 template<class key_t, class source_t>
560 inline static auto count_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) noexcept {
562 }
563
574 template<class key_t, class source_t>
575 inline 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 {
576 auto result = __opaque_xtd_linq_enumerable_collection__<key_value_pair<key_t, xtd::size>> {};
577 auto keys = list<key_t> {};
578 auto enumerator = source.get_enumerator();
579 while (enumerator.move_next()) {
580 auto key = key_selector(enumerator.current());
581 auto index = size_t {0};
582 for (; index < keys.count(); ++index)
583 if (key_comparer.equals(keys[index], key)) break;
584 if (index < keys.count()) result.items[index] = {key, result.items[index].value() + 1};
585 else {
586 keys.add(key);
587 result.items.push_back({key, 1});
588 }
589 }
590 return result;
591 }
592
600 template<class source_t>
601 inline static auto default_if_empty(const ienumerable<source_t>& source) noexcept {
602 return default_if_empty(source, source_t {});
603 }
604
613 template<class source_t>
614 inline static auto default_if_empty(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
615 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
616 if (!any(source)) result.items.push_back(default_value);
617 else for (const auto& item : source)
618 result.items.push_back(item);
619 return result;
620 }
621
625 template<class source_t>
626 inline static auto distinct(const ienumerable<source_t>& source) noexcept {
627 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
628 for (const auto& item : source)
629 if (!contains(result, item))
630 result.items.push_back(item);
631 return result;
632 }
633
638 template<class source_t>
639 inline static auto distinct(const ienumerable<source_t>& source, const xtd::collections::generic::iequality_comparer<source_t>& comparer) noexcept {
640 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
641 for (const auto& item : source)
642 if (!contains(result, item, comparer))
643 result.items.push_back(item);
644 return result;
645 }
646
653 template<class source_t>
654 inline static source_t first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate, const source_t& default_value) noexcept {
655 const auto& result = where(source, predicate);
656 return any(result) ? *result.begin() : default_value;
657 }
658
663 template<class source_t>
664 inline static source_t first_or_default(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) noexcept {
665 return first_or_default(source, predicate, source_t {});
666 }
667
672 template<class source_t>
673 inline static source_t first_or_default(const ienumerable<source_t>& source, const source_t& default_value) noexcept {
674 return any(source) ? *source.begin() : default_value;
675 }
676
680 template<class source_t>
681 inline static source_t first_or_default(const ienumerable<source_t>& source) noexcept {
682 return first_or_default(source, source_t {});
683 }
684
693 template<class source_t>
694 inline static const auto& from(const ienumerable<source_t>& source) noexcept {
695 return as_enumerable(source);
696 }
697
705 template<class source_t>
706 inline static auto from(std::initializer_list<source_t> source) noexcept {
707 return as_enumerable(source);
708 }
709
717 template<class collection_t>
718 inline static auto from(collection_t&& source) noexcept {
719 return as_enumerable(source);
720 }
721
732 template<class input_iterator_t>
733 inline static auto from(input_iterator_t first, input_iterator_t last) noexcept {
734 return as_enumerable(first, last);
735 }
736
745 template<class input_iterator_t>
746 inline static auto from(input_iterator_t iterator, size_t length) noexcept {
747 return as_enumerable(iterator, iterator + length);
748 }
749
758 template<class source_t, size_t length>
759 inline static auto from(const source_t (&array)[length]) noexcept {
760 return as_enumerable(array, array + length);
761 }
762
764 template<class source_t, class container_t>
765 inline static auto from(std::queue<source_t, container_t> source) noexcept {
766 return as_enumerable(source);
767 }
768 template<class source_t, class container_t>
769 inline static auto from(std::stack<source_t, container_t> source) noexcept {
770 return as_enumerable(source);
771 }
773
777 template<class source_t>
778 inline static auto order(const ienumerable<source_t>& source) {
780 }
781
785 template<class source_t>
786 inline static auto order(const ienumerable<source_t>& source, const xtd::collections::generic::icomparer<source_t>& comparer) {
787 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
788 result.items = xtd::collections::generic::helpers::raw_array<source_t> {source.begin(), source.end()};
789 std::sort(result.items.begin(), result.items.end(), xtd::collections::generic::helpers::lesser<source_t>(comparer));
790 return result;
791 }
792
799 template<class key_t, class source_t>
800 inline static auto order_by(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
801 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
802 result.items = std::vector<source_t> {source.begin(), source.end()};
803 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);});
804 return result;
805 }
806
813 template<class source_t>
814 inline static auto order_by(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
815 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
816 result.items = std::vector<source_t> {source.begin(), source.end()};
817 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);});
818 return result;
819 }
820
827 template<class key_t, class source_t>
828 inline static auto order_by_descending(const ienumerable<source_t>& source, const std::function<key_t(const source_t&)>& key_selector) {
829 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
830 result.items = std::vector<source_t> {source.begin(), source.end()};
831 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);});
832 return result;
833 }
834
841 template<class source_t>
842 inline static auto order_by_descending(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& key_selector) {
843 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
844 result.items = std::vector<source_t> {source.begin(), source.end()};
845 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);});
846 return result;
847 }
848
856 template<class type_t>
857 inline static auto range(type_t count) {
858 auto step = type_t {};
859 return range(type_t {}, count, ++step);
860 }
861
869 template<class type_t>
870 inline static auto range(type_t start, type_t count) {
871 auto step = type_t {};
872 return range(start, count, ++step);
873 }
874
880 template<class type_t>
881 inline static auto range(type_t start, type_t count, type_t step) {
882 using param_type = std::tuple<type_t, type_t, type_t, type_t>;
883 auto numbers = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {};
884
887
888 numbers = __opaque_xtd_linq_lazy_enumerable__<type_t, param_type> {
889 std::make_tuple(start, count, step, type_t {}),
890 [](param_type & params) {
891 auto& result = std::get<0>(params);
892 auto& count = std::get<1>(params);
893 auto& step = std::get<2>(params);
894 auto& index = std::get<3>(params);
895 if (index != 0) result += step;
896 return index++ < count;
897 },
898 [start, count, step](param_type & params) {
899 params = std::make_tuple(start, count, step, type_t {});
900 }
901 };
902 return numbers;
903 }
904
914 template<class result_t, class source_t>
915 inline static auto select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&)>& selector) {
916 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
917 for (const auto& item : source)
918 result.items.push_back(selector(item));
919 return result;
920 }
921
929 template<class source_t>
930 inline static auto select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&)>& selector) {
931 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
932 for (const auto& item : source)
933 result.items.push_back(selector(item));
934 return result;
935 }
936
945 template<class result_t, class source_t>
946 inline static auto select(const ienumerable<source_t>& source, const std::function<result_t(const source_t&, xtd::size)>& selector) {
947 auto result = __opaque_xtd_linq_enumerable_collection__<result_t> {};
948 auto index = xtd::size {0};
949 for (const auto& item : source)
950 result.items.push_back(selector(item, index++));
951 return result;
952 }
953
961 template<class source_t>
962 inline static auto select(const ienumerable<source_t>& source, const std::function<source_t(const source_t&, xtd::size)>& selector) {
963 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
964 auto index = xtd::size {0};
965 for (const auto& item : source)
966 result.items.push_back(selector(item, index++));
967 return result;
968 }
969
978 template<class source_t>
979 inline static auto to_array(const ienumerable<source_t>& source) noexcept; // Defined in include/xtd/array.hpp
980
989 template<class source_t>
990 inline static auto to_list(const ienumerable<source_t>& source) noexcept; // Defined in include/xtd/collections/generic/list.hpp
991
1000 template<class source_t>
1001 inline static auto where(const ienumerable<source_t>& source, const std::function<bool(const source_t&)>& predicate) {
1002 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
1003 for (const auto& item : source)
1004 if (predicate(item)) result.items.push_back(item);
1005 return result;
1006 }
1007
1015 template<class source_t>
1016 inline static auto where(const ienumerable<source_t>& source, const std::function<bool(const source_t&, xtd::size)>& predicate) {
1017 auto result = __opaque_xtd_linq_enumerable_collection__<source_t> {};
1018 auto index = xtd::size {0};
1019 for (const auto& item : source)
1020 if (predicate(item, index++)) result.items.push_back(item);
1021 return result;
1022 }
1023
1024 };
1025 }
1026}
1027
1029#include "from.hpp"
Contains xtd::array definitions.
Contains xtd::collections::generic::key_value_pair definitions.
Contains xtd::collections::generic::list definitions.
Contains __xtd_std_version definitions.
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 void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Provides a set of static methods for querying objects that implement ienumerable <type_t>.
Definition enumerable.hpp:67
static auto select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:915
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:575
static xtd::decimal average(const ienumerable< xtd::decimal > &source)
Computes the average of a sequence of xtd::decimal 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:601
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:234
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:842
static auto as_enumerable(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:352
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:733
static xtd::optional< float > average(const ienumerable< xtd::optional< float > > &source) noexcept
Computes the average of a sequence of optional float values.
static bool all(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition enumerable.hpp:192
typename xtd::collections::generic::ienumerable< type_t > ienumerable
Represents the ienumerable value type.
Definition enumerable.hpp:82
static xtd::optional< xtd::decimal > average(const ienumerable< xtd::optional< xtd::decimal > > &source) noexcept
Computes the average of a sequence of optional xtd::decimal values.
typename xtd::collections::generic::enumerator< type_t > enumerator
Represents the enumerator value type.
Definition enumerable.hpp:74
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:759
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:336
static result_t 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)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:176
static double average(const ienumerable< xtd::int32 > &source)
Computes the average of a sequence of xtd::int32 values.
static bool any(const ienumerable< source_t > &source) noexcept
Determines whether a sequence contains any elements.
Definition enumerable.hpp:207
static bool any(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Determines whether any element of a sequence satisfies a condition.
Definition enumerable.hpp:219
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 source_t 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)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:157
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:291
static bool contains(const ienumerable< source_t > &source, const source_t &value, const xtd::collections::generic::iequality_comparer< source_t > &comparer) noexcept
Determines whether a sequence contains a specified element by using a specified equality comparer.
Definition enumerable.hpp:506
typename xtd::collections::generic::iequality_comparer< type_t > iequality_comparer
Represents the ienumerable value type.
Definition enumerable.hpp:78
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:639
static auto range(type_t start, type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:870
typename xtd::collections::generic::list< type_t > list
Represents the list value type.
Definition enumerable.hpp:86
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int32 > > &source) noexcept
Computes the average of a sequence of optional xtd::int32 values.
static auto from(input_iterator_t iterator, size_t length) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:746
static auto select(const ienumerable< source_t > &source, const std::function< result_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:946
static auto chunk(const ienumerable< source_t > &source, xtd::size size)
Splits the elements of a sequence into chunks of size at most size.
static double average(const ienumerable< double > &source)
Computes the average of a sequence of double values.
static accumulate_t aggregate(const ienumerable< source_t > &source, const accumulate_t &seed, const std::function< accumulate_t(const accumulate_t &, const source_t &)> &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:140
static bool contains(const ienumerable< source_t > &source, const source_t &value) noexcept
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition enumerable.hpp:493
static double average(const ienumerable< xtd::int64 > &source)
Computes the average of a sequence of xtd::int64 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 where(const ienumerable< source_t > &source, const std::function< bool(const source_t &, xtd::size)> &predicate)
Filters a sequence of values based on a predicate. Each element's index is used in the logic of the p...
Definition enumerable.hpp:1016
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition, or a specified default value if...
Definition enumerable.hpp:654
static auto select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, xtd::size)> &selector)
Projects each element of a sequence into a new form by incorporating the element's index.
Definition enumerable.hpp:962
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:786
static auto from(std::initializer_list< source_t > source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:706
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:614
static source_t first_or_default(const ienumerable< source_t > &source, const source_t &default_value) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:673
static auto select(const ienumerable< source_t > &source, const std::function< source_t(const source_t &)> &selector)
Projects each element of a sequence into a new form.
Definition enumerable.hpp:930
static auto concat(const ienumerable< source_t > &first, const ienumerable< source_t > &second) noexcept
Concatenates two sequences.
Definition enumerable.hpp:478
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:881
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:828
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:626
static auto as_enumerable(const source_t(&array)[length]) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:364
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:814
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:800
static xtd::optional< double > average(const ienumerable< xtd::optional< double > > &source) noexcept
Computes the average of a sequence of optional double values.
static auto order(const ienumerable< source_t > &source)
Sorts the elements of a sequence in ascending order.
Definition enumerable.hpp:778
static float average(const ienumerable< float > &source)
Computes the average of a sequence of float values.
static auto from(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:718
static auto where(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate)
Filters a sequence of values based on a predicate.
Definition enumerable.hpp:1001
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:560
xtd::collections::generic::key_value_pair< key_t, value_t > key_value_pair
Represents the key value pair value type.
Definition enumerable.hpp:90
static xtd::optional< double > average(const ienumerable< xtd::optional< xtd::int64 > > &source) noexcept
Computes the average of a sequence of optional xtd::int64 values.
static source_t aggregate(const ienumerable< source_t > &source, const source_t &seed, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition enumerable.hpp:123
static auto range(type_t count)
Generates a sequence of integral numbers within a specified range.
Definition enumerable.hpp:857
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:302
static xtd::size count(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns a number that represents how many elements in the specified sequence satisfy a condition.
Definition enumerable.hpp:536
static source_t first_or_default(const ienumerable< source_t > &source, const std::function< bool(const source_t &)> &predicate) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:664
static xtd::size count(const ienumerable< source_t > &source) noexcept
Returns the number of elements in a sequence.
Definition enumerable.hpp:520
static const auto & from(const ienumerable< source_t > &source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:694
static source_t first_or_default(const ienumerable< source_t > &source) noexcept
Returns the first element of the sequence that satisfies a condition or a default value if no such el...
Definition enumerable.hpp:681
static source_t aggregate(const ienumerable< source_t > &source, const std::function< source_t(const source_t &, const source_t &)> &func)
Applies an accumulator function over a sequence.
Definition enumerable.hpp:105
static auto as_enumerable(collection_t &&source) noexcept
Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
Definition enumerable.hpp:316
static xtd::size count(const ienumerable< source_t > &source, const source_t &value) noexcept
Returns the number of elements with the specified value.
Definition enumerable.hpp:546
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
Contains xtd::collections::generic::extensions::enumerable <type_t> class.
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.
generic::queue< xtd::any_object > queue
Represents a first-in, first-out collection of objects.
Definition queue.hpp:27
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
std::stack< type_t, container_t > stack
Represents a variable size last-in-first-out (LIFO) collection of instances of the same specified typ...
Definition stack.hpp:34
@ 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:37
std::type_info type
Stores information about a type.
Definition type.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
long double decimal
Represents a decimal-precision floating-point number.
Definition decimal.hpp:23
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::optional< type_t > optional
Represents the optional alias on std::optional.
Definition optional.hpp:25
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:50
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
read_only_span< type_t, count > first() const
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:282
const_iterator end() const
Returns an iterator to the end.
Definition read_only_span.hpp:213
read_only_span< type_t, count > last() const
Obtains a subspan consisting of the last N elements of the sequence.
Definition read_only_span.hpp:307
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
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:38
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::size type.