143#include <tclap/CmdLine.h>
151using namespace Aleph;
159 cout <<
"\n" << string(60,
'=') <<
"\n";
161 cout << string(60,
'=') <<
"\n\n";
169template <
typename Container>
172 cout << label <<
": [";
174 for (
auto it = c.get_it(); it.has_curr(); it.next())
177 cout << it.get_curr();
201 cout <<
"Iterating numbers and names together:\n";
204 auto [num, name] = it.get_curr();
205 cout <<
" " << num <<
" -> " << name <<
endl;
210 cout <<
"Iterating numbers, names, and letters:\n";
213 auto [num, name,
letter] = it.get_curr();
214 cout <<
" " << num <<
" (" << name <<
") [" <<
letter <<
"]" <<
endl;
222 cout <<
"Zipping numbers with short_list (stops at shorter):\n";
225 auto [a, b] = it.get_curr();
226 cout <<
" " << a <<
", " << b <<
endl;
242 cout <<
"prices: [1.50, 0.80, 2.30, 1.20]" <<
endl;
246 cout <<
"Iterating with index:\n";
256 cout <<
"Created list of (index, fruit, price) tuples:\n";
277 cout <<
"prices: [15.0, 5.0, 8.0]" <<
endl;
283 cout <<
"Inventory as list of tuples:\n";
293 cout <<
"Unzipped back to separate lists:\n";
295 cout <<
" prices: [";
300 cout << it.get_curr();
319 cout <<
"unit_prices: [10.0, 25.0, 5.0, 100.0]" <<
endl;
327 cout <<
"Totals (qty * price):\n";
328 for (
auto it =
totals.
get_it(); it.has_curr(); it.next())
337 cout <<
"Orders > $30:\n";
347 cout <<
"Product descriptions:\n";
350 auto [name,
qty,
price] = it.get_curr();
372 cout <<
"Top 3 cities:\n";
373 for (
auto it =
top3.
get_it(); it.has_curr(); it.next())
375 auto [
city, pop] = it.get_curr();
382 cout <<
"Remaining cities (after dropping 3):\n";
383 for (
auto it =
rest.
get_it(); it.has_curr(); it.next())
385 auto [
city, pop] = it.get_curr();
395 cout <<
"Cities with population > 1500k (prefix):\n";
398 auto [
city, pop] = it.get_curr();
413 cout <<
"Large cities (>= 2M):\n";
414 for (
auto it =
large.
get_it(); it.has_curr(); it.next())
416 auto [
city, pop] = it.get_curr();
419 cout <<
"Smaller cities (< 2M):\n";
422 auto [
city, pop] = it.get_curr();
435 vector<int>
vec1 = {1, 2, 3, 4};
438 cout <<
"vec1 (std::vector): [1, 2, 3, 4]" <<
endl;
439 cout <<
"vec2 (std::vector): [a, b, c, d]" <<
endl;
444 cout <<
"Zipped STL vectors (returns std::vector):\n";
452 vector<double>
vec3 = {1.1, 2.2, 3.3, 4.4};
453 cout <<
"vec3 (std::vector): [1.1, 2.2, 3.3, 4.4]" <<
endl;
456 cout <<
"Triple-zipped (returns std::vector):\n";
482 cout <<
"list1 and list2 equal length? "
484 cout <<
"list1 and list3 equal length? "
489 cout <<
"Zipping list1 and list3:\n";
492 auto [a, b] = it.get_curr();
493 cout <<
" " << a <<
" + " << b <<
" = " << (a + b) <<
endl;
495 cout <<
" (Only 2 pairs produced)\n";
499 cout <<
"t_zip_eq on equal lists:\n";
502 auto result =
t_zip_eq(list1, list2);
503 cout <<
" Created " << result.
size() <<
" tuples successfully\n";
505 catch (
const length_error& e)
507 cout <<
" Error: " << e.what() <<
endl;
510 cout <<
"\nt_zip_eq on unequal lists:\n";
514 cout <<
" Created " << result.
size() <<
" tuples\n";
516 catch (
const length_error& e)
518 cout <<
" Caught exception: " << e.what() <<
endl;
541 cout <<
"Growth by region:\n";
547 <<
": " <<
y23 <<
" -> " <<
y24
561 cout <<
"High growth regions:\n";
575 auto [
y23,
y24] = it.get_curr();
595 "Comprehensive zip operations example for Aleph-w.\n"
596 "Demonstrates ZipIterator, t_zip, zip_map, and more.",
602 "Run only specific section: basic, enum, tuples, transform, "
603 "utilities, stl, length, practical, or 'all'",
604 false,
"all",
"section",
cmd
612 cout <<
"============================================================\n";
613 cout <<
" ALEPH-W ZIP OPERATIONS EXAMPLE\n";
614 cout <<
"============================================================\n";
640 cout <<
"\n" << string(60,
'=') <<
"\n";
641 cout <<
"Zip operations demo completed!\n";
642 cout << string(60,
'=') <<
"\n\n";
646 catch (TCLAP::ArgException& e)
648 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() <<
endl;
653 cerr <<
"Error: " << e.what() <<
endl;
Zip iterators and functional operations for multiple containers.
Functional programming utilities for Aleph-w containers.
Dynamic singly linked list with functional programming support.
size_t size() const noexcept
Count the number of elements of the list.
Iterator that traverses multiple containers with enumeration index.
Aleph::DynList< T > filter(Operation &operation) const
Filter the elements of a container according to a matching criteria.
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.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
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).
auto zip_filter(Op op, const Cs &... cs)
Filter zipped tuples by predicate op.
auto zip_take_while(Pred &&pred, const Cs &... cs)
Take tuples while predicate pred returns true.
bool equal_length(const Cs &... cs)
Return true if all containers have the same length.
auto zip_take(size_t n, const Cs &... cs)
Take at most n tuples from the zipped containers.
auto t_zip(const Cs &... cs)
Materialize zipped tuples into a DynList.
auto t_unzip(const DynList< std::tuple< Ts... > > &tuples)
Unzip a list of tuples into a tuple of lists.
auto t_enum_zip(const Cs &... cs)
Materialize enumerated zipped tuples into a DynList.
auto t_zip_eq(const Cs &... cs)
Materialize zipped tuples; throw if containers differ in length.
auto zip_drop(size_t n, const Cs &... cs)
Skip n tuples and return the rest.
auto zip_map(Op &&op, const Cs &... cs)
Map op over zipped tuples with auto-deduced return type.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Dynamic doubly linked list implementation.
void demo_tuple_operations()
void print_subsection(const string &title)
void demo_zip_transformation()
void demo_length_checking()
void print_section(const string &title)
void demo_zip_utilities()
void print_list(const string &label, const Container &c)
void demo_practical_example()
void demo_stl_compatibility()