Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-zip.H File Reference

Zip iterators and functional operations for multiple containers. More...

#include <type_traits>
#include <tuple>
#include <vector>
#include <htlist.H>
#include <ahFunctional.H>
#include <tpl_dynSkipList.H>
Include dependency graph for ah-zip.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Aleph::ZipIterator< C >
 
class  Aleph::EnumZipIterator< C >
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::zip_detail
 
namespace  Aleph::std_zip_detail
 
namespace  Aleph::zip_index_detail
 

Typedefs

using Aleph::T = std::decay_t< typename HeadC::Item_Type >
 
using Aleph::Tuple_Type = decltype(std::tuple_cat(std::declval< std::tuple< T > >(), std::declval< typename ZipIterator< TailC... >::Tuple_Type >()))
 The tuple type returned by get_curr() and get_curr_ne()
 
using Aleph::Item_Type = T
 Type of elements from the first container.
 

Functions

 Aleph::ZipIterator (const HeadC &head, const TailC &...tail)
 Construct a zip iterator over multiple Aleph containers.
 
bool Aleph::has_curr () const noexcept
 Return true if all underlying iterators are positioned on a valid item.
 
bool Aleph::completed () const noexcept
 Return true if all underlying iterators are finished.
 
auto Aleph::get_curr () const
 Return the current tuple (bounds-checked).
 
auto Aleph::get_curr_ne () const noexcept
 Return the current tuple (no-throw variant).
 
DynList< TAleph::get_curr_list () const
 Returns current elements as a DynList (requires homogeneous Item_Type)
 
void Aleph::next ()
 Advance all underlying iterators (bounds-checked).
 
void Aleph::next_ne () noexcept
 Advance all underlying iterators (no-throw variant).
 
template<class ... Cs>
ZipIterator< Cs... > Aleph::get_zip_it (const Cs &... cs)
 Create a ZipIterator over the given containers.
 
template<class ... Cs>
ZipIterator< Cs... > Aleph::get_zip_it_pos (size_t pos, const Cs &... cs)
 Create a ZipIterator positioned at index pos.
 
template<class ... Cs>
ZipIterator< Cs... > Aleph::zip_it (const Cs &... cs)
 Alias for get_zip_it.
 
template<class ... Cs>
ZipIterator< Cs... > Aleph::zip_it_pos (size_t pos, const Cs &... cs)
 Alias for get_zip_it_pos.
 
template<class ... Cs>
bool Aleph::equal_length (const Cs &... cs)
 Return true if all containers have the same length.
 
template<class Op , class ... Cs>
bool Aleph::zip_traverse (Op &&op, const Cs &... cs)
 Traverse zipped containers while op returns true.
 
template<class Op , class ... Cs>
bool Aleph::zip_traverse_eq (Op &&op, const Cs &... cs)
 Traverse zipped containers while op returns true; verify equal lengths.
 
template<class Op , class ... Cs>
void Aleph::zip_for_each (Op &&op, const Cs &... cs)
 Apply op to every zipped tuple.
 
template<class Op , class ... Cs>
void Aleph::zip_for_each_eq (Op &&op, const Cs &... cs)
 Apply op to every zipped tuple; throw if containers differ in length.
 
template<class Op , class ... Cs>
bool Aleph::zip_all (Op &&op, const Cs &... cs)
 Return true if op returns true for all tuples and containers have equal length.
 
template<class Op , class ... Cs>
bool Aleph::zip_all_short (Op &&op, const Cs &... cs)
 Return true if op returns true for all tuples (without length check).
 
template<class Op , class ... Cs>
bool Aleph::zip_forall (Op &&op, const Cs &... cs)
 Alias for zip_all.
 
template<class Op , class ... Cs>
bool Aleph::zip_forall_short (Op &&op, const Cs &... cs)
 Alias for zip_all_short.
 
template<class Op , class ... Cs>
bool Aleph::zip_exists (Op &&op, const Cs &... cs)
 Return true if op returns true for at least one tuple.
 
template<class Op , class ... Cs>
bool Aleph::zip_any (Op &&op, const Cs &... cs)
 Alias for zip_exists.
 
template<class Op , class ... Cs>
bool Aleph::zip_none (Op &&op, const Cs &... cs)
 Return true if op returns false for all tuples.
 
template<class Op , class ... Cs>
size_t Aleph::zip_count (Op &&op, const Cs &... cs)
 Count tuples that satisfy predicate op.
 
template<class ... Cs>
size_t Aleph::zip_length (const Cs &... cs)
 Count all tuples (minimum length of containers).
 
template<class Op , class ... Cs>
auto Aleph::zip_find_first (Op &&op, const Cs &... cs)
 Return the first tuple that satisfies predicate op.
 
template<class Op , class ... Cs>
auto Aleph::zip_find_last (Op &&op, const Cs &... cs)
 Return the last tuple that satisfies predicate op.
 
template<class ... Cs>
auto Aleph::zip_nth (size_t n, const Cs &... cs)
 Return the n-th tuple from zipped containers.
 
template<class ... Cs>
auto Aleph::zip_first (const Cs &... cs)
 Return the first tuple from zipped containers.
 
template<typename T , class Op , class ... Cs>
DynList< TAleph::zip_maps (Op op, const Cs &... cs)
 Map op over zipped tuples, returning a list of results.
 
template<typename T , class Prop , class Op , class ... Cs>
DynList< TAleph::zip_maps_if (Prop prop, Op op, const Cs &... cs)
 Map op over zipped tuples that satisfy prop.
 
template<typename T , class Op , class ... Cs>
T Aleph::zip_foldl (const T &init, Op op, const Cs &... cs)
 Left fold (reduce) over zipped tuples.
 
template<typename T , class Op , class ... Cs>
T Aleph::zip_foldl_eq (const T &init, Op op, const Cs &... cs)
 Left fold over zipped tuples; throw if containers differ in length.
 
template<typename T , class Op , class ... Cs>
DynList< TAleph::zip_maps_eq (Op op, const Cs &... cs)
 Map op over zipped tuples; throw if containers differ in length.
 
template<typename T , class Prop , class Op , class ... Cs>
DynList< TAleph::zip_maps_if_eq (Prop prop, Op op, const Cs &... cs)
 Map op over zipped tuples that satisfy prop; throw if lengths differ.
 
template<class Op , class ... Cs>
auto Aleph::zip_map (Op &&op, const Cs &... cs)
 Map op over zipped tuples with auto-deduced return type.
 
template<class Op , class ... Cs>
auto Aleph::zip_map_eq (Op &&op, const Cs &... cs)
 Map op over zipped tuples with auto-deduced return type; throw if lengths differ.
 
template<class Op , class ... Cs>
auto Aleph::zip_filter (Op op, const Cs &... cs)
 Filter zipped tuples by predicate op.
 
template<class Op , class ... Cs>
auto Aleph::zip_filter_eq (Op op, const Cs &... cs)
 Filter zipped tuples by predicate op; throw if containers differ in length.
 
template<class Cmp , class Tuple , size_t... Is>
bool Aleph::zip_detail::compare_adjacent (Cmp &cmp, const Tuple &t, std::index_sequence< Is... >)
 Compare all adjacent pairs in a tuple using the given comparator.
 
template<class Cmp , class ... Cs>
bool Aleph::zip_cmp (Cmp cmp, const Cs &... cs)
 Return true if cmp(t) is true for each built tuple t.
 
template<class Op , class ... Cs>
size_t Aleph::zip_find_index (Op op, const Cs &... cs)
 Find the first index where op returns true.
 
template<class Op , class ... Cs>
auto Aleph::zip_partition (Op op, const Cs &... cs)
 Partition zipped tuples by predicate op.
 
template<class ... Cs>
auto Aleph::t_zip (const Cs &... cs)
 Materialize zipped tuples into a DynList.
 
template<class ... Cs>
auto Aleph::t_zip_eq (const Cs &... cs)
 Materialize zipped tuples; throw if containers differ in length.
 
 Aleph::EnumZipIterator (const HeadC &head, const TailC &...tail)
 Construct an enumerating zip iterator over multiple containers.
 
template<class ... Cs>
EnumZipIterator< Cs... > Aleph::get_enum_zip_it (const Cs &... cs)
 Create an EnumZipIterator over the given containers.
 
template<class C , class ... Cs>
EnumZipIterator< C, Cs... > Aleph::get_enum_zip_it_pos (size_t pos, const C &c, const Cs &... cs)
 Create an EnumZipIterator positioned at index pos.
 
template<class ... Cs>
EnumZipIterator< Cs... > Aleph::enum_zip_it (const Cs &... cs)
 Alias for get_enum_zip_it.
 
template<class ... Cs>
EnumZipIterator< Cs... > Aleph::enum_zip_it_pos (size_t pos, const Cs &... cs)
 Alias for get_enum_zip_it_pos.
 
template<class ... Cs>
auto Aleph::t_enum_zip (const Cs &... cs)
 Materialize enumerated zipped tuples into a DynList.
 
template<class ... Cs>
auto Aleph::t_enum_zip_eq (const Cs &... cs)
 Materialize enumerated zipped tuples; throw if containers differ in length.
 
template<typename... Ts, size_t... is>
static auto Aleph::t_unzip_impl (const DynList< std::tuple< Ts... > > &l, std::index_sequence< is... >)
 
template<class... Ts>
auto Aleph::t_unzip (const DynList< std::tuple< Ts... > > &tuples)
 Unzip a list of tuples into a tuple of lists.
 
template<class C , typename ... Lists>
auto Aleph::zip_lists (const C &c, const Lists &... lists)
 Take several container of same type and some length and builds a list of lists.
 
template<class C , typename ... Lists>
auto Aleph::zip_lists_eq (const C &c, const Lists &... lists)
 Like zip_lists but throws if containers differ in length.
 
template<typename... Its>
bool Aleph::std_zip_detail::all_valid (const Its &... its)
 Check if all iterators are valid (not at end).
 
template<typename... Its>
void Aleph::std_zip_detail::advance_all (Its &... its)
 Advance all iterators.
 
template<typename... Its>
auto Aleph::std_zip_detail::deref_all (const Its &... its)
 Dereference all iterators and make a tuple.
 
template<typename C1 , typename C2 >
auto Aleph::std_zip (const C1 &c1, const C2 &c2)
 Build a vector of pairs from two STL containers.
 
template<typename... Cs>
auto Aleph::tzip_std (const Cs &... cs)
 Build a vector of tuples from 2 or more STL containers (variadic).
 
template<typename... Cs>
auto Aleph::std_zip_n (const Cs &... cs)
 Build a vector of tuples from 2 or more STL containers (variadic).
 
template<class Op , class ... Cs>
auto Aleph::zip_transform (Op &&op, const Cs &... cs)
 Transform zipped tuples using op and return results in a vector.
 
template<class Op , class ... Cs>
auto Aleph::zip_transform_eq (Op &&op, const Cs &... cs)
 Transform zipped tuples; throw if containers differ in length.
 
template<class Op , class ... Cs>
void Aleph::zip_for_each_indexed (Op &&op, const Cs &... cs)
 Apply op to each zipped tuple along with its index.
 
template<class Op , class ... Cs>
void Aleph::zip_for_each_indexed_eq (Op &&op, const Cs &... cs)
 Apply op to each zipped tuple with index; throw if lengths differ.
 
template<class ... Cs>
auto Aleph::zip_take (size_t n, const Cs &... cs)
 Take at most n tuples from the zipped containers.
 
template<class ... Cs>
auto Aleph::zip_drop (size_t n, const Cs &... cs)
 Skip n tuples and return the rest.
 
template<class Pred , class ... Cs>
auto Aleph::zip_take_while (Pred &&pred, const Cs &... cs)
 Take tuples while predicate pred returns true.
 
template<class Pred , class ... Cs>
auto Aleph::zip_drop_while (Pred &&pred, const Cs &... cs)
 Skip tuples while predicate pred returns true, then return the rest.
 
template<class Op , class Tuple , size_t... Is>
void Aleph::zip_index_detail::for_each_in_tuple_impl (Op &&op, Tuple &&t, std::index_sequence< Is... >)
 Apply a function to each element in a tuple.
 
template<class Op , class Tuple , size_t... Is>
auto Aleph::zip_index_detail::transform_tuple_impl (Op &&op, Tuple &&t, std::index_sequence< Is... >)
 Transform each element in a tuple.
 
template<class Pred , class Tuple , size_t... Is>
bool Aleph::zip_index_detail::all_of_tuple_impl (Pred &&pred, const Tuple &t, std::index_sequence< Is... >)
 Check if all elements satisfy a predicate.
 
template<class Pred , class Tuple , size_t... Is>
bool Aleph::zip_index_detail::any_of_tuple_impl (Pred &&pred, const Tuple &t, std::index_sequence< Is... >)
 Check if any element satisfies a predicate.
 
template<class Op , class Tuple >
void Aleph::for_each_in_tuple (Op &&op, Tuple &&t)
 Apply op to each element of a tuple.
 
template<class Op , class Tuple >
auto Aleph::transform_tuple (Op &&op, Tuple &&t)
 Transform each element of a tuple, returning a new tuple.
 
template<class Pred , class Tuple >
bool Aleph::all_of_tuple (Pred &&pred, const Tuple &t)
 Return true if all tuple elements satisfy pred.
 
template<class Pred , class Tuple >
bool Aleph::any_of_tuple (Pred &&pred, const Tuple &t)
 Return true if any tuple element satisfies pred.
 
template<class Pred , class Tuple >
bool Aleph::none_of_tuple (Pred &&pred, const Tuple &t)
 Return true if no tuple element satisfies pred.
 

Detailed Description

Zip iterators and functional operations for multiple containers.

This header provides:

  • ZipIterator: Iterate over multiple Aleph containers in lockstep
  • EnumZipIterator: Like ZipIterator but includes enumeration index
  • Functional operations: zip_traverse, zip_for_each, zip_map, zip_filter, zip_fold, zip_partition, and more
  • STL compatibility: std_zip, tzip_std for std::vector and other STL containers
  • Tuple utilities: for_each_in_tuple, transform_tuple, all_of_tuple, any_of_tuple

All zip operations stop at the shortest container. Variants ending in _eq throw std::length_error if container lengths differ.

Note
This header is NOT thread-safe. Concurrent access to iterators or containers from multiple threads leads to undefined behavior.
Author
Leandro Rabindranath Leon

Definition in file ah-zip.H.