152#include <tclap/CmdLine.h>
159using namespace Aleph;
167 cout <<
"\n" << string(60,
'=') <<
"\n";
168 cout <<
" " << title <<
"\n";
169 cout << string(60,
'=') <<
"\n\n";
174 cout <<
"\n--- " << title <<
" ---\n";
185 cout <<
"The key feature of ah-zip-utils.H is mixing STL and Aleph containers!\n\n";
188 vector<int> stl_ids = {101, 102, 103, 104};
189 list<string> stl_names = {
"Juan",
"Maria",
"Carlos",
"Ana"};
194 cout <<
"STL vector<int> ids: [101, 102, 103, 104]" << endl;
195 cout <<
"STL list<string> names: [Juan, Maria, Carlos, Ana]" << endl;
196 cout <<
"Aleph DynList<double>: [85.5, 92.3, 78.0, 95.8]" << endl;
200 cout <<
"Zipping vector + list + DynList together:\n";
201 for (
auto it =
uni_zip_it(stl_ids, stl_names, aleph_scores); it.has_curr(); it.next())
203 auto [id, name, score] = it.get_curr();
204 cout <<
" ID " <<
id <<
": " << setw(8) << left << name
205 <<
" Score: " << fixed << setprecision(1) << score << endl;
210 cout <<
"Using unified iterator:\n";
211 for (
auto it =
uni_zip_it(stl_ids, stl_names); it.has_curr(); it.next())
213 auto [id, name] = it.get_curr();
214 cout <<
" " <<
id <<
" -> " << name << endl;
226 vector<int> stl_quantities = {10, 25, 5, 30};
229 cout <<
"STL vector quantities: [10, 25, 5, 30]" << endl;
230 cout <<
"Aleph DynList prices: [100, 50, 200, 25]" << endl;
234 bool all_valuable =
uni_zip_all([](
const auto& t) {
235 return get<0>(t) * get<1>(t) > 100;
236 }, stl_quantities, aleph_prices);
237 cout <<
"All orders > $100? " << (all_valuable ?
"yes" :
"no") << endl;
242 return get<0>(t) * get<1>(t) > 500;
243 }, stl_quantities, aleph_prices);
244 cout <<
"Exists order > $500? " << (has_expensive ?
"yes" :
"no") << endl;
249 return get<0>(t) * get<1>(t) < 50;
250 }, stl_quantities, aleph_prices);
251 cout <<
"No orders < $50? " << (none_cheap ?
"yes" :
"no") << endl;
254 cout <<
"\nAll orders:\n";
257 double price = get<1>(t);
258 cout <<
" " << qty <<
" x $" << price <<
" = $" << (qty * price) << endl;
259 }, stl_quantities, aleph_prices);
271 vector<string> stl_depts = {
"Huila",
"Nariño",
"Cauca",
"Tolima"};
274 cout <<
"STL vector depts: [Huila, Nariño, Cauca, Tolima]" << endl;
275 cout <<
"Aleph DynList bags(k): [150, 85, 72, 65]" << endl;
280 return get<0>(t) +
": " +
to_string(get<1>(t)) +
"k bags";
281 }, stl_depts, aleph_production);
283 cout <<
"Production reports:\n";
284 for (
const auto&
r : reports)
285 cout <<
" " <<
r << endl;
290 return get<1>(t) >= 80;
291 }, stl_depts, aleph_production);
293 cout <<
"Major producers (>= 80k bags):\n";
294 for (
const auto& [dept, bags] : major_producers)
295 cout <<
" " << dept <<
": " << bags <<
"k bags" << endl;
299 auto ranked =
uni_zip_mapi([](
size_t idx,
const auto& t) {
300 return "#" +
to_string(idx + 1) +
" " + get<0>(t);
301 }, stl_depts, aleph_production);
303 cout <<
"Ranked by position:\n";
304 for (
const auto&
r : ranked)
305 cout <<
" " <<
r << endl;
316 list<string> stl_cities = {
"Bogota",
"Medellin",
"Cali",
"Barranquilla",
"Cartagena"};
319 cout <<
"STL list cities: [Bogota, Medellin, Cali, Barranquilla, Cartagena]" << endl;
320 cout <<
"Aleph DynList temps(C): [14, 24, 25, 28, 29]" << endl;
325 cout <<
"First 3 cities:\n";
326 for (
const auto& [city, temp] : top3)
327 cout <<
" " << city <<
": " << temp <<
"°C" << endl;
332 cout <<
"Remaining cities:\n";
333 for (
const auto& [city, temp] : rest)
334 cout <<
" " << city <<
": " << temp <<
"°C" << endl;
340 auto min_opt =
uni_zip_min(stl_cities, aleph_temps);
343 auto [city, temp] = *min_opt;
344 cout <<
"Coldest: " << city <<
" at " << temp <<
"°C" << endl;
347 auto max_opt =
uni_zip_max(stl_cities, aleph_temps);
350 auto [city, temp] = *max_opt;
351 cout <<
"Hottest: " << city <<
" at " << temp <<
"°C" << endl;
363 vector<int> vec_a = {1, 2, 3, 4, 5};
366 cout <<
"STL vector a: [1, 2, 3, 4, 5]" << endl;
367 cout <<
"Aleph DynList b: [10, 20, 30, 40, 50]" << endl;
372 return acc + get<0>(t) + get<1>(t);
375 cout <<
"Running sum of (a[i] + b[i]):\n ";
376 for (
int val : running_sums)
382 vector<int> short_vec = {1, 2};
383 cout <<
"vec_a and list_b same length? "
385 cout <<
"vec_a and short_vec same length? "
390 cout <<
"Zipped pairs: ";
391 for (
auto it =
uni_zip_it(vec_a, list_b); it.has_curr(); it.next())
393 auto [x,
y] = it.get_curr();
394 cout <<
"(" << x <<
"," <<
y <<
") ";
407 vector<string> stl_products = {
"Cafe",
"Panela",
"Arroz",
"Frijol"};
408 vector<double> stl_prices = {25.0, 8.0, 12.0, 15.0};
410 cout <<
"STL vectors:\n";
411 cout <<
" products: [Cafe, Panela, Arroz, Frijol]" << endl;
412 cout <<
" prices: [25.0, 8.0, 12.0, 15.0]" << endl;
418 cout <<
"Converted to DynList<tuple>:\n";
419 for (
auto it = aleph_result.
get_it(); it.has_curr(); it.next())
421 auto [
product, price] = it.get_curr();
422 cout <<
" " <<
product <<
": $" << price << endl;
430 cout <<
"Converted to std::vector<tuple>:\n";
431 for (
const auto& [
id, price] : stl_result)
432 cout <<
" ID " <<
id <<
": $" << price << endl;
445 vector<string> db_students = {
"Sofia",
"Andres",
"Valentina",
"Santiago",
"Isabella"};
449 list<double> spanish_grades = {4.0, 4.2, 4.3, 3.9, 4.6};
451 cout <<
"Data from mixed sources:\n";
452 cout <<
" DB (vector): [Sofia, Andres, Valentina, Santiago, Isabella]" << endl;
453 cout <<
" Processed (DynList): [4.2, 3.8, 4.5, 3.5, 4.8] (Math)" << endl;
454 cout <<
" Input (list): [4.0, 4.2, 4.3, 3.9, 4.6] (Spanish)" << endl;
459 string name = get<0>(t);
460 double math = get<1>(t);
461 double spanish = get<2>(t);
462 double avg = (math + spanish) / 2.0;
463 return make_tuple(name, avg);
464 }, db_students, processed_math, spanish_grades);
466 cout <<
"Student averages:\n";
467 for (
const auto& [name, avg] : averages)
469 cout <<
" " << setw(10) << left << name <<
": "
470 << fixed << setprecision(2) << avg << endl;
476 double math = get<1>(t);
477 double spanish = get<2>(t);
478 return (math + spanish) / 2.0 >= 4.3;
479 }, db_students, processed_math, spanish_grades);
481 cout <<
"Honors list:\n";
482 for (
const auto& t : honors)
484 auto [name, math, spanish] = t;
485 double avg = (math + spanish) / 2.0;
486 cout <<
" " << name <<
" (avg: " << fixed << setprecision(2) << avg <<
")" << endl;
495 if ((get<1>(t) + get<2>(t)) / 2.0 >= 3.0)
497 }, db_students, processed_math, spanish_grades);
499 cout <<
"Total students: " << total << endl;
500 cout <<
"Passing (avg >= 3.0): " << passing << endl;
501 cout <<
"Pass rate: " << (100.0 * passing / total) <<
"%" << endl;
508int main(
int argc,
char* argv[])
513 "Unified zip utilities example for Aleph-w.\n"
514 "Demonstrates mixing STL and Aleph containers in zip operations.",
518 TCLAP::ValueArg<string> sectionArg(
520 "Run only specific section: mixed, predicates, transform, "
521 "utilities, advanced, conversion, practical, or 'all'",
522 false,
"all",
"section",
cmd
525 cmd.parse(argc, argv);
527 string section = sectionArg.getValue();
530 cout <<
"============================================================\n";
531 cout <<
" ALEPH-W UNIFIED ZIP UTILITIES EXAMPLE\n";
532 cout <<
" (Mix STL and Aleph containers!)\n";
533 cout <<
"============================================================\n";
556 cout <<
"\n" << string(60,
'=') <<
"\n";
557 cout <<
"Unified zip utilities demo completed!\n";
558 cout << string(60,
'=') <<
"\n\n";
562 catch (TCLAP::ArgException& e)
564 cerr <<
"Error: " << e.error() <<
" for argument " << e.argId() << endl;
569 cerr <<
"Error: " << e.what() << endl;
Unified zip operations for both STL and Aleph containers.
Doubly-linked list (defined in tpl_dynList.H).
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
Singly linked list implementations with head-tail access.
Main namespace for Aleph-w library functions.
auto uni_zip_min(const Containers &...cs)
Get minimum tuple.
bool uni_zip_equal_length(const Containers &...cs)
Check if all containers have equal length.
auto uni_zip_filter(Pred &&pred, const Containers &...cs)
Filter zipped tuples by predicate.
bool uni_zip_none(Pred &&pred, const Containers &...cs)
Check if no tuple satisfies the predicate.
auto uni_zip_take(size_t n, const Containers &...cs)
Take first n tuples.
auto uni_zip_map(Op &&op, const Containers &...cs)
Map operation over zipped tuples.
auto uni_zip_mapi(Op &&op, const Containers &...cs)
Map with index (mapi in ML).
bool uni_zip_all(Pred &&pred, const Containers &...cs)
Check if predicate holds for all zipped tuples.
auto uni_zip_scan_left(T init, Op &&op, const Containers &...cs)
Scan left - fold with intermediate results.
T product(const Container &container, const T &init=T{1})
Compute product of all elements.
auto uni_zip_to_vector(const Containers &...cs)
Materialize zipped tuples into a vector.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
auto uni_zip_to_dynlist(const Containers &...cs)
Materialize a zipped view into a DynList of tuples.
auto uni_zip_drop(size_t n, const Containers &...cs)
Skip first n tuples, return the rest.
auto uni_zip_max(const Containers &...cs)
Get maximum tuple.
bool uni_zip_exists(Pred &&pred, const Containers &...cs)
Check if predicate holds for any zipped tuple.
auto uni_zip_it(const Containers &...cs)
Get a unified zip iterator.
void uni_zip_for_each(Op &&op, const Containers &...cs)
Apply operation to each zipped tuple.
static void section(const string &title)
Lazy and scalable dynamic array implementation.
void print_subsection(const string &title)
void print_section(const string &title)
void demo_transformations()
void demo_mixed_containers()