xtd 1.0.0
Loading...
Searching...
No Matches
xtd::collections::generic::enumerator<> Struct Reference
Inheritance diagram for xtd::collections::generic::enumerator<>:
xtd::object xtd::collections::generic::ienumerator< type_t > xtd::static_object xtd::interface

Definition

Supports a simple iteration over a generic collection.

Definition
template<typename type_t>
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:38
Header
#include <xtd/collections/generic/enumerator>
Namespace
xtd::collections::generic
Library
xtd.core
Remarks
The xtd::collections::generic::enumerator <type_t> class is used to encapsulate an xtd::collections::generic::ienumerator <type_t>.

Public Static Methods

template<typename collection_t, typename version_t = std::nullptr_t>
static auto create (const collection_t &items, const version_t *current_version=nullptr) noexcept
 Create an enumerator from specified collection and version.

Public Constructors

 enumerator ()=default
 Initializes a new instance of the xtd::collections::generic::enumerator <type_t> class.

Public Properties

const type_t & current () const override
 Gets the element in the collection at the current position of the enumerator.

Public Methods

bool move_next () override
 Advances the enumerator to the next element of the collection.
void reset () override
 Sets the enumerator to its initial position, which is before the first element in the collection.

Additional Inherited Members

 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 to_string () const -> xtd::string
 Returns a xtd::string that represents the current object.
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.

Constructor & Destructor Documentation

◆ enumerator()

xtd::collections::generic::enumerator< type_t >::enumerator ( )
default

Initializes a new instance of the xtd::collections::generic::enumerator <type_t> class.

Member Function Documentation

◆ create()

template<typename collection_t, typename version_t = std::nullptr_t>
auto xtd::collections::generic::enumerator<>::create ( const collection_t & items,
const version_t * current_version = nullptr )
inlinestaticnoexcept

Create an enumerator from specified collection and version.

Template Parameters
collection_tThe collection type.
version_tThe collection version type.
Parameters
itemsThe collection to create an enumerator on.
current_versionA pointer on the collection current version.
Returns
The enumerator created.
Examples
The following code shows how to use enumerator<>::create method to create a simple enumerator on any std or xtd collections.
#include <xtd/xtd>
class program {
public:
static auto main() -> void {
auto boxes = box_collection {{10, 20, 30}, {20, 5, 10}, {12, 3, 7}};
auto enumerator = boxes.get_enumerator();
while (enumerator.move_next())
console::write_line(enumerator.current().to_string());
console::write_line();
for (auto box : boxes)
console::write_line(box.to_string());
console::write_line();
for (auto iterator = boxes.begin(); iterator != boxes.end(); ++iterator)
console::write_line(iterator->to_string());
}
struct box : public iequatable<program::box> {
box() = default;
box(int l, int w, int h) : length{l}, width {w}, height {h} {}
int length = 0;
int width = 0;
int height = 0;
bool equals(const program::box& o) const noexcept override {return length == o.length && width == o.width && height == o.height;}
string to_string() const noexcept {return string::format("box [length={}, width={}, height={}]", length, width, height);}
};
class box_collection : public ienumerable<program::box> {
public:
box_collection(const std::initializer_list<program::box>& boxes) : boxes_(boxes) {}
enumerator<program::box> get_enumerator() const override {
return enumerator<>::create(boxes_);
}
private:
list<program::box> boxes_;
};
};
startup_(program::main);
// This code produces the following output :
//
// box [length=10, width=20, height=30]
// box [length=20, width=5, height=10]
// box [length=12, width=3, height=7]
//
// box [length=10, width=20, height=30]
// box [length=20, width=5, height=10]
// box [length=12, width=3, height=7]
//
// box [length=10, width=20, height=30]
// box [length=20, width=5, height=10]
// box [length=12, width=3, height=7]
auto to_string() const noexcept -> xtd::string override
Returns a xtd::string that represents the current object.
generic::ienumerable< xtd::any_object > ienumerable
Exposes an enumerator, which supports a simple iteration over a non-generic collection.
Definition ienumerable.hpp:32
#define startup_(...)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:284
@ h
The H key.
Definition console_key.hpp:102
@ l
The L key.
Definition console_key.hpp:110
@ o
The O key.
Definition console_key.hpp:116
@ w
The W key.
Definition console_key.hpp:132
@ height
Specifies that the height of the control is defined.
Definition bounds_specified.hpp:34
@ width
Specifies that the width of the control is defined.
Definition bounds_specified.hpp:32
virtual auto get_enumerator() const -> xtd::collections::generic::enumerator< type_t >=0
Returns an enumerator that iterates through a collection.
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:342
auto equals(const object &obj) const noexcept -> bool override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:239
constexpr auto length() const noexcept -> size_type
Returns the length of the current read_only_span.
Definition read_only_span.hpp:213
const type_t & current() const override
Gets the element in the collection at the current position of the enumerator.
Definition enumerator.hpp:63
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:72

◆ current()

const type_t & xtd::collections::generic::enumerator< type_t >::current ( ) const
inlinenodiscardoverridevirtual

Gets the element in the collection at the current position of the enumerator.

Returns
The element in the collection at the current position of the enumerator.

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

◆ move_next()

bool xtd::collections::generic::enumerator< type_t >::move_next ( )
inlinenodiscardoverridevirtual

Advances the enumerator to the next element of the collection.

Returns
true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.
Exceptions
xtd::invalid_operation_exceptionThe collection was modified after the enumerator was created.

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

◆ reset()

void xtd::collections::generic::enumerator< type_t >::reset ( )
inlineoverridevirtual

Sets the enumerator to its initial position, which is before the first element in the collection.

Exceptions
xtd::invalid_operation_exceptionThe collection was modified after the enumerator was created.
xtd::not_supported_exceptionThe enumerator does not support being reset.

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


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