38# include <gtest/gtest.h>
61 static constexpr size_t N = 5;
80 auto it =
zip_it(l1, l2 , l3);
86 auto it =
zip_it(l1, l2, l3, l4);
121 for (
auto it =
zip_it(l1, l2, l3); it.has_curr(); it.next_ne(), ++i)
123 auto t = it.get_curr_ne();
130 for (
auto it =
zip_it_pos(1, l1, l2, l3); it.has_curr(); it.next_ne(), ++i)
132 auto t = it.get_curr_ne();
138 for (
auto it =
enum_zip_it(l1, l2, l3); it.has_curr(); it.next_ne())
140 auto t = it.get_curr_ne();
173 }, l1, l2, l3), length_error);
178 get<2>(t) ==
"3"; }, l1, l2, l3));
218 get<2>(t) ==
"3"; }, l1, l2, l3));
220 get<2>(t) ==
"7"; }, l1, l2, l3));
242 {
return get<1>(t) != 2; }, l1, l2, l3);
256 for (
auto it =
zip_it(
lzip, l1, l2, l3); it.has_curr(); it.next_ne())
258 auto t = it.get_curr_ne();
296 for (
auto it =
zip_it(
l, l1, l2); it.has_curr(); it.next_ne())
298 auto c = it.get_curr_ne();
314 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
343 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
345 auto t = it.get_curr();
360 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++
expected_idx)
362 auto t = it.get_curr();
376 vector<int> v1 = { 1, 2, 3, 4, 5 };
383 for (
size_t i = 0; i < result.size(); ++i)
385 EXPECT_EQ(result[i].first,
static_cast<int>(i + 1));
393 vector<int> v1 = { 1, 2, 3 };
394 vector<int> v2 = { 10, 20, 30, 40, 50 };
408 vector<int> v1 = { 1, 2, 3 };
423 vector<int> v1 = { 1, 2, 3 };
424 vector<double> v2 = { 1.1, 2.2, 3.3 };
438 vector<int> v1 = { 1, 2, 3 };
439 vector<double> v2 = { 1.1, 2.2, 3.3 };
461 vector<int> v1 = { 1, 2 };
462 vector<double> v2 = { 1.1, 2.2 };
479 vector<int> v1 = { 1, 2, 3 };
480 vector<double> v2 = { 1.1, 2.2, 3.3 };
490 vector<int> v1 = { 1, 2 };
491 vector<int> v2 = { 10, 20, 30 };
492 vector<int>
v3 = { 100, 200, 300, 400 };
504 vector<int> v1 = { 1, 2 };
505 vector<int> v2 = { 10, 20, 30 };
506 vector<int>
v3 = { 100, 200, 300, 400 };
507 vector<int>
v4 = { 1000, 2000, 3000, 4000, 5000 };
521 for (; it.has_curr(); it.next_ne(), ++
count)
523 auto t = it.get_curr_ne();
543 auto it =
zip_it(a, b, c);
616 const size_t SIZE = 1000;
649 auto it =
zip_it(l1, l2, l3);
652 while (it.has_curr())
661 auto it =
zip_it(l1, l2, l3);
664 while (it.has_curr())
685 auto t = it.get_curr_ne();
703 static_assert(std::is_same_v<std::decay_t<decltype(get<0>(t))>,
int>);
704 static_assert(std::is_same_v<std::decay_t<decltype(get<1>(t))>,
double>);
705 static_assert(std::is_same_v<std::decay_t<decltype(get<2>(t))>,
string>);
706 static_assert(std::is_same_v<std::decay_t<decltype(get<3>(t))>,
char>);
707 static_assert(std::is_same_v<std::decay_t<decltype(get<4>(t))>,
long>);
722 auto t = it.get_curr_ne();
747 auto t = it.get_curr_ne();
765 static_assert(std::is_same_v<std::decay_t<decltype(get<0>(t))>,
string>);
766 static_assert(std::is_same_v<std::decay_t<decltype(get<1>(t))>,
double>);
767 static_assert(std::is_same_v<std::decay_t<decltype(get<2>(t))>,
int>);
783 for (
auto it =
zip_it(
hash, tree, list, arr); it.has_curr(); it.next_ne(), ++
count)
785 auto t = it.get_curr_ne();
820 for (
size_t i = 0; i <
N; ++i)
821 EXPECT_EQ(result[i],
static_cast<int>(2 * i));
831 for (
size_t i = 0; i <
N; ++i)
832 EXPECT_EQ(result[i],
static_cast<int>(i * i));
859 values.push_back(
get<0>(t));
865 for (
size_t i = 0; i <
N; ++i)
868 EXPECT_EQ(values[i],
static_cast<int>(i));
913 auto result =
zip_take(3, l1, l2, l3);
918 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
920 auto t = it.get_curr();
929 auto result =
zip_take(100, l1, l2);
941 auto result =
zip_drop(2, l1, l2, l3);
946 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
948 auto t = it.get_curr();
963 auto result =
zip_drop(100, l1, l2);
981 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
983 auto t = it.get_curr();
1011 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1013 auto t = it.get_curr();
1046 auto t =
make_tuple(1, 2.5,
string(
"hello"));
1125 bool result =
all_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1133 bool result =
all_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1141 bool result =
all_of_tuple([](
auto) {
return false; }, t);
1149 bool result =
any_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1157 bool result =
any_of_tuple([](
auto x) {
return x % 2 == 0; }, t);
1165 bool result =
any_of_tuple([](
auto) {
return true; }, t);
1189 const size_t SIZE = 1000;
1198 for (
size_t i = 0; i <
SIZE; ++i)
1278 auto it1 =
zip_it(l1, l2);
1360 auto t = it.get_curr_ne();
1408 auto t = it.get_curr_ne();
1454 auto it =
zip_it(l1, l2);
1467 auto it =
zip_it(l1, l2);
1753 static_assert(std::is_same_v<ZipIt::Tuple_Type, ExpectedType>,
1754 "Tuple_Type should be tuple<int, int, string>");
1757 ZipIt::Tuple_Type t = std::make_tuple(1, 2,
"test");
1767 static_assert(std::is_same_v<ZipIt::Item_Type, int>,
1768 "Item_Type should be int for single container");
1797 [](
auto t) {
return get<0>(t) > 1; },
1798 [](
auto t) {
return get<0>(t) * 10; },
1810 [](
auto) {
return true; },
1811 [](
auto t) {
return get<0>(t); },
1838 auto result =
zip_map([](
auto t) {
1847 "zip_map should return DynList<string>");
1853 auto result =
zip_map([](
auto t) {
1860 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1861 EXPECT_EQ(it.get_curr(),
static_cast<int>(2 * i));
1864 static_assert(std::is_same_v<
decltype(result),
DynList<int>>,
1865 "zip_map should return DynList<int>");
1878 for (
auto it = result.get_it(); it.has_curr(); it.next_ne(), ++i)
1879 EXPECT_EQ(it.get_curr(),
static_cast<int>(i * i));
1986 auto pred = [](
auto x) {
return x > 10; };
1995 const size_t SIZE = 1000;
2037 auto [i, s] = it.get_curr_ne();
String manipulation utilities.
Zip iterators and functional operations for multiple containers.
TEST_F(EmptyGroup, empty)
Functional programming utilities for Aleph-w containers.
Simple dynamic array with automatic resizing and functional operations.
Dynamic singly linked list with functional programming support.
T & get_first() const
Return the first item of the list.
Dynamic set backed by balanced binary search trees with automatic memory management.
bool contains(const Key &key) const
Dynamic ordered set implemented with a Skip List.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
Aleph::DynList< __T > maps(Operation &op) const
Map the elements of the container.
Type & nth(const size_t n)
Return the n-th item of container.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
Iterator that traverses multiple Aleph containers in lockstep.
Freq_Node * pred
Predecessor node in level-order traversal.
Main namespace for Aleph-w library functions.
void zip_for_each(Op &&op, const Cs &... cs)
Apply op to every zipped tuple.
bool zip_none(Op &&op, const Cs &... cs)
Return true if op returns false for all tuples.
bool zip_all(Op &&op, const Cs &... cs)
Return true if op returns true for all tuples and containers have equal length.
bool zip_cmp(Cmp cmp, const Cs &... cs)
Return true if cmp(t) is true for each built tuple t.
auto zip_find_first(Op &&op, const Cs &... cs)
Return the first tuple that satisfies predicate op.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
size_t zip_find_index(Op op, const Cs &... cs)
Find the first index where op returns true.
EnumZipIterator< Cs... > enum_zip_it(const Cs &... cs)
Alias for get_enum_zip_it.
size_t zip_count(Op &&op, const Cs &... cs)
Count tuples that satisfy predicate op.
auto zip_transform_eq(Op &&op, const Cs &... cs)
Transform zipped tuples; throw if containers differ in length.
auto zip_drop_while(Pred &&pred, const Cs &... cs)
Skip tuples while predicate pred returns true, then return the rest.
auto zip_first(const Cs &... cs)
Return the first tuple from zipped containers.
T zip_foldl(const T &init, Op op, const Cs &... cs)
Left fold (reduce) over zipped tuples.
auto std_zip(const C1 &c1, const C2 &c2)
Build a vector of pairs from two STL containers.
auto tzip_std(const Cs &... cs)
Build a vector of tuples from 2 or more STL containers (variadic).
bool all_of_tuple(Pred &&pred, const Tuple &t)
Return true if all tuple elements satisfy pred.
auto transform_tuple(Op &&op, Tuple &&t)
Transform each element of a tuple, returning a new tuple.
auto zip_filter(Op op, const Cs &... cs)
Filter zipped tuples by predicate op.
bool zip_any(Op &&op, const Cs &... cs)
Alias for zip_exists.
auto zip_take_while(Pred &&pred, const Cs &... cs)
Take tuples while predicate pred returns true.
void for_each_in_tuple(Op &&op, Tuple &&t)
Apply op to each element of a tuple.
ZipIterator< Cs... > zip_it_pos(size_t pos, const Cs &... cs)
Alias for get_zip_it_pos.
void zip_for_each_indexed(Op &&op, const Cs &... cs)
Apply op to each zipped tuple along with its index.
bool zip_traverse(Op &&op, const Cs &... cs)
Traverse zipped containers while op returns true.
bool zip_forall(Op &&op, const Cs &... cs)
Alias for zip_all.
bool equal_length(const Cs &... cs)
Return true if all containers have the same length.
bool zip_traverse_eq(Op &&op, const Cs &... cs)
Traverse zipped containers while op returns true; verify equal lengths.
auto zip_lists(const C &c, const Lists &... lists)
Take several container of same type and some length and builds a list of lists.
void zip_for_each_eq(Op &&op, const Cs &... cs)
Apply op to every zipped tuple; throw if containers differ in length.
bool any_of_tuple(Pred &&pred, const Tuple &t)
Return true if any tuple element satisfies pred.
bool zip_forall_short(Op &&op, const Cs &... cs)
Alias for zip_all_short.
auto zip_transform(Op &&op, const Cs &... cs)
Transform zipped tuples using op and return results in a vector.
auto zip_map_eq(Op &&op, const Cs &... cs)
Map op over zipped tuples with auto-deduced return type; throw if lengths differ.
auto zip_take(size_t n, const Cs &... cs)
Take at most n tuples from the zipped containers.
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
bool none_of_tuple(Pred &&pred, const Tuple &t)
Return true if no tuple element satisfies pred.
auto t_zip(const Cs &... cs)
Materialize zipped tuples into a DynList.
auto zip_lists_eq(const C &c, const Lists &... lists)
Like zip_lists but throws if containers differ in length.
auto t_enum_zip_eq(const Cs &... cs)
Materialize enumerated zipped tuples; throw if containers differ in length.
auto t_unzip(const DynList< std::tuple< Ts... > > &tuples)
Unzip a list of tuples into a tuple of lists.
T zip_foldl_eq(const T &init, Op op, const Cs &... cs)
Left fold over zipped tuples; throw if containers differ in length.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
auto zip_partition(Op op, const Cs &... cs)
Partition zipped tuples by predicate op.
bool zip_all_short(Op &&op, const Cs &... cs)
Return true if op returns true for all tuples (without length check).
size_t zip_length(const Cs &... cs)
Count all tuples (minimum length of containers).
auto t_enum_zip(const Cs &... cs)
Materialize enumerated zipped tuples into a DynList.
auto zip_nth(size_t n, const Cs &... cs)
Return the n-th tuple from zipped containers.
auto t_zip_eq(const Cs &... cs)
Materialize zipped tuples; throw if containers differ in length.
EnumZipIterator< Cs... > enum_zip_it_pos(size_t pos, const Cs &... cs)
Alias for get_enum_zip_it_pos.
auto std_zip_n(const Cs &... cs)
Build a vector of tuples from 2 or more STL containers (variadic).
auto zip_drop(size_t n, const Cs &... cs)
Skip n tuples and return the rest.
auto zip_filter_eq(Op op, const Cs &... cs)
Filter zipped tuples by predicate op; throw if containers differ in length.
auto zip_map(Op &&op, const Cs &... cs)
Map op over zipped tuples with auto-deduced return type.
bool zip_exists(Op &&op, const Cs &... cs)
Return true if op returns true for at least one tuple.
ZipIterator< Cs... > zip_it(const Cs &... cs)
Alias for get_zip_it.
auto zip_find_last(Op &&op, const Cs &... cs)
Return the last tuple that satisfies predicate op.
void zip_for_each_indexed_eq(Op &&op, const Cs &... cs)
Apply op to each zipped tuple with index; throw if lengths differ.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static constexpr size_t N
Aleph::DynList< T > keys() const
Dynamic array container with automatic resizing.
Lazy and scalable dynamic array implementation.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.