6#include "../../helpers/throw_helper.hpp"
7#include "../../new_ptr.hpp"
8#include "../../static.hpp"
13 namespace collections {
17 template <
class type_t = std::
nullptr_t>
37 template<
class type_t>
62 const type_t&
current()
const override {
return enumerator_->current();}
71 bool move_next()
override {
return enumerator_->move_next();}
76 void reset()
override {enumerator_->reset();}
113 template <
class collection_t,
class vertion_t = std::
nullptr_t>
114 static auto create(
const collection_t& items,
const vertion_t* current_version =
nullptr) noexcept {
115 using value_type =
typename collection_t::value_type;
116 using const_iterator =
typename collection_t::const_iterator;
117 struct internal_enumerator :
public ienumerator<value_type> {
119 explicit internal_enumerator(
const collection_t& items,
const vertion_t* current_version) : items_(items), version_(current_version ? *current_version : vertion_t {}), current_version_(current_version) {}
121 const value_type& current()
const override {
123 if (iterator_ != items_.cend())
return *iterator_;
124 static auto default_value_type = value_type {};
125 return default_value_type;
128 bool move_next()
override {
130 if (!reset_)
return ++iterator_ != items_.cend();
132 iterator_ = items_.cbegin();
133 return iterator_ != items_.cend();
136 void reset()
override {
138 version_ = current_version_ ? *current_version_ : vertion_t {};
139 iterator_ = items_.cend();
144 const collection_t& items_;
145 const_iterator iterator_ = items_.cend();
146 vertion_t version_ = vertion_t {};
147 const vertion_t* current_version_ =
nullptr;
Supports a simple iteration over a generic collection.
Definition ienumerator.hpp:58
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
The xtd::shared_ptr_object is a shared pointer as std::shared_ptr.
Definition shared_ptr_object.hpp:30
generic::enumerator< xtd::any_object > enumerator
Supports a simple iteration over a non-generic collection.
Definition enumerator.hpp:28
@ invalid_operation
The operation is not valid.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
Contains xtd::collections::ienumerator alias.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
static auto create(const collection_t &items, const vertion_t *current_version=nullptr) noexcept
Create an enumerator from specified collection and version.
Definition enumerator.hpp:114
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
enumerator(ptr< ienumerator< type_t > > enumerator)
Initializes a new instance of the xtd::collections::generic::enumerator <type_t> class with specified...
Definition enumerator.hpp:46
enumerator()=default
Initializes a new instance of the xtd::collections::generic::enumerator <type_t> class.
bool move_next() override
Advances the enumerator to the next element of the collection.
Definition enumerator.hpp:71
void reset() override
Sets the enumerator to its initial position, which is before the first element in the collection.
Definition enumerator.hpp:76