143#include <tclap/CmdLine.h>
151using namespace Aleph;
159 cout <<
"\n" << string(60,
'=') <<
"\n";
160 cout <<
" " << title <<
"\n";
161 cout << string(60,
'=') <<
"\n\n";
166 cout <<
"\n--- " << title <<
" ---\n";
169template <
typename Container>
172 cout << label <<
": [";
174 for (
auto it = c.get_it(); it.has_curr(); it.next())
176 if (
not first) cout <<
", ";
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";
250 cout <<
" [" << idx <<
"] " <<
fruit <<
": $" << fixed << setprecision(2) <<
price <<
endl;
256 cout <<
"Created list of (index, fruit, price) tuples:\n";
257 for (
auto it =
enumerated.get_it(); it.has_curr(); it.next())
260 cout <<
" (" << idx <<
", " <<
fruit <<
", $" <<
price <<
")" <<
endl;
277 cout <<
"prices: [15.0, 5.0, 8.0]" <<
endl;
283 cout <<
"Inventory as list of tuples:\n";
284 for (
auto it =
inventory.get_it(); it.has_curr(); it.next())
293 cout <<
"Unzipped back to separate lists:\n";
295 cout <<
" prices: [";
297 for (
auto it =
prices_back.get_it(); it.has_curr(); it.next())
299 if (
not first) cout <<
", ";
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())
329 cout <<
" $" << fixed << setprecision(2) << it.get_curr() <<
endl;
337 cout <<
"Orders > $30:\n";
338 for (
auto it =
expensive.get_it(); it.has_curr(); it.next())
347 cout <<
"Product descriptions:\n";
350 auto [name,
qty,
price] = it.get_curr();
351 cout <<
" " << name <<
" (" <<
qty <<
" @ $" <<
price <<
")" <<
endl;
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();
376 cout <<
" " <<
city <<
": " << pop <<
"k" <<
endl;
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();
386 cout <<
" " <<
city <<
": " << pop <<
"k" <<
endl;
395 cout <<
"Cities with population > 1500k (prefix):\n";
396 for (
auto it =
big_cities.get_it(); it.has_curr(); it.next())
398 auto [
city, pop] = it.get_curr();
399 cout <<
" " <<
city <<
": " << pop <<
"k" <<
endl;
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();
417 cout <<
" " <<
city <<
": " << pop <<
"k" <<
endl;
419 cout <<
"Smaller cities (< 2M):\n";
420 for (
auto it =
small_cities.get_it(); it.has_curr(); it.next())
422 auto [
city, pop] = it.get_curr();
423 cout <<
" " <<
city <<
": " << pop <<
"k" <<
endl;
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";
447 cout <<
" (" << num <<
", " <<
letter <<
")" <<
endl;
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";
459 auto [num,
letter, dbl] = t;
460 cout <<
" (" << num <<
", " <<
letter <<
", " << dbl <<
")" <<
endl;
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";
544 auto [region,
y23,
y24] = it.get_curr();
546 cout <<
" " << setw(12) << left << region
547 <<
": " <<
y23 <<
" -> " <<
y24
548 <<
" (" <<
showpos << fixed << setprecision(1) <<
pct <<
"%)"
561 cout <<
"High growth regions:\n";
562 for (
auto it =
good_growth.get_it(); it.has_curr(); it.next())
564 auto [region,
y23,
y24] = it.get_curr();
566 cout <<
" " << region <<
": " <<
showpos << fixed << setprecision(1)
575 auto [
y23,
y24] = it.get_curr();
582 cout <<
"Overall growth: " <<
showpos << fixed << setprecision(1)
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.
Iterator that traverses multiple containers with enumeration index.
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.
bool equal_length(const Cs &...cs)
Return true if all containers have the same length.
auto zip_filter(Op op, const Cs &...cs)
Filter zipped tuples by predicate op.
auto t_zip(const Cs &...cs)
Materialize zipped tuples into a DynList.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
auto t_zip_eq(const Cs &...cs)
Materialize zipped tuples; throw if containers differ in length.
auto tzip_std(const Cs &...cs)
Build a vector of tuples from 2 or more STL containers (variadic).
auto t_enum_zip(const Cs &...cs)
Materialize enumerated 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 zip_map(Op &&op, const Cs &...cs)
Map op over zipped tuples with auto-deduced return type.
auto zip_take_while(Pred &&pred, const Cs &...cs)
Take tuples while predicate pred returns true.
auto zip_drop(const size_t n, const Cs &...cs)
Skip n tuples and return the rest.
auto zip_take(size_t n, const Cs &...cs)
Take at most n tuples from the zipped containers.
static void section(const string &title)
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()