47#include <gtest/gtest.h>
66#include <unordered_set>
69#include <forward_list>
79 std::vector<int> v1 = {1, 2, 3};
80 std::vector<std::string> v2 = {
"a",
"b",
"c"};
83 for (
auto [num, str] :
uni_zip(v1, v2))
94 std::vector<int> v = {1, 2, 3};
95 std::list<double>
l = {1.1, 2.2, 3.3};
98 return std::get<0>(t) + std::get<1>(t);
107 std::vector<int> v1 = {1, 2};
108 std::vector<int> v2 = {10, 20};
109 std::vector<int>
v3 = {100, 200};
112 for (
auto [a, b, c] :
uni_zip(v1, v2,
v3))
134 std::vector<int>
nums;
135 std::vector<std::string>
strs;
137 for (
auto [num, str] :
uni_zip(l1, l2))
157 for (
auto [num, str] :
uni_zip(list, arr))
169 std::vector<int>
stl_vec = {1, 2, 3, 4, 5};
172 std::vector<std::string>
results;
174 results.push_back(std::to_string(num) + str);
184 std::vector<double>
stl_vec = {1.5, 2.5, 3.5};
187 return std::get<0>(t) * std::get<1>(t);
197 std::vector<int>
stl_vec = {1, 2, 3};
199 std::list<std::string>
stl_list = {
"a",
"b",
"c"};
224 std::vector<int>
stl_vec = {1, 2, 3};
228 return std::get<0>(t) < std::get<1>(t);
236 std::vector<int>
stl_vec = {1, 2, 3};
240 return std::get<1>(t).length() > 10;
248 std::vector<int>
stl_vec = {1, 2, 3};
251 std::vector<int>
sums;
253 sums.push_back(std::get<0>(t) + std::get<1>(t));
263 std::vector<int>
prices = {10, 20, 30};
267 return acc + std::get<0>(t) * std::get<1>(t);
275 std::vector<int>
xs = {1, 2, 3};
279 return std::get<0>(t) + std::get<1>(t);
288 std::vector<int>
xs = {1, 2, 3, 4, 5};
292 return std::get<0>(t) % 2 == 0;
300 std::vector<int>
xs = {1, 2, 3, 4, 5};
304 return std::get<0>(t) == 3;
314 std::vector<int>
xs = {1, 2, 3, 4, 5};
318 return std::get<0>(t) % 2 == 0;
326 std::vector<int>
xs = {1, 2, 3, 4, 5};
338 std::vector<int>
xs = {1, 2, 3, 4, 5};
349 std::vector<int>
xs = {1, 2, 3, 4, 5};
360 std::vector<int>
xs = {1, 2, 3, 10, 4, 5};
364 return std::get<0>(t) < 10;
372 std::vector<int>
xs = {1, 2, 3, 10, 4, 5};
376 return std::get<0>(t) < 10;
385 std::vector<int>
xs = {1, 2, 3};
401 std::vector<int>
xs = {1, 2, 3, 4, 5};
405 return std::get<0>(t) % 2 == 0;
414 std::vector<int>
xs = {1, 2, 3};
424 std::vector<int>
xs = {1, 2, 3};
463 EXPECT_EQ(std::get<1>(*result),
"answer");
474 for (
const auto& v : values)
481 for (
const auto& v : values)
488 for (
const auto& v : values)
498 std::vector<int>
stl = {1, 2, 3, 4, 5};
502 return std::get<0>(t) + std::get<1>(t);
512 std::vector<int>
stl = {1, 2, 3, 4, 5};
517 return acc + std::get<0>(t) * std::get<1>(t);
526 std::vector<std::string>
stl = {
"a",
"b",
"c"};
531 return std::get<0>(t) + std::to_string(std::get<1>(t));
540 std::vector<int>
stl = {100, 200, 300};
561 std::list<double>
stl = {1.1, 2.2, 3.3};
565 return std::get<0>(t) * std::get<1>(t);
574 std::list<int>
stl = {1, 2, 3, 4};
581 std::vector<std::string>
results;
583 results.push_back(std::to_string(std::get<0>(t)) +
"-" + std::get<1>(t));
597 std::deque<int>
stl = {5, 10, 15, 20};
601 return std::get<0>(t) > std::get<1>(t);
609 std::deque<char>
stl = {
'a',
'b',
'c'};
614 return std::string(1, std::get<0>(t)) + std::to_string(std::get<1>(t));
627 std::set<int>
stl = {10, 20, 30};
630 std::vector<int>
nums;
631 std::vector<std::string>
strs;
646 std::set<int>
stl = {100, 200, 300};
651 return std::get<0>(t) * std::get<1>(t);
663 std::array<int, 4>
stl = {1, 2, 3, 4};
667 return acc + std::get<0>(t) + std::get<1>(t);
675 std::array<std::string, 3>
stl = {
"hello",
"world",
"test"};
680 return std::get<0>(t) +
":" + std::to_string(std::get<1>(t));
693 std::vector<int> v = {1, 2, 3};
695 std::deque<int> d = {100, 200, 300};
698 return std::get<0>(t) + std::get<1>(t) + std::get<2>(t);
709 std::vector<std::string> v = {
"a",
"b",
"c"};
724 std::vector<int> v1 = {1, 2};
726 std::list<int> v2 = {100, 200};
731 return std::get<0>(t) + std::get<1>(t) + std::get<2>(t) + std::get<3>(t);
749 return std::get<0>(t) * std::get<1>(t);
769 std::vector<std::string>
results;
771 results.push_back(std::get<0>(t) +
"=" + std::to_string(std::get<1>(t)));
786 return acc + std::get<0>(t) + std::get<1>(t) + std::get<2>(t);
798 std::vector<int>
stl = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
806 std::vector<int>
stl = {1, 2};
814 std::vector<int> v = {1, 2, 3, 4, 5};
816 std::deque<int> d = {100, 200, 300, 400};
827 std::vector<int>
stl = {1, 2, 3, 4, 5, 6};
832 return std::get<0>(t) % 2 == 0;
842 std::vector<int>
stl = {1, 2, 3, 4, 5};
851 return std::get<0>(t) % 2 == 1;
861 std::vector<std::string>
stl = {
"a",
"b",
"c",
"d",
"e"};
875 std::deque<int>
stl = {1, 2, 3, 10, 11, 12};
880 return std::get<0>(t) < 10;
884 return std::get<0>(t) < 10;
897 std::string
stl =
"ABC";
901 return std::string(1, std::get<0>(t)) + std::to_string(std::get<1>(t));
915 std::vector<int>
stl = {10, 20, 30};
919 return std::to_string(i) +
":" + std::to_string(std::get<0>(t) + std::get<1>(t));
930 std::vector<std::string>
stl = {
"a",
"b",
"c",
"d",
"e"};
943 std::vector<int>
stl = {1, 2, 3, 4};
947 return acc + std::get<0>(t);
961 std::vector<std::string>
stl = {
"a",
"b",
"c",
"d",
"e"};
963 auto result =
uni_zip_find_mapi([](
size_t i,
auto t) -> std::optional<std::string> {
964 if (std::get<0>(t) == 3)
965 return "found at " + std::to_string(i);
975 std::vector<int>
stl = {1, 2, 3};
979 return std::get<0>(t) * 10 == std::get<1>(t);
987 std::vector<int>
stl = {1, 2, 3};
997 std::vector<int> values = {1, 2, 3};
999 auto result =
uni_zip_assoc(std::string(
"two"), keys, values);
1008 std::vector<int>
stl = {3, 1, 4, 1, 5};
1019 std::vector<int>
stl = {3, 1, 4, 1, 5};
1031 std::vector<int>
stl = {30, 10, 40, 10, 50};
1036 EXPECT_EQ(std::get<0>(result->first), 1);
1037 EXPECT_EQ(std::get<0>(result->second), 5);
1046 std::vector<std::pair<int, std::string>>
pairs = {
1047 {1,
"a"}, {2,
"b"}, {3,
"c"}
1079 std::vector<std::tuple<int, double, char>>
tuples = {
1113 std::vector<int>
stl = {1, 2, 3};
1120 auto it = result.get_it();
1121 EXPECT_EQ(std::get<0>(it.get_curr()), 1);
1122 EXPECT_EQ(std::get<1>(it.get_curr()),
"a");
1144 std::vector<int> v1 = {1, 2, 3, 4, 5};
1145 std::vector<int> v2 = {10, 20, 30, 40, 50};
1155 std::vector<int> v1 = {1, 2, 3, 4, 5};
1156 std::vector<int> v2 = {10, 20, 30, 40, 50};
1166 std::vector<int> v1 = {1, 2, 3};
1167 std::vector<int> v2 = {10, 20, 30};
1172 return std::get<0>(t) + std::get<1>(t);
1181 std::vector<int> v1 = {1, 2, 3, 4, 5};
1182 std::vector<int> v2 = {10, 20, 30, 40, 50};
1187 return std::get<0>(t) % 2 == 0;
1196 std::vector<int> v1 = {1, 2, 3};
1197 std::vector<int> v2 = {10, 20, 30};
1202 return acc + std::get<0>(t);
1215 std::vector<int> v1 = {1, 2, 3};
1216 std::vector<int> v2 = {10, 20, 30};
1217 std::vector<int>
v3 = {100, 200};
1229 std::vector<int> v1 = {1, 2, 3};
1230 std::vector<int> v2 = {10, 20, 30};
1231 std::vector<int>
v3 = {100, 200};
1241 return std::get<0>(t) != 2;
1247 std::vector<int> v1 = {1, 2, 3};
1248 std::vector<int> v2 = {10, 20, 30};
1249 std::vector<int>
v3 = {10, 20};
1253 return std::get<0>(t) < std::get<1>(t);
1258 return std::get<0>(t) < std::get<1>(t);
1268 std::vector<int> v1 = {1, 2, 3, 4, 5};
1269 std::vector<int> v2 = {10, 20, 30, 40, 50};
1279 for (
auto [a, b] :
view)
1289 std::vector<int> v1 = {1, 2, 3};
1290 std::vector<int> v2 = {10, 20, 30};
1314 std::vector<int> v1 = {1, 2, 3};
1315 std::vector<int> v2 = {10, 20};
1336 std::vector<int> v1 = {1, 2, 3};
1337 std::vector<int> v2 = {10, 20, 30};
1342 while (it.has_curr())
1366 return std::get<0>(t);
1374 std::vector<int> v1 = {42};
1375 std::vector<std::string> v2 = {
"answer"};
1380 return std::to_string(std::get<0>(t)) +
":" + std::get<1>(t);
1391 ::testing::InitGoogleTest(&
argc,
argv);
Unified zip operations for both STL and Aleph containers.
void populate_dyndlist(DynDlist< T > &l, std::initializer_list< T > values)
void populate_dynarray(DynArray< T > &arr, std::initializer_list< T > values)
void populate_dynlist(DynList< T > &l, std::initializer_list< T > values)
T & append()
Allocate a new entry to the end of array.
Dynamic doubly linked list with O(1) size and bidirectional access.
Dynamic singly linked list with functional programming support.
T & insert(const T &item)
Insert a new item by copy.
T & append(const T &item)
Append a new item by copy.
void empty() noexcept
empty the list
Dynamic set backed by balanced binary search trees with automatic memory management.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
size_t size() const noexcept
Count the number of elements of the list.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
auto uni_zip_scan_left(T init, Op &&op, const Containers &... cs)
Scan left - fold with intermediate results.
auto uni_zip(const Containers &... cs)
Create a lazy zip view over any combination of STL/Aleph containers.
auto uni_zip_take(size_t n, const Containers &... cs)
Take first n tuples.
bool uni_zip_equal_length(const Containers &... cs)
Check if all containers have equal length.
bool uni_zip_exists(Pred &&pred, const Containers &... cs)
Check if predicate holds for any zipped tuple.
auto uni_zip_to_vector(const Containers &... cs)
Materialize zipped tuples into a vector.
auto uni_zip_min_max(const Containers &... cs)
Get both min and max in a single pass.
auto uni_zip_filteri(Pred &&pred, const Containers &... cs)
Filter with index (filteri in ML).
T uni_zip_foldl(T init, Op &&op, const Containers &... cs)
Left fold over zipped tuples.
size_t uni_zip_length(const Containers &... cs)
Get zip length (minimum of all container sizes).
auto uni_unzip_tuple(const Container &c)
Unzip a container of tuples into a tuple of DynLists.
auto uni_zip_mapi(Op &&op, const Containers &... cs)
Map with index (mapi in ML).
bool uni_zip_equal_by(Eq &&eq, const Containers &... cs)
Check equality with custom comparator.
auto uni_zip_last(const Containers &... cs)
Get last tuple.
auto uni_zip_partition(Pred &&pred, const Containers &... cs)
Partition tuples by predicate.
auto uni_zip_nth(size_t n, const Containers &... cs)
Get n-th tuple from zipped containers.
auto uni_zip_min(const Containers &... cs)
Get minimum tuple.
auto uni_unzip(const Container &c)
Unzip a container of pairs into two DynLists.
auto uni_zip_to_dynlist(const Containers &... cs)
Materialize a zipped view into a DynList of tuples.
void uni_zip_for_each(Op &&op, const Containers &... cs)
Apply operation to each zipped tuple.
auto uni_zip_max(const Containers &... cs)
Get maximum tuple.
auto uni_zip_assoc(const Key &key, const Containers &... cs)
Find value associated with key in zipped pairs (assoc in ML).
auto uni_zip_it(const Containers &... cs)
Get a unified zip iterator.
bool uni_zip_all(Pred &&pred, const Containers &... cs)
Check if predicate holds for all zipped tuples.
size_t uni_zip_count(Pred &&pred, const Containers &... cs)
Count tuples satisfying predicate.
auto uni_zip_first(const Containers &... cs)
Get first tuple.
auto uni_zip_drop_while(Pred &&pred, const Containers &... cs)
Skip tuples while predicate is true, return the rest.
auto uni_zip_find_mapi(Op &&op, const Containers &... cs)
Find and map with index (find_mapi in ML).
auto uni_zip_filter(Pred &&pred, const Containers &... cs)
Filter zipped tuples by predicate.
auto uni_zip_map(Op &&op, const Containers &... cs)
Map operation over zipped tuples.
auto uni_zip_take_while(Pred &&pred, const Containers &... cs)
Take tuples while predicate is true.
auto uni_zip_drop(size_t n, const Containers &... cs)
Skip first n tuples, return the rest.
bool uni_zip_all_eq(Pred &&pred, const Containers &... cs)
Check if all tuples satisfy predicate AND containers have equal length.
auto uni_zip_find_first(Pred &&pred, const Containers &... cs)
Find first tuple satisfying predicate.
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.
bool uni_zip_mem(const Tuple &target, const Containers &... cs)
Check if a tuple exists in the zipped sequence (mem in ML).
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Sentinel type for UniZipIterator end comparison.
void operator()(auto t) const
bool operator()(auto) const
Circular queue implementations backed by arrays.
Stack implementations backed by dynamic or fixed arrays.
Lazy and scalable dynamic array implementation.
Dynamic doubly linked list implementation.
Dynamic queue implementation based on linked lists.
Dynamic stack implementation based on linked lists.
Dynamic set implementations based on hash tables.
Dynamic set implementations based on balanced binary search trees.