#include <xtd/collections/array_list>
#include <xtd/array>
#include <xtd/console>
#include <xtd/not_implemented_exception>
#include <xtd/startup>
class program {
public:
static auto main() -> void {
auto test = simple_list();
console::write_line("Populate the List");
test.add("one");
test.add("two");
test.add("three");
test.add("four");
test.add("five");
test.add("six");
test.add("seven");
test.add("eight");
test.print_contents();
console::write_line();
console::write_line("Remove elements from the list");
test.remove("six");
test.remove("eight");
test.print_contents();
console::write_line();
console::write_line("Add an element to the end of the list");
test.add("nine");
test.print_contents();
console::write_line();
console::write_line("Insert an element into the middle of the list");
test.insert(4, "number");
test.print_contents();
console::write_line();
console::write_line("Check for specific elements in the list");
console::write_line("List contains \"three\": {}", test.contains("three"));
console::write_line("List contains \"ten\": {}", test.contains("ten"));
}
private:
public:
inline static constexpr size npos = ilist::npos;
simple_list() {count_ = 0;}
void print_contents() const noexcept {
console::write_line("List has a capacity of {} and currently has {} elements.", contents_.size(), count_);
console::write("List contents:");
for (auto i = 0_z; i < count(); ++i)
console::write(" {}", contents_[i]);
console::write_line();
}
bool is_fixed_size() const noexcept override {return true;}
bool is_read_only() const noexcept override {return false;}
if (count_ < contents_.size()) {
contents_[count_] = value;
count_++;
}
}
void clear() override {
count_ = 0;
}
bool contains(
const any_object& value)
const noexcept override {
for (auto i = 0_z; i < count(); ++i)
if (contents_[i] == value) return true;
return false;
}
for (auto i = 0_z; i < count(); ++i)
if (contents_[i] == value) return i;
return npos;
}
if (count_ + 1 <= contents_.size() && index < count()) {
++count_;
for (
size i = count() - 1; i > index; --i)
contents_[i] = contents_[i - 1];
contents_[index] = value;
}
}
auto index = index_of(value);
remove_at(index);
return index != npos;
}
void remove_at(
size index)
override {
if (index < count()) {
for (
size i = index; i < count() - 1; ++i)
contents_[i] = contents_[i + 1];
--count_;
}
}
return contents_[index];
}
return contents_[index];
}
size count()
const noexcept override {
return count_;}
bool is_synchronized() const noexcept override {return false;}
const object& sync_root() const noexcept override {return *this;}
for (auto i = 0_z; i < count(); ++i)
array[index + i] = contents_[i];
}
}
};
};
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.h:28
Supports a simple iteration over a generic collection.
Definition enumerator.h:31
Represents a collection of objects that can be individually accessed by index.
Definition ilist.h:41
The exception that is thrown when a requested method or operation is not implemented.
Definition not_implemented_exception.h:19
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:42
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
size_t size
Represents a size of any object in bytes.
Definition size.h:23
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
std::vector< type_t > array
Definition __array_definition.h:18