xtd 1.0.0
Loading...
Searching...
No Matches
xtd::collections::generic::enumerable_generator< type_t > Class Template Reference
Inheritance diagram for xtd::collections::generic::enumerable_generator< type_t >:
xtd::object xtd::collections::generic::ienumerable< type_t > xtd::interface xtd::collections::generic::ienumerable_abstract xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > xtd::collections::generic::extensions::enumerable< type_t, xtd::collections::generic::ienumerable< type_t > >

Definition

template<typename type_t>
class xtd::collections::generic::enumerable_generator< type_t >

Represents an enumerable generator that supports deferred, lazy iteration over a collection of a specified type using C++20 coroutines.

Definition
template<typename type_t>
class enumerable_generator : public xtd::collections::generic::ienumerable<type_t>
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
Header
#include <xtd/collections/generic/enumerable_generator>
Namespace
xtd::collections::generic
Library
xtd.core
Examples
The following example demonstrates how to create and consume an xtd::collections::generic::enumerable_generator <type_t> using the co_yield keyword and LINQ pipeline operators.
#include <xtd/xtd>
[[nodiscard]] auto odd_numbers_generator(int count = 100, int min_value = 0, int max_value = 100) -> enumerable_generator<int> {
auto rnd = xtd::random {};
for (auto __ : range(count))
co_yield rnd.next(min_value, max_value) | 1;
}
auto main() -> int {
println("Odd numbers : ");
for (auto number : odd_numbers_generator().where(_ % 5 == 0).distinct().order_by(_))
println("{,4}", number);
println("Done!");
}
// This code can produce the following output :
//
// Odd numbers :
// 5
// 25
// 45
// 55
// 65
// 75
// 85
// 95
// Done!
Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet c...
Definition random.hpp:42
virtual auto next() const -> xtd::int32
Returns a nonnegative random number.
Definition number.hpp:11
auto println(FILE *file) -> void
Writes the current line terminator to the file output stream using the specified format information.
Definition println.hpp:14
Remarks
xtd::collections::generic::enumerable_generator <type_t> acts as a stream-like, lazy-evaluated data source. It leverages the C++20 coroutine standard to suspend and resume execution on-demand whenever an element is requested by an iterator or an enumerator.
Because it wraps an ephemeral coroutine frame state, an xtd::collections::generic::enumerable_generator <type_t> is a single-pass stream. It cannot be copied, only moved. Multiple iterators active at the same time on the same generator will advance and consume the exact same underlying state stream.
Tenting to invoke the xtd::collections::generic::ienumerator::reset method on a generator's enumerator will systematically throw an xtd::not_supported_exception, as coroutine execution states cannot be rewound.

Classes

struct  promise_type
 The promise type required by the C++20 coroutine standard to manage the state and lifecycle of the enumerable_generator. More...

Public Methods

xtd::collections::generic::enumerator< type_t > get_enumerator () const override
 Returns an enumerator that iterates through the xtd::collections::generic::enumerable_generator.
auto to_string () const -> xtd::string override
 Returns a xtd::string that represents the current object.

Additional Inherited Members

using value_type
 Represents the xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
using const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
using iterator
 Represents the iterator of enumerable value type.
using const_iterator
 Represents the const iterator of enumerable value type.
using enumerable_type
 Represents the ienumerable enumerable type.
using value_type
 Represents the ienumerable value type.
using ienumerable
 Represents the ienumerable value type.
using list
 Represents the list value type.
 object ()=default
 Create a new instance of the ultimate base class object.
virtual auto equals (const object &obj) const noexcept -> bool
 Determines whether the specified object is equal to the current object.
virtual auto get_hash_code () const noexcept -> xtd::usize
 Serves as a hash function for a particular type.
virtual auto get_type () const noexcept -> type_object
 Gets the type of the current instance.
template<typename object_t>
auto memberwise_clone () const -> xtd::unique_ptr_object< object_t >
 Creates a shallow copy of the current object.
virtual auto begin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cbegin () const -> const_iterator
 Returns an iterator to the first element of the enumerable.
virtual auto cend () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
virtual auto end () const -> const_iterator
 Returns an iterator to the element following the last element of the enumerable.
auto aggregate (func_t &&funcfunc) const -> type_t
 Applies an accumulator function over a sequence.
auto all (predicate_t &&predicatepredicate) const -> bool
 Determines whether all elements of a sequence satisfy a condition.
auto any () const noexcept -> bool
 Determines whether a sequence contains any elements.
auto append (element_t &&element) const noexcept
 Appends a value to the end of the sequence.
auto as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
auto average () const noexcept
 Computes the average of a sequence of value_t values.
auto cast () const noexcept
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
auto chunk (xtd::usize size) const
 Splits the elements of a sequence into chunks of size at most size.
auto concat (second_t &&second) const noexcept
 Concatenates two sequences.
auto contains (type_t &&value) const noexcept -> bool
 Determines whether a sequence contains a specified element by using the default equality comparer.
auto count () const noexcept -> xtd::usize
 Returns the number of elements in current sequence.
auto count_by (key_selector_t &&key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
auto default_if_empty () const noexcept
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
auto distinct () const noexcept
 Returns distinct elements from a sequence by using the default equality comparer to compare values.
auto first_or_default (predicate_t &&predicatepredicate, type_t &&default_value) const noexcept -> type_t
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
auto max (selector_t &&selector) const
auto min (auto &&selector) const
auto order () const
 Sorts the elements of a sequence in ascending order.
auto order_by (const std::function< type_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in ascending order according to a key.
auto order_by_descending (const std::function< key_t(const type_t &)> &key_selector) const
 Sorts the elements of a sequence in descending order according to a key.
auto select (auto &&selector) const
 Projects each element of a sequence into a new form.
auto to_array () const -> xtd::array< type_t >
 Creates a xtd::array <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto to_list () const -> xtd::collections::generic::list< type_t >
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
auto where (auto &&predicatepredicate) const
 Filters a sequence of values based on a predicate.
template<typename object_a_t, typename object_b_t>
static auto equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are considered equal.
template<typename object_a_t, typename object_b_t>
static auto reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
 Determines whether the specified object instances are the same instance.
static auto to_const_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.
static auto to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept -> typename target_collection_t::const_iterator
 Converts source iterator to target iterator.

Member Function Documentation

◆ get_enumerator()

template<typename type_t>
xtd::collections::generic::enumerator< type_t > xtd::collections::generic::enumerable_generator< type_t >::get_enumerator ( ) const
inlineoverridevirtual

Returns an enumerator that iterates through the xtd::collections::generic::enumerable_generator.

Returns
An xtd::collections::generic::enumerator object that can be used to iterate through the xtd::collections::generic::enumerable_generator <type_t>.

Implements xtd::collections::generic::ienumerable< type_t >.

◆ to_string()

template<typename type_t>
auto xtd::collections::generic::enumerable_generator< type_t >::to_string ( ) const -> xtd::string
nodiscardoverridevirtual

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.


The documentation for this class was generated from the following file: