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

Definition

Supports a simple iteration over a generic collection.

Definition
template<class type_t>
#define interface_
This keyword is use to represent an interface.
Definition interface.hpp:58
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<class collection_t, class vertion_t = std::nullptr_t>
static auto create (const collection_t &items, const vertion_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.
 
 enumerator (ptr< ienumerator< type_t > > enumerator)
 Initializes a new instance of the xtd::collections::generic::enumerator <type_t> class with specified enumerator.
 

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

Constructor & Destructor Documentation

◆ enumerator() [1/2]

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

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

◆ enumerator() [2/2]

xtd::collections::generic::enumerator< type_t >::enumerator ( ptr< ienumerator< type_t > > enumerator)
inline

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

Parameters
enumeratorThe xtd::collections::generic::ienumerator <type_t> enumerator to encapsulate.

Member Function Documentation

◆ create()

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

Create an enumerator from specified collection and version.

Template Parameters
collection_tThe collection type.
vertion_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>
using namespace xtd;
using namespace xtd::collections::generic;
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();
for (auto box : boxes)
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]
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
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_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:167
@ 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
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
constexpr size_type length() const noexcept
Returns the length of the current read_only_span.
Definition read_only_span.hpp:229
Represents a boxed object.
Definition box.hpp:57
xtd::string to_string() const noexcept override
Returns a xtd::string that represents the current object.
Definition box.hpp:148
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38
const type_t & current() const override
Gets the element in the collection at the current position of the enumerator.
Definition enumerator.hpp:62
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:71

◆ current()

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

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 ( )
inlineoverridevirtual

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: