A view over multiple containers simultaneously. It allows iterating through multiple containers at once, stopping at the shortest container.
More...
#include <zip.hpp>
|
using | iterator = zip_iterator< typename std::conditional_t< std::is_const_v< Containers >, typename Containers::const_iterator, typename Containers::iterator >... > |
| A composite iterator that iterates over all provided containers in parallel. More...
|
|
using | const_iterator = zip_iterator< typename Containers::const_iterator... > |
| A composite iterator that iterates over all provided containers in parallel. More...
|
|
using | value_type = typename iterator::value_type |
| The value_type is the type of the element returned by the iterator, which is a tuple of elements from each container.
|
|
|
| zip (Containers &... containers) |
| Constructs a zip object from the provided containers. More...
|
|
iterator | begin () const |
| Returns an iterator pointing to the beginning of the zipped containers. More...
|
|
iterator | end () const |
| Returns an iterator pointing to the end of the zipped containers. More...
|
|
const_iterator | cbegin () const |
| Returns a const iterator pointing to the beginning of the zipped containers. More...
|
|
const_iterator | cend () const |
| Returns a const iterator pointing to the end of the zipped containers. More...
|
|
std::size_t | size () const |
| Returns the size of the zipped sequence, which is the size of the smallest container. More...
|
|
bool | empty () const |
| Checks if the zipped sequence is empty. More...
|
|
| operator bool () const |
| Allows the zip object to be used in a boolean context, indicating whether the zipped sequence is non-empty. More...
|
|
value_type | front () |
| Returns the first element in the zipped sequence. More...
|
|
value_type | front () const |
| Returns the first element in the zipped sequence (const overload). More...
|
|
value_type | back () |
| Returns the last element in the zipped sequence. More...
|
|
value_type | back () const |
| Returns the last element in the zipped sequence (const overload). More...
|
|
value_type | operator[] (const std::size_t offset) const |
| Returns the element at the specified offset in the zipped sequence. More...
|
|
template<typename... Containers>
class msd::zip< Containers >
A view over multiple containers simultaneously. It allows iterating through multiple containers at once, stopping at the shortest container.
- Note
- The zip never throws explicitly any exception. It all depends on what the given containers throw.
- Template Parameters
-
Containers | The types of the containers to be zipped. Each container must support standard iteration (must have begin() , end() , cbegin() , and cend() methods). |
◆ const_iterator
template<typename... Containers>
A composite iterator that iterates over all provided containers in parallel.
Guarantees that the containers are not modified.
◆ iterator
template<typename... Containers>
using msd::zip< Containers >::iterator = zip_iterator<typename std::conditional_t<std::is_const_v<Containers>, typename Containers::const_iterator, typename Containers::iterator>...> |
A composite iterator that iterates over all provided containers in parallel.
It is constructed based on whether the containers are const or non-const.
◆ zip()
template<typename... Containers>
msd::zip< Containers >::zip |
( |
Containers &... |
containers | ) |
|
|
inlineexplicit |
Constructs a zip
object from the provided containers.
- Parameters
-
containers | The containers to be zipped together. |
- Precondition
- At least two containers must be provided.
◆ back() [1/2]
template<typename... Containers>
Returns the last element in the zipped sequence.
- Precondition
- The zipped sequence must not be empty.
- Returns
- The last element in the zipped sequence.
◆ back() [2/2]
template<typename... Containers>
Returns the last element in the zipped sequence (const overload).
- Precondition
- The zipped sequence must not be empty.
- Returns
- The last element in the zipped sequence.
◆ begin()
template<typename... Containers>
Returns an iterator pointing to the beginning of the zipped containers.
- Returns
- An iterator to the first element in the zipped sequence.
◆ cbegin()
template<typename... Containers>
Returns a const iterator pointing to the beginning of the zipped containers.
- Returns
- A const iterator to the first element in the zipped sequence.
◆ cend()
template<typename... Containers>
Returns a const iterator pointing to the end of the zipped containers.
- Returns
- A const iterator to the end of the zipped sequence.
◆ empty()
template<typename... Containers>
bool msd::zip< Containers >::empty |
( |
| ) |
const |
|
inline |
Checks if the zipped sequence is empty.
- Returns
true
if the zipped sequence is empty, false
otherwise.
◆ end()
template<typename... Containers>
Returns an iterator pointing to the end of the zipped containers.
- Returns
- An iterator to the end of the zipped sequence.
◆ front() [1/2]
template<typename... Containers>
Returns the first element in the zipped sequence.
- Precondition
- The zipped sequence must not be empty.
- Returns
- The first element in the zipped sequence.
◆ front() [2/2]
template<typename... Containers>
Returns the first element in the zipped sequence (const overload).
- Precondition
- The zipped sequence must not be empty.
- Returns
- The first element in the zipped sequence.
◆ operator bool()
template<typename... Containers>
msd::zip< Containers >::operator bool |
( |
| ) |
const |
|
inlineexplicit |
Allows the zip
object to be used in a boolean context, indicating whether the zipped sequence is non-empty.
- Returns
true
if the zipped sequence is non-empty, false
otherwise.
◆ operator[]()
template<typename... Containers>
Returns the element at the specified offset in the zipped sequence.
- Parameters
-
offset | The index of the element to retrieve. |
- Precondition
- The offset must be less than the size of the zipped sequence.
- Returns
- Reference to the element at the specified offset.
◆ size()
template<typename... Containers>
std::size_t msd::zip< Containers >::size |
( |
| ) |
const |
|
inline |
Returns the size of the zipped sequence, which is the size of the smallest container.
- Returns
- The number of elements in the zipped sequence.
The documentation for this class was generated from the following file: