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

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
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:40
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.
 

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();
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:
};
};
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]
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.hpp:80
Represents the standard input, output, and error streams for console applications.
Definition console.hpp:36
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
#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:175
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ h
The H key.
@ l
The L key.
@ o
The O key.
@ w
The W key.
@ height
Specifies that the height of the control is defined.
@ width
Specifies that the width of the control is defined.
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 xtd_about_box.hpp:10
Represents a boxed object.
Definition box.hpp:56
const type_t & current() const override
Gets the element in the collection at the current position of the enumerator.
Definition enumerator.hpp:64
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:73

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