3#include <StormByte/exception.hxx>
4#include <StormByte/type_traits.hxx>
25 template <
typename Container>
30 using value_type =
typename Container::value_type;
31 using size_type =
typename Container::size_type;
32 using difference_type =
typename Container::difference_type;
33 using reference =
typename Container::reference;
34 using const_reference =
typename Container::const_reference;
35 using pointer =
typename Container::pointer;
36 using const_pointer =
typename Container::const_pointer;
45 using iterator_category = std::random_access_iterator_tag;
46 using value_type =
typename Container::value_type;
47 using difference_type =
typename Container::difference_type;
48 using pointer =
typename Container::pointer;
49 using reference =
typename Container::reference;
137 typename Container::iterator m_it;
143 Iterator(
typename Container::iterator it): m_it(it) {}
153 using iterator_category = std::random_access_iterator_tag;
154 using value_type =
typename Container::value_type;
155 using difference_type =
typename Container::difference_type;
156 using pointer =
typename Container::const_pointer;
157 using reference =
typename Container::const_reference;
245 typename Container::const_iterator m_it;
251 ConstIterator(
typename Container::const_iterator it): m_it(it) {}
254 using iterator = Iterator;
255 using const_iterator = ConstIterator;
256 using reverse_iterator = std::reverse_iterator<iterator>;
257 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
359 reverse_iterator
rbegin() noexcept {
return reverse_iterator(
end()); }
365 reverse_iterator
rend() noexcept {
return reverse_iterator(
begin()); }
371 const_reverse_iterator
rbegin() const noexcept {
return const_reverse_iterator(
end()); }
377 const_reverse_iterator
rend() const noexcept {
return const_reverse_iterator(
begin()); }
383 const_reverse_iterator
crbegin() const noexcept {
return const_reverse_iterator(
cend()); }
389 const_reverse_iterator
crend() const noexcept {
return const_reverse_iterator(
cbegin()); }
411 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
418 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
433 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
446 auto operator[](K
const &key) ->
decltype(
auto)
448 return m_data[
static_cast<typename Container::key_type
>(key)];
457 auto operator[](K
const &key)
const ->
decltype(
auto)
458 requires (Type::HasMappedType<const Container>) {
459 auto k =
static_cast<typename Container::key_type
>(key);
462 throw OutOfBoundsError(
"Key not found in Iterable::operator[]");
474 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
487 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
488 auto it =
m_data.cbegin();
502 throw OutOfBoundsError(
"Index {} out of bounds in Iterable::operator[]", i);
503 auto it =
m_data.cbegin();
536 m_data.push_back(std::move(value));
544 m_data.push_front(std::move(value));
551 m_data.insert(std::move(value));
560 for (
const auto& item :
m_data) {
576 for (
const auto &item :
m_data) {
577 if (item.second == value)
return true;
590 auto k =
static_cast<typename Container::key_type
>(key);
Wrapper const iterator for Iterable.
Definition iterable.hxx:150
ConstIterator operator++(int)
Post-increment operator.
Definition iterable.hxx:181
ConstIterator & operator-=(difference_type n)
Compound subtraction operator.
Definition iterable.hxx:207
ConstIterator & operator--()
Pre-decrement operator.
Definition iterable.hxx:187
ConstIterator operator-(difference_type n) const
Subtraction operator.
Definition iterable.hxx:221
reference operator*() const
Dereference operator.
Definition iterable.hxx:163
pointer operator->() const
Arrow operator.
Definition iterable.hxx:169
ConstIterator operator+(difference_type n) const
Addition operator.
Definition iterable.hxx:214
bool operator!=(const ConstIterator &other) const
Inequality operator.
Definition iterable.hxx:242
ConstIterator & operator++()
Pre-increment operator.
Definition iterable.hxx:175
ConstIterator operator--(int)
Post-decrement operator.
Definition iterable.hxx:193
bool operator==(const ConstIterator &other) const
Subscript operator.
Definition iterable.hxx:235
difference_type operator-(const ConstIterator &other) const
Subtraction operator between two const iterators.
Definition iterable.hxx:228
ConstIterator & operator+=(difference_type n)
Compound addition operator.
Definition iterable.hxx:200
Wrapper iterator for Iterable.
Definition iterable.hxx:42
Iterator & operator++()
Pre-increment operator.
Definition iterable.hxx:67
bool operator!=(const Iterator &other) const
Inequality operator.
Definition iterable.hxx:134
reference operator*()
Dereference operator.
Definition iterable.hxx:55
Iterator & operator+=(difference_type n)
Compound addition operator.
Definition iterable.hxx:92
Iterator operator++(int)
Post-increment operator.
Definition iterable.hxx:73
Iterator operator--(int)
Post-decrement operator.
Definition iterable.hxx:85
Iterator & operator-=(difference_type n)
Compound subtraction operator.
Definition iterable.hxx:99
Iterator operator+(difference_type n) const
Addition operator.
Definition iterable.hxx:106
bool operator==(const Iterator &other) const
Subscript operator.
Definition iterable.hxx:127
Iterator & operator--()
Pre-decrement operator.
Definition iterable.hxx:79
Iterator operator-(difference_type n) const
Subtraction operator.
Definition iterable.hxx:113
pointer operator->()
Arrow operator.
Definition iterable.hxx:61
difference_type operator-(const Iterator &other) const
Subtraction operator between two iterators.
Definition iterable.hxx:120
A generic iterable container wrapper.
Definition iterable.hxx:26
const_reverse_iterator crbegin() const noexcept
Gets const reverse begin iterator.
Definition iterable.hxx:383
const_iterator cend() const noexcept
Gets const end iterator.
Definition iterable.hxx:353
reverse_iterator rend() noexcept
Gets reverse end iterator.
Definition iterable.hxx:365
const_reverse_iterator rbegin() const noexcept
Gets const reverse begin iterator.
Definition iterable.hxx:371
virtual ~Iterable()=default
Virtual destructor.
bool has_key(const K &key) const
Checks if the container has a specific key (for associative containers)
Definition iterable.hxx:588
const_reference operator[](size_type i) const
Access element at given index (const version)
Definition iterable.hxx:471
bool has_item(const value_type &value) const
Checks if the container has a specific item.
Definition iterable.hxx:559
iterator end() noexcept
Gets end iterator.
Definition iterable.hxx:335
Iterable(Container &&data)
Move constructor from existing container.
Definition iterable.hxx:274
const_iterator cbegin() const noexcept
Gets const begin iterator.
Definition iterable.hxx:347
void add(value_type &&value)
Adds an element to associative containers via insert (move version)
Definition iterable.hxx:550
Iterable(Iterable &&)=default
Move constructor.
reverse_iterator rbegin() noexcept
Gets reverse begin iterator.
Definition iterable.hxx:359
Iterable()=default
Default constructor.
reference operator[](size_type i)
Access element at given index.
Definition iterable.hxx:408
void add(const value_type &value)
Adds an element to the container.
Definition iterable.hxx:520
bool empty() const noexcept
Checks if the container is empty.
Definition iterable.hxx:401
auto operator[](size_type i) -> decltype(auto)
Access element at given index (non-const version)
Definition iterable.hxx:430
void add(const value_type &value)
Adds an element to the container.
Definition iterable.hxx:512
bool operator==(const Iterable &other) const
Equality operator.
Definition iterable.hxx:310
void add(value_type &&value)
Adds an element to the container (move version)
Definition iterable.hxx:543
const_iterator end() const noexcept
Gets const end iterator.
Definition iterable.hxx:341
Iterable(const Iterable &)=default
Copy constructor.
const_reverse_iterator rend() const noexcept
Gets const reverse end iterator.
Definition iterable.hxx:377
size_type size() const noexcept
Gets the size of the container.
Definition iterable.hxx:395
Container m_data
Underlying container.
Definition iterable.hxx:28
Iterable(const Container &data)
Constructor from existing container.
Definition iterable.hxx:268
auto operator[](size_type i) const -> decltype(auto)
Access element at given index (const version)
Definition iterable.hxx:499
const_reference operator[](size_type i) const
Access element at given index (const version)
Definition iterable.hxx:484
bool has_item(M const &value) const
Checks if the container has a specific item (for associative containers)
Definition iterable.hxx:574
iterator begin() noexcept
Gets begin iterator.
Definition iterable.hxx:323
const_reverse_iterator crend() const noexcept
Gets const reverse end iterator.
Definition iterable.hxx:389
void add(const value_type &value)
Adds an element to associative containers via insert
Definition iterable.hxx:527
bool operator!=(const Iterable &other) const
Inequality operator.
Definition iterable.hxx:317
const_iterator begin() const noexcept
Gets const begin iterator.
Definition iterable.hxx:329
void add(value_type &&value)
Adds an element to the container (move version)
Definition iterable.hxx:535
Iterable & operator=(Iterable &&)=default
Move assignment operator.
Iterable & operator=(const Iterable &)=default
Copy assignment operator.
Exception thrown when an out-of-bounds access is attempted.
Definition exception.hxx:130
Concept that checks whether a container supports insert with a value.
Definition type_traits.hxx:121
Concept to check if a container has a mapped_type member type.
Definition type_traits.hxx:156
Concept that checks whether a container supports push_back.
Definition type_traits.hxx:105
Concept that checks whether a container supports push_front.
Definition type_traits.hxx:113
Concept that checks whether a container supports operator[] for a given key/index type U.
Definition type_traits.hxx:132
Main namespace for the StormByte library.